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
0
Merge Requests
0
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
Rafael Monnerat
slapos.core
Commits
a6a347d8
Commit
a6a347d8
authored
Jun 28, 2018
by
Guillaume Hervier
Committed by
Rafael Monnerat
Jul 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapgrid_tests: Add tests for manager lifecycle
parent
2163b10a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
0 deletions
+96
-0
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+18
-0
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+78
-0
No files found.
slapos/tests/slapformat.py
View file @
a6a347d8
...
@@ -44,6 +44,8 @@ import pwd
...
@@ -44,6 +44,8 @@ import pwd
import
time
import
time
import
mock
import
mock
from
.slapgrid
import
DummyManager
USER_LIST
=
[]
USER_LIST
=
[]
GROUP_LIST
=
[]
GROUP_LIST
=
[]
INTERFACE_DICT
=
{}
INTERFACE_DICT
=
{}
...
@@ -882,5 +884,21 @@ class TestUser(SlapformatMixin):
...
@@ -882,5 +884,21 @@ class TestUser(SlapformatMixin):
user
=
slapos
.
format
.
User
(
'doesnotexistsyet'
)
user
=
slapos
.
format
.
User
(
'doesnotexistsyet'
)
self
.
assertFalse
(
user
.
isAvailable
())
self
.
assertFalse
(
user
.
isAvailable
())
class
TestSlapformatManagerLifecycle
(
SlapformatMixin
):
def
test_partition_format
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
,
instance_root
=
'/instance_root'
,
software_root
=
'software_root'
)
manager
=
DummyManager
()
computer
.
_manager_list
=
[
manager
]
computer
.
format
(
alter_user
=
False
,
alter_network
=
False
)
self
.
assertEqual
(
manager
.
sequence
,
[
'format'
,
'formatTearDown'
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
slapos/tests/slapgrid.py
View file @
a6a347d8
...
@@ -44,6 +44,7 @@ import re
...
@@ -44,6 +44,7 @@ import re
import
xml_marshaller
import
xml_marshaller
from
mock
import
patch
from
mock
import
patch
from
zope
import
interface
import
slapos.slap.slap
import
slapos.slap.slap
import
slapos.grid.utils
import
slapos.grid.utils
...
@@ -52,6 +53,7 @@ from slapos.grid.utils import md5digest
...
@@ -52,6 +53,7 @@ from slapos.grid.utils import md5digest
from
slapos.grid.watchdog
import
Watchdog
from
slapos.grid.watchdog
import
Watchdog
from
slapos.grid
import
SlapObject
from
slapos.grid
import
SlapObject
from
slapos.grid.SlapObject
import
WATCHDOG_MARK
from
slapos.grid.SlapObject
import
WATCHDOG_MARK
from
slapos.manager.interface
import
IManager
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
import
slapos.grid.SlapObject
import
slapos.grid.SlapObject
from
slapos
import
manager
as
slapmanager
from
slapos
import
manager
as
slapmanager
...
@@ -108,6 +110,7 @@ touch worked
...
@@ -108,6 +110,7 @@ touch worked
class
BasicMixin
(
object
):
class
BasicMixin
(
object
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
manager_list
=
[]
self
.
software_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'software'
)
self
.
software_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'software'
)
self
.
instance_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'instance'
)
self
.
instance_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'instance'
)
if
os
.
environ
.
has_key
(
'SLAPGRID_INSTANCE_ROOT'
):
if
os
.
environ
.
has_key
(
'SLAPGRID_INSTANCE_ROOT'
):
...
@@ -131,6 +134,7 @@ class BasicMixin(object):
...
@@ -131,6 +134,7 @@ class BasicMixin(object):
self
.
buildout
,
self
.
buildout
,
develop
=
develop
,
develop
=
develop
,
logger
=
logging
.
getLogger
())
logger
=
logging
.
getLogger
())
self
.
grid
.
_manager_list
=
self
.
manager_list
# monkey patch buildout bootstrap
# monkey patch buildout bootstrap
def
dummy
(
*
args
,
**
kw
):
def
dummy
(
*
args
,
**
kw
):
...
@@ -360,6 +364,8 @@ class ComputerForTest(object):
...
@@ -360,6 +364,8 @@ class ComputerForTest(object):
# XXX hardcoded to first software release!
# XXX hardcoded to first software release!
software
=
self
.
software_list
[
0
]
software
=
self
.
software_list
[
0
]
software
.
sequence
.
append
(
url
.
path
)
software
.
sequence
.
append
(
url
.
path
)
if
url
.
path
==
'/availableSoftwareRelease'
:
return
{
'status_code'
:
200
}
if
url
.
path
==
'/buildingSoftwareRelease'
:
if
url
.
path
==
'/buildingSoftwareRelease'
:
return
{
'status_code'
:
200
}
return
{
'status_code'
:
200
}
if
url
.
path
==
'/softwareReleaseError'
:
if
url
.
path
==
'/softwareReleaseError'
:
...
@@ -545,6 +551,34 @@ touch worked"""):
...
@@ -545,6 +551,34 @@ touch worked"""):
fout
.
write
(
str
(
periodicity
))
fout
.
write
(
str
(
periodicity
))
class
DummyManager
(
object
):
interface
.
implements
(
IManager
)
def
__init__
(
self
):
self
.
sequence
=
[]
def
format
(
self
,
computer
):
self
.
sequence
.
append
(
'format'
)
def
formatTearDown
(
self
,
computer
):
self
.
sequence
.
append
(
'formatTearDown'
)
def
software
(
self
,
software
):
self
.
sequence
.
append
(
'software'
)
def
softwareTearDown
(
self
,
software
):
self
.
sequence
.
append
(
'softwareTearDown'
)
def
instance
(
self
,
partition
):
self
.
sequence
.
append
(
'instance'
)
def
instanceTearDown
(
self
,
partition
):
self
.
sequence
.
append
(
'instanceTearDown'
)
def
report
(
self
,
partition
):
self
.
sequence
.
append
(
'report'
)
class
TestSlapgridCPWithMaster
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPWithMaster
(
MasterMixin
,
unittest
.
TestCase
):
def
test_nothing_to_do
(
self
):
def
test_nothing_to_do
(
self
):
...
@@ -2924,3 +2958,47 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
...
@@ -2924,3 +2958,47 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
partition_supervisord_config = self._read_instance_supervisord_config()
partition_supervisord_config = self._read_instance_supervisord_config()
self.assertNotIn('socat-htcpcp-1234', partition_supervisord_config)
self.assertNotIn('socat-htcpcp-1234', partition_supervisord_config)
self.assertNotIn('socat HTCPCP4-LISTEN:1234,fork HTCPCP4:127.0.0.1:4321', partition_supervisord_config)
self.assertNotIn('socat HTCPCP4-LISTEN:1234,fork HTCPCP4:127.0.0.1:4321', partition_supervisord_config)
class TestSlapgridManagerLifecycle(MasterMixin, unittest.TestCase):
def setUp(self):
MasterMixin.setUp(self)
self.manager = DummyManager()
self.manager_list = [self.manager]
self.setSlapgrid()
self.computer = ComputerForTest(self.software_root, self.instance_root)
def _mock_requests(self):
return httmock.HTTMock(self.computer.request_handler)
def test_partition_instance(self):
with self._mock_requests():
partition = self.computer.instance_list[0]
partition.requested_state = 'started'
partition.software.setBuildout(WRAPPER_CONTENT)
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation', '/availableComputerPartition',
'/startedComputerPartition'])
self.assertEqual(partition.state, 'started')
self.assertEqual(self.manager.sequence,
['instance', 'instanceTearDown'])
def test_partition_software(self):
with self._mock_requests():
software = self.computer.software_list[0]
buildout = """#!/bin/sh
echo "
Kitty
cute
kitkat
"
"""
software.setBuildout(buildout)
self.launchSlapgridSoftware()
self.assertEqual(self.manager.sequence,
['software', 'softwareTearDown'])
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