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
class
TheiaTestCase
(
SlapOSInstanceTestCase
):
__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
def
_getSlapos
(
cls
):
partition_root
=
cls
.
computer_partition_root_path
slapos
=
os
.
path
.
join
(
partition_root
,
'srv'
,
'runner'
,
'bin'
,
'slapos'
)
return
slapos
try
:
return
cls
.
_theia_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
):
...
...
@@ -229,82 +272,61 @@ class TestTheiaEmbeddedSlapOSShutdown(TheiaTestCase):
self
.
assertFalse
(
embedded_slapos_process
.
is_running
())
class
ReRequestMixin
(
object
):
def
rerequest
(
self
,
parameter_dict
=
None
,
state
=
'started'
):
software_url
=
self
.
getSoftwareURL
()
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
)
class
TestTheiaWithEmbeddedSR
(
TheiaTestCase
):
sr_url
=
'~/bogus/sr/url/1.cfg'
regexpr
=
re
.
compile
(
r"([\
w/
\.]+)\
s+sl
aprunner\
s+
available"
)
def
reinstantiate
(
self
):
# Process at least twice to propagate parameter changes
try
:
self
.
slap
.
waitForInstance
()
except
SlapOSNodeCommandError
:
pass
self
.
slap
.
waitForInstance
(
self
.
instance_max_retry
)
@
classmethod
def
getInstanceParameterDict
(
cls
,
sr_url
=
None
):
return
{
'one-time-embedded-sr'
:
sr_url
or
cls
.
sr_url
}
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
):
sr_url
=
'~/bogus/software.cfg'
sr_type
=
'bogus_type'
instance_parameters
=
'{
\
n
"bogus_param": "bogus_value",
\
n
"bogus_param2": "bogus_value2"
\
n
}'
def
assertSupplied
(
self
,
sr_url
):
info
=
self
.
captureSlapos
(
'proxy'
,
'show'
,
text
=
True
)
matches
=
self
.
regexpr
.
findall
(
info
)
self
.
assertIn
(
sr_url
,
info
)
self
.
assertIn
(
sr_url
,
matches
)
def
proxy_show
(
self
,
slapos
):
return
subprocess
.
check_output
((
slapos
,
'proxy'
,
'show'
),
universal_newlines
=
True
)
def
assertNotSupplied
(
self
,
sr_url
):
info
=
self
.
captureSlapos
(
'proxy'
,
'show'
,
text
=
True
)
self
.
assertNotIn
(
sr_url
,
info
)
def
test
(
self
):
slapos
=
self
.
_getSlapos
()
home
=
self
.
computer_partition_root_path
# Check that no request script was generated
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 requested SR is correctly supplied
initial_sr_url
=
self
.
expandUrl
(
self
.
sr_url
)
self
.
assertSupplied
(
initial_sr_url
)
self
.
assertNotSupplied
(
self
.
sr_url
)
# Check that embedded instance was requested
instance_name
=
"embedded_instance"
info
=
self
.
proxy_show
(
slapos
)
try
:
self
.
assertIn
(
instance_name
,
info
)
except
AssertionError
:
for
filename
in
os
.
listdir
(
home
):
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
# Request a new SR
sr_url_2
=
'/bogus/sr/url/2.cfg'
self
.
requestInstance
(
self
.
getInstanceParameterDict
(
sr_url_2
))
self
.
waitForInstance
()
# Check that new SR is not supplied
self
.
assertNotSupplied
(
sr_url_2
)
# Check that old
-name instance was renam
ed
self
.
assert
NotIn
(
old_instance_name
,
info
)
# Check that old
SRs is still suppli
ed
self
.
assert
Supplied
(
initial_sr_url
)
# Check embedded instance parameters
bogus_sr
=
os
.
path
.
join
(
home
,
self
.
sr_url
[
2
:])
# Delete script and flag file
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
)
self
.
assertIsNotNone
(
re
.
search
(
r"%s\
s+%s
\s+%s"
%
(
bogus_sr
,
self
.
sr_type
,
instance_name
),
info
),
info
)
# Check that requested SR is correctly supplied
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
)
self
.
assert
In
(
"{'bogus_param': 'bogus_value', 'bogus_param2': 'bogus_value2'}"
,
service_info
)
# Check that old SRs is still supplied
self
.
assert
Supplied
(
initial_sr_url
)
class
TestTheiaFrontend
(
TheiaTestCase
):
...
...
@@ -329,7 +351,7 @@ class TestTheiaEnv(TheiaTestCase):
@
classmethod
def
getInstanceParameterDict
(
cls
):
return
{
'embedded-sr'
:
cls
.
dummy_software_path
,
'
one-time-
embedded-sr'
:
cls
.
dummy_software_path
,
'autorun'
:
'stopped'
,
}
...
...
@@ -442,6 +464,11 @@ class ResilientTheiaMixin(object):
def
getInstanceSoftwareType
(
cls
):
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
):
@
classmethod
...
...
@@ -451,9 +478,9 @@ class TestTheiaResilientInterface(ResilientTheiaMixin, TestTheia):
cls
.
computer_partition_root_path
=
cls
.
_getPartitionPath
(
'export'
)
class
TestTheiaResilientWith
SR
(
ResilientTheiaMixin
,
TestTheiaWith
SR
):
class
TestTheiaResilientWith
EmbeddedSR
(
ResilientTheiaMixin
,
TestTheiaWithEmbedded
SR
):
@
classmethod
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
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