Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
89a4334c
Commit
89a4334c
authored
Aug 25, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Plain Diff
Utilities for testing
See merge request
!245
parents
bbcbab07
75eafe55
Pipeline
#11144
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
slapos/testing/utils.py
slapos/testing/utils.py
+54
-0
No files found.
slapos/testing/utils.py
View file @
89a4334c
...
...
@@ -29,6 +29,10 @@
import
socket
import
hashlib
import
unittest
import
os
import
subprocess
import
sys
import
json
from
contextlib
import
closing
try
:
...
...
@@ -60,6 +64,56 @@ def getPortFromPath(path):
16
)
%
(
65535
-
1024
)
def
getPromisePluginParameterDict
(
filepath
):
# type: (str) -> dict
"""Load the slapos monitor plugin and returns the configuration used by this plugin.
This allow to check that monitoring plugin are using a proper config.
"""
extra_config_dict_json
=
subprocess
.
check_output
([
sys
.
executable
,
"-c"
,
"""
import json, sys
with open(sys.argv[1]) as f:
exec(f.read())
print(json.dumps(extra_config_dict))
"""
,
filepath
,
])
return
json
.
loads
(
extra_config_dict_json
)
class
CrontabMixin
(
object
):
computer_partition_root_path
=
None
# type: str
def
_getCrontabCommand
(
self
,
crontab_name
):
# type: (str) -> str
"""Read a crontab and return the command that is executed.
"""
with
open
(
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'etc'
,
'cron.d'
,
crontab_name
,
))
as
f
:
crontab_spec
=
f
.
read
()
return
" "
.
join
(
crontab_spec
.
split
()[
5
:])
def
_executeCrontabAtDate
(
self
,
crontab_name
,
date
):
# type: (str, str) -> None
"""Executes a crontab as if the current date was `date`.
`date` will be passed to faketime time command, it can also
be a relative time.
"""
crontab_command
=
self
.
_getCrontabCommand
(
crontab_name
)
subprocess
.
check_call
(
"faketime {date} bash -o pipefail -e -c '{crontab_command}'"
.
format
(
**
locals
()),
shell
=
True
,
)
class
ImageComparisonTestCase
(
unittest
.
TestCase
):
"""TestCase with utility method to compare images.
...
...
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