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
Lu Xu
slapos
Commits
4b564bbe
Commit
4b564bbe
authored
Sep 06, 2022
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/theia/test: simplify a test by using self.addCleanup
parent
28c25f43
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
46 deletions
+43
-46
software/theia/test/test.py
software/theia/test/test.py
+43
-46
No files found.
software/theia/test/test.py
View file @
4b564bbe
...
@@ -391,52 +391,49 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -391,52 +391,49 @@ class TestTheiaEnv(TheiaTestCase):
# Start a theia shell that inherits the environment of the theia process
# Start a theia shell that inherits the environment of the theia process
# This simulates the environment of a shell launched from the browser application
# This simulates the environment of a shell launched from the browser application
theia_shell_process
=
pexpect
.
spawnu
(
'{}/bin/theia-shell'
.
format
(
self
.
getPath
()),
env
=
theia_env
)
theia_shell_process
=
pexpect
.
spawnu
(
'{}/bin/theia-shell'
.
format
(
self
.
getPath
()),
env
=
theia_env
)
try
:
self
.
addCleanup
(
theia_shell_process
.
wait
)
theia_shell_process
.
expect_exact
(
'Standalone SlapOS for computer `slaprunner` activated'
)
self
.
addCleanup
(
theia_shell_process
.
terminate
)
# Launch slapos node software from theia shell
theia_shell_process
.
expect_exact
(
'Standalone SlapOS for computer `slaprunner` activated'
)
theia_shell_process
.
sendline
(
'slapos node software'
)
theia_shell_process
.
expect
(
'Installing software release %s'
%
self
.
dummy_software_path
)
# Launch slapos node software from theia shell
theia_shell_process
.
expect
(
'Finished software releases.'
)
theia_shell_process
.
sendline
(
'slapos node software'
)
theia_shell_process
.
expect
(
'Installing software release %s'
%
self
.
dummy_software_path
)
# Get the theia shell environment
theia_shell_process
.
expect
(
'Finished software releases.'
)
with
open
(
env_json_path
)
as
f
:
theia_shell_env
=
json
.
load
(
f
)
# Get the theia shell environment
with
open
(
env_json_path
)
as
f
:
# Remove the env.json file to later be sure that a new one has been generated
theia_shell_env
=
json
.
load
(
f
)
os
.
remove
(
env_json_path
)
# Remove the env.json file to later be sure that a new one has been generated
# Launch slapos node software service from the embedded supervisord.
os
.
remove
(
env_json_path
)
# Note that we have two services, slapos-node-software and slapos-node-software-all
# The later uses --all which is what we want to use here, because the software
# Launch slapos node software service from the embedded supervisord.
# is already installed and we want to install it again, this time from supervisor
# Note that we have two services, slapos-node-software and slapos-node-software-all
embedded_run_path
=
self
.
getPath
(
'srv'
,
'runner'
,
'var'
,
'run'
)
# The later uses --all which is what we want to use here, because the software
embedded_supervisord_socket_path
=
_getSupervisordSocketPath
(
embedded_run_path
,
self
.
logger
)
# is already installed and we want to install it again, this time from supervisor
with
getSupervisorRPC
(
embedded_supervisord_socket_path
)
as
embedded_supervisor
:
embedded_run_path
=
self
.
getPath
(
'srv'
,
'runner'
,
'var'
,
'run'
)
previous_stop_time
=
embedded_supervisor
.
getProcessInfo
(
'slapos-node-software-all'
)[
'stop'
]
embedded_supervisord_socket_path
=
_getSupervisordSocketPath
(
embedded_run_path
,
self
.
logger
)
embedded_supervisor
.
startProcess
(
'slapos-node-software-all'
)
with
getSupervisorRPC
(
embedded_supervisord_socket_path
)
as
embedded_supervisor
:
for
_retries
in
range
(
20
):
previous_stop_time
=
embedded_supervisor
.
getProcessInfo
(
'slapos-node-software-all'
)[
'stop'
]
time
.
sleep
(
1
)
embedded_supervisor
.
startProcess
(
'slapos-node-software-all'
)
if
embedded_supervisor
.
getProcessInfo
(
'slapos-node-software-all'
)[
'stop'
]
!=
previous_stop_time
:
for
_retries
in
range
(
20
):
break
time
.
sleep
(
1
)
else
:
if
embedded_supervisor
.
getProcessInfo
(
'slapos-node-software-all'
)[
'stop'
]
!=
previous_stop_time
:
self
.
fail
(
"the supervisord service 'slapos-node-software-all' takes too long to finish"
)
break
else
:
# Get the supervisord environment
self
.
fail
(
"the supervisord service 'slapos-node-software-all' takes too long to finish"
)
with
open
(
env_json_path
)
as
f
:
supervisord_env
=
json
.
load
(
f
)
# Get the supervisord environment
with
open
(
env_json_path
)
as
f
:
# Compare relevant variables from both environments
supervisord_env
=
json
.
load
(
f
)
self
.
maxDiff
=
None
self
.
assertEqual
(
theia_shell_env
[
'PATH'
].
split
(
':'
),
supervisord_env
[
'PATH'
].
split
(
':'
))
# Compare relevant variables from both environments
self
.
assertEqual
(
theia_shell_env
[
'SLAPOS_CONFIGURATION'
],
supervisord_env
[
'SLAPOS_CONFIGURATION'
])
self
.
maxDiff
=
None
self
.
assertEqual
(
theia_shell_env
[
'SLAPOS_CLIENT_CONFIGURATION'
],
supervisord_env
[
'SLAPOS_CLIENT_CONFIGURATION'
])
self
.
assertEqual
(
theia_shell_env
[
'PATH'
].
split
(
':'
),
supervisord_env
[
'PATH'
].
split
(
':'
))
self
.
assertEqual
(
theia_shell_env
[
'HOME'
],
supervisord_env
[
'HOME'
])
self
.
assertEqual
(
theia_shell_env
[
'SLAPOS_CONFIGURATION'
],
supervisord_env
[
'SLAPOS_CONFIGURATION'
])
self
.
assertEqual
(
theia_shell_env
[
'SLAPOS_CLIENT_CONFIGURATION'
],
supervisord_env
[
'SLAPOS_CLIENT_CONFIGURATION'
])
finally
:
self
.
assertEqual
(
theia_shell_env
[
'HOME'
],
supervisord_env
[
'HOME'
])
# Cleanup the theia shell process
theia_shell_process
.
terminate
()
theia_shell_process
.
wait
()
class
ResilientTheiaMixin
(
object
):
class
ResilientTheiaMixin
(
object
):
...
...
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