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
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
Xavier Thompson
slapos
Commits
622a834e
Commit
622a834e
authored
Apr 13, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/theia: Add resiliency tests
parent
02e5acf0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
185 additions
and
0 deletions
+185
-0
software/theia/test/resilience_dummy/README.md
software/theia/test/resilience_dummy/README.md
+12
-0
software/theia/test/resilience_dummy/instance.cfg.in
software/theia/test/resilience_dummy/instance.cfg.in
+21
-0
software/theia/test/resilience_dummy/software.cfg
software/theia/test/resilience_dummy/software.cfg
+26
-0
software/theia/test/test.py
software/theia/test/test.py
+126
-0
No files found.
software/theia/test/resilience_dummy/README.md
0 → 100644
View file @
622a834e
<<<<<<< HEAD
# Dummy Software
A very simple SR that dumps the environment in JSON format during installation.
=======
# Resilience Dummy
A very simple SR that is entirely self contained.
It doesn't depend on any files other than those it this directory.
In particular it doesn't extent stack/slapos.cfg.
It takes very little time to compile and deploy.
>>>>>>> software/theia: Add resiliency tests
software/theia/test/resilience_dummy/instance.cfg.in
0 → 100644
View file @
622a834e
[buildout]
parts =
log-writer
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[directory]
recipe = plone.recipe.command
home = $${buildout:directory}
etc = $${:home}/etc
run = $${:etc}/run
command = mkdir -p $${:run}
[log-writer]
recipe = slapos.recipe.template:jinja2
template = inline:#!/bin/sh
echo "Hello : $(date)" >> $${directory:home}/log.log
rendered = $${directory:run}/log-writer
mode = 700
software/theia/test/resilience_dummy/software.cfg
0 → 100644
View file @
622a834e
[buildout]
find-links +=
http://www.nexedi.org/static/packages/source/
http://www.nexedi.org/static/packages/source/slapos.buildout/
parts =
instance-template
plone-recipe-command
versions = versions
[plone-recipe-command]
recipe = zc.recipe.egg
eggs = plone.recipe.command
[instance-template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in
output = ${buildout:directory}/instance.cfg
mode = 0644
[versions]
setuptools = 44.0.0
zc.buildout = 2.7.1+slapos010
zc.recipe.egg = 2.0.3+slapos003
software/theia/test/test.py
View file @
622a834e
...
@@ -34,6 +34,7 @@ import tempfile
...
@@ -34,6 +34,7 @@ import tempfile
import
time
import
time
import
re
import
re
import
json
import
json
import
shutil
from
six.moves.urllib.parse
import
urlparse
,
urljoin
from
six.moves.urllib.parse
import
urlparse
,
urljoin
import
pexpect
import
pexpect
...
@@ -312,3 +313,128 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -312,3 +313,128 @@ class TestTheiaEnv(TheiaTestCase):
# Cleanup the theia shell process
# Cleanup the theia shell process
theia_shell_process
.
terminate
()
theia_shell_process
.
terminate
()
theia_shell_process
.
wait
()
theia_shell_process
.
wait
()
class
ResilientTheiaTestCase
(
TheiaTestCase
):
@
classmethod
def
_getTypePartition
(
cls
,
software_type
):
software_url
=
cls
.
getSoftwareURL
()
for
computer_partition
in
cls
.
slap
.
computer
.
getComputerPartitionList
():
partition_url
=
computer_partition
.
getSoftwareRelease
().
_software_release
partition_type
=
computer_partition
.
getType
()
if
partition_url
==
software_url
and
partition_type
==
software_type
:
return
computer_partition
raise
"Theia %s partition not found"
%
software_type
@
classmethod
def
_getTypePartitionId
(
cls
,
software_type
):
return
cls
.
_getTypePartition
(
software_type
).
getId
()
@
classmethod
def
_getTypePartitionPath
(
cls
,
software_type
,
*
paths
):
return
os
.
path
.
join
(
cls
.
slap
.
_instance_root
,
cls
.
_getTypePartitionId
(
software_type
),
*
paths
)
@
classmethod
def
_getSlapos
(
cls
,
software_type
=
'export'
):
return
cls
.
_getTypePartitionPath
(
software_type
,
'srv'
,
'runner'
,
'bin'
,
'slapos'
)
@
classmethod
def
_deployEmbeddedSoftware
(
cls
,
software_url
,
instance_name
):
slapos
=
cls
.
_getSlapos
()
subprocess
.
check_call
((
slapos
,
'supply'
,
software_url
,
'slaprunner'
))
subprocess
.
check_call
((
slapos
,
'node'
,
'software'
))
subprocess
.
check_call
((
slapos
,
'request'
,
instance_name
,
software_url
))
subprocess
.
check_call
((
slapos
,
'node'
,
'instance'
))
@
classmethod
def
getInstanceSoftwareType
(
cls
):
return
'resilient'
@
classmethod
def
getInstanceParameterDict
(
cls
):
return
{
'autorun'
:
'stopped'
}
@
classmethod
def
setUpClass
(
cls
):
super
(
ResilientTheiaTestCase
,
cls
).
setUpClass
()
# Patch the computer root path to that of the export theia instance
cls
.
computer_partition_root_path
=
cls
.
_getTypePartitionPath
(
'export'
)
class
TestTheiaResilientInterface
(
TestTheia
,
ResilientTheiaTestCase
):
pass
class
TestTheiaResilientWithSR
(
TestTheiaWithSR
,
ResilientTheiaTestCase
):
pass
class
TestTheiaExportImport
(
ResilientTheiaTestCase
):
def
_getTestSoftwareUrl
(
self
):
try
:
return
self
.
_test_software_url
except
AttributeError
:
# Copy ./resilience_dummy SR in export theia ~/srv/project/dummy
dummy_target_path
=
self
.
_getTypePartitionPath
(
'export'
,
'srv'
,
'project'
,
'dummy'
)
shutil
.
copytree
(
'resilience_dummy'
,
dummy_target_path
)
self
.
_test_software_url
=
os
.
path
.
join
(
dummy_target_path
,
'software.cfg'
)
return
self
.
_test_software_url
def
_getAdaptedTestSoftwareUrl
(
self
):
return
self
.
_getTypePartitionPath
(
'import'
,
'srv'
,
'project'
,
'dummy'
,
'software.cfg'
)
def
test_export_import
(
self
):
# Deploy dummy instance in export partition
test_software_url
=
self
.
_getTestSoftwareUrl
()
self
.
_deployEmbeddedSoftware
(
test_software_url
,
'dummy_instance'
)
# Check that dummy instance was properly deployed
log_path
=
self
.
_getTypePartitionPath
(
'export'
,
'srv'
,
'runner'
,
'instance'
,
'slappart0'
,
'log.log'
)
with
open
(
log_path
)
as
f
:
initial_log
=
f
.
readlines
()
self
.
assertEqual
(
len
(
initial_log
),
1
)
self
.
assertTrue
(
initial_log
[
0
].
startswith
(
"Hello"
),
initial_log
[
0
])
# Call export script manually
theia_export_script
=
self
.
_getTypePartitionPath
(
'export'
,
'bin'
,
'theia-export-script'
)
subprocess
.
check_call
((
theia_export_script
,))
# Copy <export>/srv/backup/theia to <import>/srv/backup/theia manually
export_backup_path
=
self
.
_getTypePartitionPath
(
'export'
,
'srv'
,
'backup'
,
'theia'
)
import_backup_path
=
self
.
_getTypePartitionPath
(
'import'
,
'srv'
,
'backup'
,
'theia'
)
shutil
.
rmtree
(
import_backup_path
)
shutil
.
copytree
(
export_backup_path
,
import_backup_path
)
# Call the import script manually
theia_import_script
=
self
.
_getTypePartitionPath
(
'import'
,
'bin'
,
'theia-import-script'
)
subprocess
.
check_call
((
theia_import_script
,))
# Check that the software url is correct
test_adapted_url
=
self
.
_getAdaptedTestSoftwareUrl
()
proxy_content
=
subprocess
.
check_output
((
self
.
_getSlapos
(
'import'
),
'proxy'
,
'show'
))
self
.
assertIn
(
test_adapted_url
,
proxy_content
)
if
test_adapted_url
!=
test_software_url
:
self
.
assertNotIn
(
test_software_url
,
proxy_content
)
# Check that the dummy instance is not yet started
log_path
=
self
.
_getTypePartitionPath
(
'import'
,
'srv'
,
'runner'
,
'instance'
,
'slappart0'
,
'log.log'
)
with
open
(
log_path
)
as
f
:
copied_log
=
f
.
readlines
()
self
.
assertEqual
(
copied_log
,
initial_log
)
# Start the dummy instance
subprocess
.
check_call
((
self
.
_getSlapos
(
'import'
),
'node'
,
'instance'
))
# Check that dummy instance was properly re-deployed
log_path
=
self
.
_getTypePartitionPath
(
'import'
,
'srv'
,
'runner'
,
'instance'
,
'slappart0'
,
'log.log'
)
with
open
(
log_path
)
as
f
:
new_log
=
f
.
readlines
()
self
.
assertEqual
(
len
(
new_log
),
2
)
self
.
assertEqual
(
new_log
[
0
],
initial_log
[
0
])
self
.
assertTrue
(
new_log
[
1
].
startswith
(
"Hello"
),
new_log
[
1
])
class
TestTheiaExportImportWebURL
(
TestTheiaExportImport
):
def
_getTestSoftwareUrl
(
self
):
return
"https://lab.nexedi.com/xavier_thompson/slapos/raw/a0f0ac90/software/theia/test/dummy/software.cfg"
_getAdaptedTestSoftwareUrl
=
_getTestSoftwareUrl
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