Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafael Monnerat
slapos.toolbox
Commits
4e2e3c1a
Commit
4e2e3c1a
authored
Aug 12, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test / runner: new tests for runSlapgridUntilSuccess, which provides the base Build&Run action
parent
4589806c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
3 deletions
+73
-3
slapos/test/test_runner.py
slapos/test/test_runner.py
+73
-3
No files found.
slapos/test/test_runner.py
View file @
4e2e3c1a
...
@@ -20,9 +20,14 @@ class TestRunnerBackEnd(unittest.TestCase):
...
@@ -20,9 +20,14 @@ class TestRunnerBackEnd(unittest.TestCase):
runner_utils
.
open
=
open
runner_utils
.
open
=
open
def
tearDown
(
self
):
def
tearDown
(
self
):
htpasswd_file
=
os
.
path
.
join
(
*
(
os
.
getcwd
(),
'.htpasswd'
))
garbage_file_list
=
[
if
os
.
path
.
exists
(
htpasswd_file
):
os
.
path
.
join
(
*
(
os
.
getcwd
(),
'.htpasswd'
)),
os
.
remove
(
htpasswd_file
)
os
.
path
.
join
(
*
(
os
.
getcwd
(),
'.turn-left'
)),
os
.
path
.
join
(
*
(
os
.
getcwd
(),
'slapos-test.cfg'
)),
]
for
garbage_file
in
garbage_file_list
:
if
os
.
path
.
exists
(
garbage_file
):
os
.
remove
(
garbage_file
)
def
_startSupervisord
(
self
):
def
_startSupervisord
(
self
):
cwd
=
os
.
getcwd
()
cwd
=
os
.
getcwd
()
...
@@ -225,6 +230,71 @@ class TestRunnerBackEnd(unittest.TestCase):
...
@@ -225,6 +230,71 @@ class TestRunnerBackEnd(unittest.TestCase):
self
.
assertTrue
(
mock_removeCurrentInstance
.
called
)
self
.
assertTrue
(
mock_removeCurrentInstance
.
called
)
self
.
assertTrue
(
mock_removeSoftwareRootDirectory
.
called
)
self
.
assertTrue
(
mock_removeSoftwareRootDirectory
.
called
)
@
mock
.
patch
(
'slapos.runner.utils.runInstanceWithLock'
)
@
mock
.
patch
(
'slapos.runner.utils.runSoftwareWithLock'
)
def
test_runSoftwareRunOnlyOnceIfSoftwareSuccessfullyCompiledOnFirstTime
(
self
,
mock_runSoftwareWithLock
,
mock_runInstanceWithLock
):
cwd
=
os
.
getcwd
()
config
=
{
'runner_workdir'
:
cwd
,
'etc_dir'
:
cwd
}
build_and_run_parameter_dict
=
{
'run_instance'
:
False
,
'run_software'
:
True
,
'max_run_instance'
:
3
,
'max_run_software'
:
3
,
}
runner_utils
.
saveBuildAndRunParams
(
config
,
build_and_run_parameter_dict
)
# First, configuration is set to only run the compilation of the software release
# Both runSoftwareWithLock and runInstanceWithLock succeed on 1st try
mock_runSoftwareWithLock
.
return_value
=
0
mock_runInstanceWithLock
.
return_value
=
0
runner_utils
.
runSlapgridUntilSuccess
(
config
,
'software'
)
self
.
assertEqual
(
mock_runSoftwareWithLock
.
call_count
,
1
)
self
.
assertEqual
(
mock_runInstanceWithLock
.
call_count
,
0
)
# Second, instanciation should start if compilation succeeded
mock_runSoftwareWithLock
.
reset_mock
()
build_and_run_parameter_dict
.
update
({
'run_instance'
:
True
})
runner_utils
.
saveBuildAndRunParams
(
config
,
build_and_run_parameter_dict
)
runner_utils
.
runSlapgridUntilSuccess
(
config
,
'software'
)
self
.
assertEqual
(
mock_runSoftwareWithLock
.
call_count
,
1
)
self
.
assertEqual
(
mock_runInstanceWithLock
.
call_count
,
1
)
@
mock
.
patch
(
'slapos.runner.utils.runInstanceWithLock'
)
@
mock
.
patch
(
'slapos.runner.utils.runSoftwareWithLock'
)
def
test_runSoftwareDonotRestartForeverEvenIfBuildoutFileIsWrong
(
self
,
mock_runSoftwareWithLock
,
mock_runInstanceWithLock
):
"""
Restarting compilation or instanciation should happen a limited number of
times to prevent useless runs due to a mistaken buildout config.
"""
cwd
=
os
.
getcwd
()
config
=
{
'runner_workdir'
:
cwd
,
'etc_dir'
:
cwd
}
build_and_run_parameter_dict
=
{
'run_instance'
:
True
,
'run_software'
:
True
,
'max_run_instance'
:
3
,
'max_run_software'
:
3
,
}
runner_utils
.
saveBuildAndRunParams
(
config
,
build_and_run_parameter_dict
)
# runSoftwareWithLock always fail and runInstanceWithLock succeeds on 1st try
mock_runSoftwareWithLock
.
return_value
=
1
mock_runInstanceWithLock
.
return_value
=
0
runner_utils
.
runSlapgridUntilSuccess
(
config
,
'software'
)
self
.
assertEqual
(
mock_runSoftwareWithLock
.
call_count
,
build_and_run_parameter_dict
[
'max_run_software'
])
# if running software fails, then no need to try to deploy instances
self
.
assertEqual
(
mock_runInstanceWithLock
.
call_count
,
0
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
random
.
seed
()
random
.
seed
()
...
...
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