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
Xavier Thompson
slapos
Commits
fd0688eb
Commit
fd0688eb
authored
Mar 08, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/theia: Adapts tests for embedded SR
parent
0e66f643
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
71 deletions
+98
-71
software/theia/test/test.py
software/theia/test/test.py
+98
-71
No files found.
software/theia/test/test.py
View file @
fd0688eb
...
@@ -53,11 +53,54 @@ setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(theia_soft
...
@@ -53,11 +53,54 @@ setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(theia_soft
class
TheiaTestCase
(
SlapOSInstanceTestCase
):
class
TheiaTestCase
(
SlapOSInstanceTestCase
):
__partition_reference__
=
'T'
# for supervisord sockets in included slapos
__partition_reference__
=
'T'
# for supervisord sockets in included slapos
@
classmethod
def
_getPath
(
cls
,
*
components
):
return
os
.
path
.
join
(
cls
.
computer_partition_root_path
,
*
components
)
@
classmethod
@
classmethod
def
_getSlapos
(
cls
):
def
_getSlapos
(
cls
):
partition_root
=
cls
.
computer_partition_root_path
try
:
slapos
=
os
.
path
.
join
(
partition_root
,
'srv'
,
'runner'
,
'bin'
,
'slapos'
)
return
cls
.
_theia_slapos
return
slapos
except
AttributeError
:
cls
.
_theia_slapos
=
slapos
=
cls
.
_getPath
(
'srv'
,
'runner'
,
'bin'
,
'slapos'
)
return
slapos
@
classmethod
def
callSlapos
(
cls
,
*
command
,
**
kwargs
):
return
subprocess
.
call
((
cls
.
_getSlapos
(),)
+
command
,
**
kwargs
)
@
classmethod
def
checkSlapos
(
cls
,
*
command
,
**
kwargs
):
kwargs
[
'universal_newlines'
]
=
True
return
subprocess
.
check_call
((
cls
.
_getSlapos
(),)
+
command
,
**
kwargs
)
@
classmethod
def
captureSlapos
(
cls
,
*
command
,
**
kwargs
):
kwargs
[
'universal_newlines'
]
=
True
return
subprocess
.
check_output
((
cls
.
_getSlapos
(),)
+
command
,
**
kwargs
)
@
classmethod
def
requestInstance
(
cls
,
parameter_dict
=
None
,
state
=
'started'
):
cls
.
slap
.
request
(
software_release
=
cls
.
getSoftwareURL
(),
software_type
=
cls
.
getInstanceSoftwareType
(),
partition_reference
=
cls
.
default_partition_reference
,
partition_parameter_kw
=
parameter_dict
,
state
=
state
)
@
classmethod
def
restartService
(
cls
,
service
):
with
cls
.
slap
.
instance_supervisor_rpc
as
supervisor
:
for
process_info
in
supervisor
.
getAllProcessInfo
():
service_name
=
process_info
[
'name'
]
if
service
in
service_name
:
service_id
=
'%s:%s'
%
(
process_info
[
'group'
],
service_name
)
supervisor
.
stopProcess
(
service_id
)
supervisor
.
startProcess
(
service_id
)
break
else
:
raise
Exception
(
"Service %s not found"
%
service
)
class
TestTheia
(
TheiaTestCase
):
class
TestTheia
(
TheiaTestCase
):
...
@@ -229,82 +272,61 @@ class TestTheiaEmbeddedSlapOSShutdown(TheiaTestCase):
...
@@ -229,82 +272,61 @@ class TestTheiaEmbeddedSlapOSShutdown(TheiaTestCase):
self
.
assertFalse
(
embedded_slapos_process
.
is_running
())
self
.
assertFalse
(
embedded_slapos_process
.
is_running
())
class
ReRequestMixin
(
object
):
class
TestTheiaWithEmbeddedSR
(
TheiaTestCase
):
def
rerequest
(
self
,
parameter_dict
=
None
,
state
=
'started'
):
sr_url
=
'~/bogus/sr/url/1.cfg'
software_url
=
self
.
getSoftwareURL
()
regexpr
=
re
.
compile
(
r"([\
w/
\.]+)\
s+sl
aprunner\
s+
available"
)
software_type
=
self
.
getInstanceSoftwareType
()
name
=
self
.
default_partition_reference
self
.
slap
.
request
(
software_release
=
software_url
,
software_type
=
software_type
,
partition_reference
=
name
,
partition_parameter_kw
=
parameter_dict
,
state
=
state
)
def
reinstantiate
(
self
):
@
classmethod
# Process at least twice to propagate parameter changes
def
getInstanceParameterDict
(
cls
,
sr_url
=
None
):
try
:
return
{
self
.
slap
.
waitForInstance
()
'one-time-embedded-sr'
:
sr_url
or
cls
.
sr_url
except
SlapOSNodeCommandError
:
}
pass
self
.
slap
.
waitForInstance
(
self
.
instance_max_retry
)
def
expandUrl
(
self
,
sr_url
):
if
sr_url
.
startswith
(
'~/'
):
sr_url
=
os
.
path
.
join
(
self
.
getPath
(),
sr_url
[
2
:])
return
sr_url
class
TestTheiaWithSR
(
TheiaTestCase
,
ReRequestMixin
):
def
assertSupplied
(
self
,
sr_url
):
sr_url
=
'~/bogus/software.cfg'
info
=
self
.
captureSlapos
(
'proxy'
,
'show'
,
text
=
True
)
sr_type
=
'bogus_type'
matches
=
self
.
regexpr
.
findall
(
info
)
instance_parameters
=
'{
\
n
"bogus_param": "bogus_value",
\
n
"bogus_param2": "bogus_value2"
\
n
}'
self
.
assertIn
(
sr_url
,
info
)
self
.
assertIn
(
sr_url
,
matches
)
def
proxy_show
(
self
,
slapos
):
def
assertNotSupplied
(
self
,
sr_url
):
return
subprocess
.
check_output
((
slapos
,
'proxy'
,
'show'
),
universal_newlines
=
True
)
info
=
self
.
captureSlapos
(
'proxy'
,
'show'
,
text
=
True
)
self
.
assertNotIn
(
sr_url
,
info
)
def
test
(
self
):
def
test
(
self
):
slapos
=
self
.
_getSlapos
()
# Check that requested SR is correctly supplied
home
=
self
.
computer_partition_root_path
initial_sr_url
=
self
.
expandUrl
(
self
.
sr_url
)
self
.
assertSupplied
(
initial_sr_url
)
# Check that no request script was generated
self
.
assertNotSupplied
(
self
.
sr_url
)
request_script
=
os
.
path
.
join
(
home
,
'srv'
,
'project'
,
'request_embedded.sh'
)
self
.
assertFalse
(
os
.
path
.
exists
(
request_script
))
# Manually request old-name 'Embedded Instance'
old_instance_name
=
"Embedded Instance"
subprocess
.
check_call
((
slapos
,
'request'
,
old_instance_name
,
'bogus_url'
))
self
.
assertIn
(
old_instance_name
,
self
.
proxy_show
(
slapos
))
# Update Theia instance parameters
embedded_request_parameters
=
{
'embedded-sr'
:
self
.
sr_url
,
'embedded-sr-type'
:
self
.
sr_type
,
'embedded-instance-parameters'
:
self
.
instance_parameters
}
self
.
rerequest
(
embedded_request_parameters
)
self
.
reinstantiate
()
# Check that embedded instance was requested
# Request a new SR
instance_name
=
"embedded_instance"
sr_url_2
=
'/bogus/sr/url/2.cfg'
info
=
self
.
proxy_show
(
slapos
)
self
.
requestInstance
(
self
.
getInstanceParameterDict
(
sr_url_2
))
try
:
self
.
waitForInstance
()
self
.
assertIn
(
instance_name
,
info
)
except
AssertionError
:
# Check that new SR is not supplied
for
filename
in
os
.
listdir
(
home
):
self
.
assertNotSupplied
(
sr_url_2
)
if
'standalone'
in
filename
and
'.log'
in
filename
:
filepath
=
os
.
path
.
join
(
home
,
filename
)
with
open
(
filepath
)
as
f
:
print
(
"Contents of filepath: "
+
filepath
)
print
(
f
.
read
())
raise
# Check that old
-name instance was renam
ed
# Check that old
SRs is still suppli
ed
self
.
assert
NotIn
(
old_instance_name
,
info
)
self
.
assert
Supplied
(
initial_sr_url
)
# Check embedded instance parameters
# Delete script and flag file
bogus_sr
=
os
.
path
.
join
(
home
,
self
.
sr_url
[
2
:])
script
=
self
.
getPath
(
'etc'
,
'supply_embedded.sh'
)
os
.
remove
(
script
)
os
.
remove
(
script
+
'.done'
)
self
.
assertIsNotNone
(
re
.
search
(
r"%s\
s+sl
aprunner\
s+
available"
%
(
bogus_sr
,),
info
),
info
)
# Check that requested SR is correctly supplied
self
.
assertIsNotNone
(
re
.
search
(
r"%s\
s+%s
\s+%s"
%
(
bogus_sr
,
self
.
sr_type
,
instance_name
),
info
),
info
)
sr_url_3
=
'/bogus/sr/url/3.cfg'
self
.
requestInstance
(
self
.
getInstanceParameterDict
(
sr_url_3
))
self
.
waitForInstance
()
self
.
assertSupplied
(
sr_url_3
)
service_info
=
subprocess
.
check_output
((
slapos
,
'service'
,
'info'
,
instance_name
),
universal_newlines
=
True
)
# Check that old SRs is still supplied
self
.
assert
In
(
"{'bogus_param': 'bogus_value', 'bogus_param2': 'bogus_value2'}"
,
service_info
)
self
.
assert
Supplied
(
initial_sr_url
)
class
TestTheiaFrontend
(
TheiaTestCase
):
class
TestTheiaFrontend
(
TheiaTestCase
):
...
@@ -329,7 +351,7 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -329,7 +351,7 @@ class TestTheiaEnv(TheiaTestCase):
@
classmethod
@
classmethod
def
getInstanceParameterDict
(
cls
):
def
getInstanceParameterDict
(
cls
):
return
{
return
{
'embedded-sr'
:
cls
.
dummy_software_path
,
'
one-time-
embedded-sr'
:
cls
.
dummy_software_path
,
'autorun'
:
'stopped'
,
'autorun'
:
'stopped'
,
}
}
...
@@ -442,6 +464,11 @@ class ResilientTheiaMixin(object):
...
@@ -442,6 +464,11 @@ class ResilientTheiaMixin(object):
def
getInstanceSoftwareType
(
cls
):
def
getInstanceSoftwareType
(
cls
):
return
'resilient'
return
'resilient'
def
waitForinstance
(
self
,
*
args
,
**
kwargs
):
# process twice to propagate to all instances
for
_
in
range
(
2
):
super
(
ResilientTheiaMixin
,
self
).
waitForinstance
(
*
args
,
**
kwargs
)
class
TestTheiaResilientInterface
(
ResilientTheiaMixin
,
TestTheia
):
class
TestTheiaResilientInterface
(
ResilientTheiaMixin
,
TestTheia
):
@
classmethod
@
classmethod
...
@@ -451,9 +478,9 @@ class TestTheiaResilientInterface(ResilientTheiaMixin, TestTheia):
...
@@ -451,9 +478,9 @@ class TestTheiaResilientInterface(ResilientTheiaMixin, TestTheia):
cls
.
computer_partition_root_path
=
cls
.
_getPartitionPath
(
'export'
)
cls
.
computer_partition_root_path
=
cls
.
_getPartitionPath
(
'export'
)
class
TestTheiaResilientWith
SR
(
ResilientTheiaMixin
,
TestTheiaWith
SR
):
class
TestTheiaResilientWith
EmbeddedSR
(
ResilientTheiaMixin
,
TestTheiaWithEmbedded
SR
):
@
classmethod
@
classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
super
(
TestTheiaResilientWithSR
,
cls
).
setUpClass
()
super
(
TestTheiaResilientWith
Embedded
SR
,
cls
).
setUpClass
()
# Patch the computer root path to that of the export theia instance
# Patch the computer root path to that of the export theia instance
cls
.
computer_partition_root_path
=
cls
.
_getPartitionPath
(
'export'
)
cls
.
computer_partition_root_path
=
cls
.
_getPartitionPath
(
'export'
)
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