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
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
Titouan Soulard
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
nexedi/slapos.core!245
parents
bbcbab07
75eafe55
Changes
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