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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Roque
slapos
Commits
f77d0cc2
Commit
f77d0cc2
authored
May 16, 2024
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/kvm: dcron mock
Make it possible to mock any specific cron entry.
parent
a92e2d03
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
4 deletions
+115
-4
software/kvm/buildout.hash.cfg
software/kvm/buildout.hash.cfg
+1
-1
software/kvm/instance-kvm.cfg.jinja2
software/kvm/instance-kvm.cfg.jinja2
+0
-1
software/kvm/test/buildout.hash.cfg
software/kvm/test/buildout.hash.cfg
+22
-0
software/kvm/test/test-instance-kvm-export-mock.cfg.jinja2
software/kvm/test/test-instance-kvm-export-mock.cfg.jinja2
+21
-0
software/kvm/test/test-instance.cfg.in
software/kvm/test/test-instance.cfg.in
+12
-0
software/kvm/test/test-software.cfg
software/kvm/test/test-software.cfg
+19
-0
software/kvm/test/test.py
software/kvm/test/test.py
+40
-2
No files found.
software/kvm/buildout.hash.cfg
View file @
f77d0cc2
...
@@ -19,7 +19,7 @@ md5sum = 9ae66fb63a3cdd8072582622aa1bb36c
...
@@ -19,7 +19,7 @@ md5sum = 9ae66fb63a3cdd8072582622aa1bb36c
[template-kvm]
[template-kvm]
filename = instance-kvm.cfg.jinja2
filename = instance-kvm.cfg.jinja2
md5sum =
bd3a7229e4fdfa9372ee61b6054acf78
md5sum =
20554e40f9fe666839ef86ff8216cebf
[template-kvm-cluster]
[template-kvm-cluster]
filename = instance-kvm-cluster.cfg.jinja2.in
filename = instance-kvm-cluster.cfg.jinja2.in
...
...
software/kvm/instance-kvm.cfg.jinja2
View file @
f77d0cc2
...
@@ -715,7 +715,6 @@ cron-entries = ${directory:cron-entries}
...
@@ -715,7 +715,6 @@ cron-entries = ${directory:cron-entries}
crontabs = ${directory:crontabs}
crontabs = ${directory:crontabs}
cronstamps = ${directory:cronstamps}
cronstamps = ${directory:cronstamps}
catcher = ${cron-simplelogger:wrapper}
catcher = ${cron-simplelogger:wrapper}
binary = ${directory:bin}/crond_raw
[cron-service]
[cron-service]
recipe = slapos.cookbook:wrapper
recipe = slapos.cookbook:wrapper
...
...
software/kvm/test/buildout.hash.cfg
0 → 100644
View file @
f77d0cc2
# THIS IS NOT A BUILDOUT FILE, despite purposedly using a compatible syntax.
# The only allowed lines here are (regexes):
# - "^#" comments, copied verbatim
# - "^[" section beginings, copied verbatim
# - lines containing an "=" sign which must fit in the following categorie.
# - "^\s*filename\s*=\s*path\s*$" where "path" is relative to this file
# Copied verbatim.
# - "^\s*hashtype\s*=.*" where "hashtype" is one of the values supported
# by the re-generation script.
# Re-generated.
# - other lines are copied verbatim
# Substitution (${...:...}), extension ([buildout] extends = ...) and
# section inheritance (< = ...) are NOT supported (but you should really
# not need these here).
[template-test]
filename = test-instance.cfg.in
md5sum = 466c7324a44e0cd8ae688699aab62d5f
[template-kvm-export-mock]
filename = test-instance-kvm-export-mock.cfg.jinja2
md5sum = acf0b9a916e1411f184eb4f94c7c2abb
software/kvm/test/test-instance-kvm-export-mock.cfg.jinja2
0 → 100644
View file @
f77d0cc2
[buildout]
extends = {{ template_kvm_export }}
parts +=
cron-entry-environment
[directory]
cron-d-mock = ${:var}/cron-d-mock
[cron-entry-environment]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = environment
frequency = * * * * *
command = ${buildout:executable} -c 'import os ; import json ; print(json.dumps(dict(os.environ)))' > ${directory:var}/cron-environment.json
[cron-entry-backup]
recipe = slapos.recipe.template:jinja2
inline =
${:command}
output = ${directory:cron-d-mock}/${:name}
software/kvm/test/test-instance.cfg.in
0 → 100644
View file @
f77d0cc2
[buildout]
extends = ${template:output}
[dynamic-template-kvm-export-mock]
recipe = slapos.recipe.template:jinja2
url = ${template-kvm-export-mock:location}/${template-kvm-export-mock:filename}
output = $${buildout:directory}/template-kvm-export-mock.cfg
context =
key template_kvm_export dynamic-template-kvm-export:output
[switch_softwaretype]
kvm-export = dynamic-template-kvm-export-mock:output
software/kvm/test/test-software.cfg
0 → 100644
View file @
f77d0cc2
[buildout]
extends =
../software.cfg
buildout.hash.cfg
parts +=
template-test
[template]
output = ${buildout:directory}/template-original.cfg
[template-test]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/template.cfg
[template-kvm-export-mock]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:filename}
software/kvm/test/test.py
View file @
f77d0cc2
...
@@ -59,8 +59,7 @@ skipUnlessKvm = unittest.skipUnless(has_kvm, 'kvm not loaded or not allowed')
...
@@ -59,8 +59,7 @@ skipUnlessKvm = unittest.skipUnless(has_kvm, 'kvm not loaded or not allowed')
if
has_kvm
:
if
has_kvm
:
setUpModule
,
InstanceTestCase
=
makeModuleSetUpAndTestCaseClass
(
setUpModule
,
InstanceTestCase
=
makeModuleSetUpAndTestCaseClass
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'test-software.cfg'
))
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
'software.cfg'
)))
# XXX Keep using slapos node instance --all, because of missing promises
# XXX Keep using slapos node instance --all, because of missing promises
InstanceTestCase
.
slap
.
_force_slapos_node_instance_all
=
True
InstanceTestCase
.
slap
.
_force_slapos_node_instance_all
=
True
else
:
else
:
...
@@ -767,6 +766,45 @@ class TestAccessKvmClusterBootstrap(MonitorAccessMixin, KVMTestCase):
...
@@ -767,6 +766,45 @@ class TestAccessKvmClusterBootstrap(MonitorAccessMixin, KVMTestCase):
self.assertIn('
<
title
>
noVNC
</
title
>
', result.text)
self.assertIn('
<
title
>
noVNC
</
title
>
', result.text)
class CronMixin(object):
def setUp(self):
super().setUp()
# wait until all mocked partition have var/cron-environment.json
for i in range(20):
missing_list = []
for mocked in glob.glob(os.path.join(
self.slap._instance_root, '
*
', '
var
', '
cron
-
d
-
mock
')):
cron_environment = os.path.join(
'
/
', *mocked.split('
/
')[:-2], '
var
', '
cron
-
environment
.
json
')
if not os.path.exists(cron_environment):
missing_list.append(cron_environment)
if len(missing_list) == 0:
break
time.sleep(1)
else:
raise ValueError('
Missing
cron
environment
', '
'.join(missing_list))
@classmethod
def executeCronDMockJob(cls, instance_type, cron):
jobpath = cls.getPartitionPath(
instance_type, '
var
', '
cron
-
d
-
mock
', cron)
with open(
cls.getPartitionPath(
'
kvm
-
export
', '
var
', '
cron
-
environment
.
json
')) as fh:
cron_environment = json.load(fh)
job_list = []
with open(jobpath, 'r') as fh:
for job in fh.readlines():
job = job.strip()
job_list.append(job)
job_list_output = []
for job in job_list:
job_list_output.append(subprocess.run(
job, env=cron_environment, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT))
return job_list_output
@skipUnlessKvm
@skipUnlessKvm
class TestInstanceResilient(KVMTestCase, KvmMixin):
class TestInstanceResilient(KVMTestCase, KvmMixin):
__partition_reference__ = '
ir
'
__partition_reference__ = '
ir
'
...
...
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