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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
import
time
import
mock
from
.slapgrid
import
DummyManager
USER_LIST
=
[]
GROUP_LIST
=
[]
INTERFACE_DICT
=
{}
...
...
@@ -882,5 +884,21 @@ class TestUser(SlapformatMixin):
user
=
slapos
.
format
.
User
(
'doesnotexistsyet'
)
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__'
:
unittest
.
main
()
slapos/tests/slapgrid.py
View file @
a6a347d8
...
...
@@ -44,6 +44,7 @@ import re
import
xml_marshaller
from
mock
import
patch
from
zope
import
interface
import
slapos.slap.slap
import
slapos.grid.utils
...
...
@@ -52,6 +53,7 @@ from slapos.grid.utils import md5digest
from
slapos.grid.watchdog
import
Watchdog
from
slapos.grid
import
SlapObject
from
slapos.grid.SlapObject
import
WATCHDOG_MARK
from
slapos.manager.interface
import
IManager
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
import
slapos.grid.SlapObject
from
slapos
import
manager
as
slapmanager
...
...
@@ -108,6 +110,7 @@ touch worked
class
BasicMixin
(
object
):
def
setUp
(
self
):
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
manager_list
=
[]
self
.
software_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'software'
)
self
.
instance_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'instance'
)
if
os
.
environ
.
has_key
(
'SLAPGRID_INSTANCE_ROOT'
):
...
...
@@ -131,6 +134,7 @@ class BasicMixin(object):
self
.
buildout
,
develop
=
develop
,
logger
=
logging
.
getLogger
())
self
.
grid
.
_manager_list
=
self
.
manager_list
# monkey patch buildout bootstrap
def
dummy
(
*
args
,
**
kw
):
...
...
@@ -360,6 +364,8 @@ class ComputerForTest(object):
# XXX hardcoded to first software release!
software
=
self
.
software_list
[
0
]
software
.
sequence
.
append
(
url
.
path
)
if
url
.
path
==
'/availableSoftwareRelease'
:
return
{
'status_code'
:
200
}
if
url
.
path
==
'/buildingSoftwareRelease'
:
return
{
'status_code'
:
200
}
if
url
.
path
==
'/softwareReleaseError'
:
...
...
@@ -545,6 +551,34 @@ touch worked"""):
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
):
def
test_nothing_to_do
(
self
):
...
...
@@ -2924,3 +2958,47 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
partition_supervisord_config = self._read_instance_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)
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