Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
slapos
Commits
5b2f7cd0
Commit
5b2f7cd0
authored
Sep 05, 2022
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/slaprunner/test: port the tests to python3
parent
9f0d8d75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
21 deletions
+19
-21
software/slaprunner/test/setup.py
software/slaprunner/test/setup.py
+0
-1
software/slaprunner/test/test.py
software/slaprunner/test/test.py
+19
-20
No files found.
software/slaprunner/test/setup.py
View file @
5b2f7cd0
...
@@ -48,7 +48,6 @@ setup(name=name,
...
@@ -48,7 +48,6 @@ setup(name=name,
'supervisor'
,
'supervisor'
,
'psutil'
,
'psutil'
,
'paramiko'
,
'paramiko'
,
'six'
,
'requests'
,
'requests'
,
],
],
zip_safe
=
True
,
zip_safe
=
True
,
...
...
software/slaprunner/test/test.py
View file @
5b2f7cd0
...
@@ -35,12 +35,11 @@ import subprocess
...
@@ -35,12 +35,11 @@ import subprocess
import
json
import
json
import
time
import
time
from
six.moves.
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
from
six.moves.
urllib.parse
import
quote
from
urllib.parse
import
quote
from
six.moves.
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
from
six.moves.
configparser
import
ConfigParser
from
configparser
import
ConfigParser
import
requests
import
requests
import
six
from
slapos.recipe.librecipe
import
generateHashFromFiles
from
slapos.recipe.librecipe
import
generateHashFromFiles
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
...
@@ -61,7 +60,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -61,7 +60,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
data
=
{
data
=
{
"path"
:
"workspace/slapos/software/%s"
%
software_release
,
"path"
:
"workspace/slapos/software/%s"
%
software_release
,
}
}
resp
=
self
.
_postToSlaprunner
(
url
,
data
)
resp
=
self
.
_postToSlaprunner
(
url
,
data
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertNotEqual
(
json
.
loads
(
resp
.
text
)[
'code'
],
0
,
self
.
assertNotEqual
(
json
.
loads
(
resp
.
text
)[
'code'
],
0
,
'Unexpecting result in call to setCurrentProject: %s'
%
resp
.
text
)
'Unexpecting result in call to setCurrentProject: %s'
%
resp
.
text
)
...
@@ -69,7 +68,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -69,7 +68,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
def
_buildSoftwareRelease
(
self
):
def
_buildSoftwareRelease
(
self
):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
"%s/runSoftwareProfile"
%
parameter_dict
[
'url'
]
url
=
"%s/runSoftwareProfile"
%
parameter_dict
[
'url'
]
resp
=
self
.
_postToSlaprunner
(
url
,
{})
resp
=
self
.
_postToSlaprunner
(
url
,
{})
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
json
.
loads
(
resp
.
text
)[
'result'
],
True
,
self
.
assertEqual
(
json
.
loads
(
resp
.
text
)[
'result'
],
True
,
'Unexpecting result in call to runSoftwareProfile: %s'
%
resp
.
text
)
'Unexpecting result in call to runSoftwareProfile: %s'
%
resp
.
text
)
...
@@ -77,7 +76,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -77,7 +76,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
def
_deployInstance
(
self
):
def
_deployInstance
(
self
):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
"%s/runInstanceProfile"
%
parameter_dict
[
'url'
]
url
=
"%s/runInstanceProfile"
%
parameter_dict
[
'url'
]
resp
=
self
.
_postToSlaprunner
(
url
,
{})
resp
=
self
.
_postToSlaprunner
(
url
,
{})
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
json
.
loads
(
resp
.
text
)[
'result'
],
True
,
self
.
assertEqual
(
json
.
loads
(
resp
.
text
)[
'result'
],
True
,
'Unexpecting result in call to runSoftwareProfile: %s'
%
resp
.
text
)
'Unexpecting result in call to runSoftwareProfile: %s'
%
resp
.
text
)
...
@@ -100,7 +99,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -100,7 +99,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
def
_isSoftwareReleaseReady
(
self
):
def
_isSoftwareReleaseReady
(
self
):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
"%s/isSRReady"
%
parameter_dict
[
'url'
]
url
=
"%s/isSRReady"
%
parameter_dict
[
'url'
]
resp
=
self
.
_getFromSlaprunner
(
url
)
resp
=
self
.
_getFromSlaprunner
(
url
)
if
requests
.
codes
.
ok
!=
resp
.
status_code
:
if
requests
.
codes
.
ok
!=
resp
.
status_code
:
return
-
1
return
-
1
return
resp
.
text
return
resp
.
text
...
@@ -125,7 +124,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -125,7 +124,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
}
}
while
True
:
while
True
:
time
.
sleep
(
25
)
time
.
sleep
(
25
)
resp
=
self
.
_postToSlaprunner
(
url
,
data
)
resp
=
self
.
_postToSlaprunner
(
url
,
data
)
if
requests
.
codes
.
ok
!=
resp
.
status_code
:
if
requests
.
codes
.
ok
!=
resp
.
status_code
:
continue
continue
if
json
.
loads
(
resp
.
text
)[
"instance"
][
"state"
]
is
False
:
if
json
.
loads
(
resp
.
text
)[
"instance"
][
"state"
]
is
False
:
...
@@ -153,9 +152,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -153,9 +152,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
url
=
"%s/getFileContent"
%
parameter_dict
[
'url'
]
url
=
"%s/getFileContent"
%
parameter_dict
[
'url'
]
data
=
{
data
=
{
"file"
:
relative_path
"file"
:
relative_path
}
}
resp
=
self
.
_postToSlaprunner
(
url
,
data
)
resp
=
self
.
_postToSlaprunner
(
url
,
data
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertNotEqual
(
json
.
loads
(
resp
.
text
)[
'code'
],
0
,
self
.
assertNotEqual
(
json
.
loads
(
resp
.
text
)[
'code'
],
0
,
'Unexpecting result in call to getFileContent: %s'
%
resp
.
text
)
'Unexpecting result in call to getFileContent: %s'
%
resp
.
text
)
...
@@ -189,9 +188,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -189,9 +188,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
takeover_url
=
parameter_dict
[
"takeover-%s-url"
%
scope
]
takeover_url
=
parameter_dict
[
"takeover-%s-url"
%
scope
]
takeover_password
=
parameter_dict
[
"takeover-%s-password"
%
scope
]
takeover_password
=
parameter_dict
[
"takeover-%s-password"
%
scope
]
resp
=
requests
.
get
(
resp
=
requests
.
get
(
"%s?password=%s"
%
(
takeover_url
,
takeover_password
)
,
f"
{
takeover_url
}
?password=
{
takeover_password
}
"
,
verify
=
True
)
verify
=
True
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertNotIn
(
"Error"
,
resp
.
text
,
self
.
assertNotIn
(
"Error"
,
resp
.
text
,
...
@@ -236,7 +235,7 @@ class TestWebRunnerAutorun(SlaprunnerTestCase):
...
@@ -236,7 +235,7 @@ class TestWebRunnerAutorun(SlaprunnerTestCase):
@
classmethod
@
classmethod
def
getInstanceParameterDict
(
cls
):
def
getInstanceParameterDict
(
cls
):
return
{
return
{
# Auto deploy is required for the isSRReady works.
# Auto deploy is required for the isSRReady works.
'auto-deploy'
:
'true'
,
'auto-deploy'
:
'true'
,
'autorun'
:
'true'
,
'autorun'
:
'true'
,
'software-root'
:
os
.
path
.
join
(
cls
.
slap
.
_instance_root
,
".."
,
"soft"
),
'software-root'
:
os
.
path
.
join
(
cls
.
slap
.
_instance_root
,
".."
,
"soft"
),
...
@@ -363,7 +362,7 @@ class TestSSH(SlaprunnerTestCase):
...
@@ -363,7 +362,7 @@ class TestSSH(SlaprunnerTestCase):
self
.
assertTrue
(
fingerprint_from_url
.
startswith
(
'ssh-rsa-'
),
fingerprint_from_url
)
self
.
assertTrue
(
fingerprint_from_url
.
startswith
(
'ssh-rsa-'
),
fingerprint_from_url
)
fingerprint_from_url
=
fingerprint_from_url
[
len
(
'ssh-rsa-'
):]
fingerprint_from_url
=
fingerprint_from_url
[
len
(
'ssh-rsa-'
):]
class
KeyPolicy
(
object
)
:
class
KeyPolicy
:
"""Accept server key and keep it in self.key for inspection
"""Accept server key and keep it in self.key for inspection
"""
"""
def
missing_host_key
(
self
,
client
,
hostname
,
key
):
def
missing_host_key
(
self
,
client
,
hostname
,
key
):
...
@@ -507,7 +506,7 @@ class TestResilientInstance(SlaprunnerTestCase):
...
@@ -507,7 +506,7 @@ class TestResilientInstance(SlaprunnerTestCase):
# just check that keys returned on requested partition are for resilient
# just check that keys returned on requested partition are for resilient
self
.
assertSetEqual
(
self
.
assertSetEqual
(
set
(
self
.
computer_partition
.
getConnectionParameterDict
().
keys
()),
set
(
self
.
computer_partition
.
getConnectionParameterDict
().
keys
()),
set
([
{
'backend-url'
,
'backend-url'
,
'feed-url-runner-1-pull'
,
'feed-url-runner-1-pull'
,
'feed-url-runner-1-push'
,
'feed-url-runner-1-push'
,
...
@@ -520,7 +519,7 @@ class TestResilientInstance(SlaprunnerTestCase):
...
@@ -520,7 +519,7 @@ class TestResilientInstance(SlaprunnerTestCase):
'takeover-runner-1-password'
,
'takeover-runner-1-password'
,
'takeover-runner-1-url'
,
'takeover-runner-1-url'
,
'url'
,
'url'
,
'webdav-url'
])
)
'webdav-url'
}
)
class
TestResilientCustomFrontend
(
TestCustomFrontend
):
class
TestResilientCustomFrontend
(
TestCustomFrontend
):
instance_max_retry
=
20
instance_max_retry
=
20
...
@@ -589,7 +588,7 @@ class TestResilientDummyInstance(SlaprunnerTestCase):
...
@@ -589,7 +588,7 @@ class TestResilientDummyInstance(SlaprunnerTestCase):
self
.
_waitForCloneToBeReadyForTakeover
()
self
.
_waitForCloneToBeReadyForTakeover
()
self
.
_doTakeover
()
self
.
_doTakeover
()
self
.
slap
.
waitForInstance
(
20
)
self
.
slap
.
waitForInstance
(
20
)
previous_computer_partition
=
self
.
computer_partition
previous_computer_partition
=
self
.
computer_partition
self
.
computer_partition
=
self
.
requestDefaultInstance
()
self
.
computer_partition
=
self
.
requestDefaultInstance
()
...
@@ -601,5 +600,5 @@ class TestResilientDummyInstance(SlaprunnerTestCase):
...
@@ -601,5 +600,5 @@ class TestResilientDummyInstance(SlaprunnerTestCase):
self
.
assertTrue
(
result_after
.
startswith
(
"Hello"
),
result_after
)
self
.
assertTrue
(
result_after
.
startswith
(
"Hello"
),
result_after
)
self
.
assertIn
(
result
,
result_after
,
self
.
assertIn
(
result
,
result_after
,
"%s not in %s"
%
(
result
,
result_after
)
)
f"
{
result
}
not in
{
result_after
}
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment