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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
slapos.toolbox
Commits
7ce173e1
Commit
7ce173e1
authored
8 years ago
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test_runner: adds tests for the isSoftwareReleaseReady function
parent
76f2188a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
13 deletions
+77
-13
slapos/runner/utils.py
slapos/runner/utils.py
+12
-12
slapos/test/test_runner.py
slapos/test/test_runner.py
+65
-1
No files found.
slapos/runner/utils.py
View file @
7ce173e1
...
...
@@ -644,7 +644,7 @@ def getSoftwareReleaseName(config):
project = open(sr_profile, "r").read().split("/")
software = project[-2]
return software.replace('
', '
_
')
return
"No_name"
return
None
def removeSoftwareRootDirectory(config, md5, folder_name):
"""
...
...
@@ -835,27 +835,29 @@ def readParameters(path):
else:
return "No such file or directory: %s" % path
def isSoftwareReleaseCompleted(config):
software_name = getSoftwareReleaseName(config)
if software_name is None:
return False
elif os.path.exists(os.path.join(config['
runner_workdir
'],
'
softwareLink
', software_name, '
.
completed
')):
return True
else:
return False
def isSoftwareReleaseReady(config):
"""Return 1 if the Software Release has
correctly been deployed, 0 if not,
and 2 if it is currently deploying"""
slapos_software =
(False if config.get('
slapos
-
software
', None) is None else True)
slapos_software =
config.get('
slapos
-
software
', None) is not None
# auto_deploy and auto_run are True only if slapos_software has been declared
auto_deploy = (config['
auto_deploy
'] in TRUE_VALUES) and slapos_software
auto_run = (config['
autorun
'] in TRUE_VALUES) and slapos_software
project = os.path.join(config['
etc_dir
'], '
.
project
')
if not ( os.path.exists(project) and (auto_run or auto_deploy) ):
return "0"
path = open(project, 'r').readline().strip()
software_name = path
if software_name[-1] == '
/
':
software_name = software_name[:-1]
software_name = software_name.split('
/
')[-1]
updateInstanceParameter(config)
config_SR_folder(config)
if os.path.exists(os.path.join(config['
runner_workdir
'],
'
softwareLink
', software_name, '
.
completed
')):
if isSoftwareReleaseCompleted(config):
if auto_run:
runSlapgridUntilSuccess(config, '
instance
')
return "1"
...
...
@@ -864,8 +866,6 @@ def isSoftwareReleaseReady(config):
return "2"
elif auto_deploy:
runSoftwareWithLock(config)
config_SR_folder(config)
time.sleep(15)
if auto_run:
runSlapgridUntilSuccess(config, '
instance
')
return "2"
...
...
This diff is collapsed.
Click to expand it.
slapos/test/test_runner.py
View file @
7ce173e1
...
...
@@ -92,11 +92,13 @@ class TestRunnerBackEnd(unittest.TestCase):
@
mock
.
patch
(
'os.mkdir'
)
@
mock
.
patch
(
'slapos.runner.utils.updateProxy'
)
@
mock
.
patch
(
'slapos.runner.utils.requestInstance'
)
@
mock
.
patch
(
'slapos.runner.utils.config_SR_folder'
)
def
_runSlapgridWithLockMakesCorrectCallsToSupervisord
(
self
,
run_slapgrid_function
,
process_name
,
mock_configSRFolder
,
mock_requestInstance
,
mock_updateProxy
,
mock_mkdir
):
"""
...
...
@@ -105,7 +107,8 @@ class TestRunnerBackEnd(unittest.TestCase):
"""
mock_updateProxy
.
return_value
=
True
cwd
=
os
.
getcwd
()
config
=
{
'software_root'
:
os
.
path
.
join
(
cwd
,
'software'
),
config
=
{
'etc_dir'
:
cwd
,
'software_root'
:
os
.
path
.
join
(
cwd
,
'software'
),
'software_log'
:
os
.
path
.
join
(
cwd
,
'software.log'
),
'instance_root'
:
os
.
path
.
join
(
cwd
,
'software'
),
'instance_log'
:
os
.
path
.
join
(
cwd
,
'software.log'
)}
...
...
@@ -296,6 +299,67 @@ class TestRunnerBackEnd(unittest.TestCase):
# if running software fails, then no need to try to deploy instances
self
.
assertEqual
(
mock_runInstanceWithLock
.
call_count
,
0
)
@
mock
.
patch
(
'os.path.exists'
)
@
mock
.
patch
(
'slapos.runner.utils.updateInstanceParameter'
)
@
mock
.
patch
(
'slapos.runner.utils.isSoftwareReleaseCompleted'
)
@
mock
.
patch
(
'slapos.runner.utils.runSlapgridUntilSuccess'
)
@
mock
.
patch
(
'slapos.runner.utils.isSoftwareRunning'
)
@
mock
.
patch
(
'slapos.runner.utils.runSoftwareWithLock'
)
def
test_isSoftwareReleaseReady
(
self
,
mock_runSoftwareWithLock
,
mock_isSoftwareRunning
,
mock_runSlapgridUntilSuccess
,
mock_isSoftwareReleaseCompleted
,
mock_updateInstanceParameter
,
mock_path_exists
):
cwd
=
os
.
getcwd
()
config
=
{
'etc_dir'
:
cwd
,
'runner_workdir'
:
cwd
,
'slapos-software'
:
'slapos/dummy'
,
'auto_deploy'
:
False
,
'autorun'
:
False
,
}
# Every parameter is False, so do nothing
self
.
assertEqual
(
runner_utils
.
isSoftwareReleaseReady
(
config
),
'0'
)
# We define a software, so from now we expect to build
mock_path_exists
.
return_value
=
True
# auto_deploy is True, so Software Release should build
config
.
update
({
'auto_deploy'
:
True
,
})
# slapgrid-sr is running
mock_isSoftwareRunning
.
return_value
=
True
mock_isSoftwareReleaseCompleted
.
return_value
=
False
self
.
assertEqual
(
runner_utils
.
isSoftwareReleaseReady
(
config
),
'2'
)
# SR is not built, and slapgrid-sr is not running, so it should be started
mock_isSoftwareRunning
.
return_value
=
False
mock_isSoftwareReleaseCompleted
.
return_value
=
False
self
.
assertEqual
(
runner_utils
.
isSoftwareReleaseReady
(
config
),
'2'
)
self
.
assertTrue
(
mock_runSoftwareWithLock
.
called
)
mock_runSoftwareWithLock
.
reset_mock
()
# SR is built
mock_isSoftwareReleaseCompleted
.
return_value
=
True
self
.
assertEqual
(
runner_utils
.
isSoftwareReleaseReady
(
config
),
'1'
)
# If autorun is True, Instance is expected to build too
config
.
update
({
'autorun'
:
True
,
})
mock_isSoftwareRunning
.
return_value
=
False
mock_isSoftwareReleaseCompleted
.
return_value
=
True
self
.
assertEqual
(
runner_utils
.
isSoftwareReleaseReady
(
config
),
'1'
)
mock_runSlapgridUntilSuccess
.
assert_called_with
(
config
,
'instance'
)
@
unittest
.
skip
(
'No scenario defined'
)
def
test_autoDeployWontEraseExistingInstances
(
self
):
raise
NotImplementedError
...
...
This diff is collapsed.
Click to expand it.
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