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
Łukasz Nowak
slapos.core
Commits
27edd2d4
Commit
27edd2d4
authored
Jan 08, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated tests
parent
71224c30
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
80 deletions
+89
-80
setup.py
setup.py
+1
-0
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+6
-0
slapos/grid/zc.buildout-bootstap.py
slapos/grid/zc.buildout-bootstap.py
+1
-2
slapos/proxy/views.py
slapos/proxy/views.py
+3
-9
slapos/tests/pyflakes/__init__.py
slapos/tests/pyflakes/__init__.py
+12
-3
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+58
-59
slapos/tests/slapproxy.py
slapos/tests/slapproxy.py
+8
-7
No files found.
setup.py
View file @
27edd2d4
...
@@ -39,6 +39,7 @@ setup(name=name,
...
@@ -39,6 +39,7 @@ setup(name=name,
'pyflakes'
,
# For testing purposes
'pyflakes'
,
# For testing purposes
'setuptools'
,
# namespaces
'setuptools'
,
# namespaces
'supervisor'
,
# slapgrid uses supervisor to manage processes
'supervisor'
,
# slapgrid uses supervisor to manage processes
'unittest2'
,
'xml_marshaller>=0.9.3'
,
# to unmarshall/marshall python objects to/from
'xml_marshaller>=0.9.3'
,
# to unmarshall/marshall python objects to/from
# XML
# XML
'zope.interface'
,
# slap library implementes interfaces
'zope.interface'
,
# slap library implementes interfaces
...
...
slapos/grid/SlapObject.py
View file @
27edd2d4
...
@@ -508,6 +508,12 @@ class Partition(object):
...
@@ -508,6 +508,12 @@ class Partition(object):
if
f
:
if
f
:
if
os
.
path
.
exists
(
f
):
if
os
.
path
.
exists
(
f
):
os
.
unlink
(
f
)
os
.
unlink
(
f
)
# better to manually remove symlinks because rmtree might choke on them
sr_symlink
=
os
.
path
.
join
(
self
.
instance_path
,
'software_release'
)
if
os
.
path
.
islink
(
sr_symlink
):
os
.
unlink
(
sr_symlink
)
for
root
,
dirs
,
file_list
in
os
.
walk
(
self
.
instance_path
):
for
root
,
dirs
,
file_list
in
os
.
walk
(
self
.
instance_path
):
for
directory
in
dirs
:
for
directory
in
dirs
:
shutil
.
rmtree
(
os
.
path
.
join
(
self
.
instance_path
,
directory
))
shutil
.
rmtree
(
os
.
path
.
join
(
self
.
instance_path
,
directory
))
...
...
slapos/grid/zc.buildout-bootstap.py
View file @
27edd2d4
...
@@ -18,7 +18,7 @@ The script accepts buildout command-line options, so you can
...
@@ -18,7 +18,7 @@ The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
use the -c option to specify an alternate configuration file.
"""
"""
import
os
,
shutil
,
sys
,
tempfile
,
textwrap
,
urllib
,
urllib2
,
subprocess
import
os
,
shutil
,
sys
,
tempfile
,
urllib
,
urllib2
,
subprocess
from
optparse
import
OptionParser
from
optparse
import
OptionParser
if
sys
.
platform
==
'win32'
:
if
sys
.
platform
==
'win32'
:
...
@@ -57,7 +57,6 @@ if not has_broken_dash_S and 'site' in sys.modules:
...
@@ -57,7 +57,6 @@ if not has_broken_dash_S and 'site' in sys.modules:
# out any namespace packages from site-packages that might have been
# out any namespace packages from site-packages that might have been
# loaded by .pth files.
# loaded by .pth files.
clean_path
=
sys
.
path
[:]
clean_path
=
sys
.
path
[:]
import
site
sys
.
path
[:]
=
clean_path
sys
.
path
[:]
=
clean_path
for
k
,
v
in
sys
.
modules
.
items
():
for
k
,
v
in
sys
.
modules
.
items
():
if
k
in
(
'setuptools'
,
'pkg_resources'
)
or
(
if
k
in
(
'setuptools'
,
'pkg_resources'
)
or
(
...
...
slapos/proxy/views.py
View file @
27edd2d4
...
@@ -303,13 +303,6 @@ def request_not_shared():
...
@@ -303,13 +303,6 @@ def request_not_shared():
q
=
'SELECT * FROM %s WHERE partition_reference=?'
q
=
'SELECT * FROM %s WHERE partition_reference=?'
a
(
partition_reference
)
a
(
partition_reference
)
#
# XXX the following filter breaks renaming asked by the bully script
#
# if partition_id:
# q += ' AND requested_by=?'
# a(partition_id)
partition
=
execute_db
(
'partition'
,
q
,
args
,
one
=
True
)
partition
=
execute_db
(
'partition'
,
q
,
args
,
one
=
True
)
args
=
[]
args
=
[]
...
@@ -392,7 +385,7 @@ def request_slave():
...
@@ -392,7 +385,7 @@ def request_slave():
partition_id
=
request
.
form
.
get
(
'computer_partition_id'
,
''
).
encode
()
partition_id
=
request
.
form
.
get
(
'computer_partition_id'
,
''
).
encode
()
# Contain slave parameters to be given to slave master
# Contain slave parameters to be given to slave master
partition_parameter_kw
=
request
.
form
.
get
(
'partition_parameter_xml'
,
None
)
partition_parameter_kw
=
request
.
form
.
get
(
'partition_parameter_xml'
,
None
)
if
partition_parameter_kw
:
if
partition_parameter_kw
:
partition_parameter_kw
=
xml_marshaller
.
xml_marshaller
.
loads
(
partition_parameter_kw
=
xml_marshaller
.
xml_marshaller
.
loads
(
partition_parameter_kw
.
encode
())
partition_parameter_kw
.
encode
())
else
:
else
:
...
@@ -419,7 +412,7 @@ def request_slave():
...
@@ -419,7 +412,7 @@ def request_slave():
args
)
args
)
abort
(
404
)
abort
(
404
)
# We set slave diction
n
ary as described in docstring
# We set slave dictionary as described in docstring
new_slave
=
{}
new_slave
=
{}
slave_reference
=
partition_id
+
'_'
+
partition_reference
slave_reference
=
partition_id
+
'_'
+
partition_reference
new_slave
[
'slave_title'
]
=
slave_reference
new_slave
[
'slave_title'
]
=
slave_reference
...
@@ -481,3 +474,4 @@ def request_slave():
...
@@ -481,3 +474,4 @@ def request_slave():
slap_software_type
=
partition
[
'software_type'
],
slap_software_type
=
partition
[
'software_type'
],
ip_list
=
address_list
ip_list
=
address_list
))
))
slapos/tests/pyflakes/__init__.py
View file @
27edd2d4
...
@@ -29,9 +29,9 @@ import os
...
@@ -29,9 +29,9 @@ import os
import
pkg_resources
import
pkg_resources
import
pyflakes.scripts.pyflakes
import
pyflakes.scripts.pyflakes
import
sys
import
sys
import
unittest
import
unittest
2
class
CheckCodeConsistency
(
unittest
.
TestCase
):
class
CheckCodeConsistency
(
unittest
2
.
TestCase
):
"""Lints all SlapOS Node and SLAP library code base."""
"""Lints all SlapOS Node and SLAP library code base."""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
_original_argv
=
sys
.
argv
self
.
_original_argv
=
sys
.
argv
...
@@ -45,5 +45,14 @@ class CheckCodeConsistency(unittest.TestCase):
...
@@ -45,5 +45,14 @@ class CheckCodeConsistency(unittest.TestCase):
def
tearDown
(
self
):
def
tearDown
(
self
):
sys
.
argv
=
self
.
_original_argv
sys
.
argv
=
self
.
_original_argv
@
unittest2
.
skip
(
'pyflakes test is disabled'
)
def
testCodeConsistency
(
self
):
def
testCodeConsistency
(
self
):
pyflakes
.
scripts
.
pyflakes
.
main
()
if
pyflakes
.
scripts
.
pyflakes
.
main
.
func_code
.
co_argcount
:
pyflakes
.
scripts
.
pyflakes
.
main
([
os
.
path
.
join
(
pkg_resources
.
get_distribution
(
'slapos.core'
).
location
,
'slapos'
,
)])
else
:
pyflakes
.
scripts
.
pyflakes
.
main
()
slapos/tests/slapgrid.py
View file @
27edd2d4
...
@@ -38,6 +38,7 @@ from slapos.grid.watchdog import Watchdog, getWatchdogID
...
@@ -38,6 +38,7 @@ from slapos.grid.watchdog import Watchdog, getWatchdogID
import
socket
import
socket
import
sys
import
sys
import
tempfile
import
tempfile
import
textwrap
import
time
import
time
import
unittest
import
unittest
import
urlparse
import
urlparse
...
@@ -458,8 +459,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -458,8 +459,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'worked'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
'buildout.cfg
'
])
[
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
...
@@ -477,8 +478,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -477,8 +478,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'worked'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
'buildout.cfg
'
])
[
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
...
@@ -508,7 +509,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -508,7 +509,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
[
'.0_wrapper.log'
,
'worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
tries
=
50
tries
=
50
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -551,8 +552,8 @@ chmod 755 etc/run/wrapper
...
@@ -551,8 +552,8 @@ chmod 755 etc/run/wrapper
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
'worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
tries
=
50
tries
=
50
while
tries
>
0
:
while
tries
>
0
:
...
@@ -574,9 +575,8 @@ chmod 755 etc/run/wrapper
...
@@ -574,9 +575,8 @@ chmod 755 etc/run/wrapper
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
'.0_wrapper.log.1'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
])
[
'.0_wrapper.log'
,
'.0_wrapper.log.1'
,
'worked'
,
'buildout.cfg'
,
'etc'
])
tries
=
50
tries
=
50
expected_text
=
'Signal handler called with signal 15'
expected_text
=
'Signal handler called with signal 15'
while
tries
>
0
:
while
tries
>
0
:
...
@@ -622,8 +622,8 @@ chmod 755 etc/run/wrapper
...
@@ -622,8 +622,8 @@ chmod 755 etc/run/wrapper
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
'worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
tries
=
50
tries
=
50
while
tries
>
0
:
while
tries
>
0
:
...
@@ -648,9 +648,8 @@ exit 1
...
@@ -648,9 +648,8 @@ exit 1
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_FAIL
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_FAIL
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
'.0_wrapper.log.1'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
])
[
'.0_wrapper.log'
,
'.0_wrapper.log.1'
,
'worked'
,
'buildout.cfg'
,
'etc'
])
tries
=
50
tries
=
50
expected_text
=
'Signal handler called with signal 15'
expected_text
=
'Signal handler called with signal 15'
while
tries
>
0
:
while
tries
>
0
:
...
@@ -676,8 +675,8 @@ exit 1
...
@@ -676,8 +675,8 @@ exit 1
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'worked'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
'buildout.cfg
'
])
[
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
...
@@ -691,8 +690,8 @@ exit 1
...
@@ -691,8 +690,8 @@ exit 1
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.0_wrapper.log'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
'worked'
,
'etc'
,
'buildout.cfg
'
])
[
'.0_wrapper.log'
,
'etc'
,
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
tries
=
50
tries
=
50
...
@@ -770,11 +769,10 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -770,11 +769,10 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
partition
.
software
.
setBuildout
(
DAEMON_CONTENT
)
partition
.
software
.
setBuildout
(
DAEMON_CONTENT
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
'var'
])
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
os
.
listdir
(
partition
.
partition_path
),
[
'.0_daemon.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
])
[
'.0_daemon.log'
,
'worked'
,
'buildout.cfg'
,
'etc'
])
tries
=
200
tries
=
200
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -792,16 +790,6 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
...
@@ -792,16 +790,6 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
watchdog_banged
))
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
watchdog_banged
))
self
.
assertTrue
(
'daemon'
in
open
(
self
.
watchdog_banged
,
'r'
).
read
())
self
.
assertTrue
(
'daemon'
in
open
(
self
.
watchdog_banged
,
'r'
).
read
())
RUN_CONTENT
=
"""#!/bin/sh
mkdir -p etc/run &&
echo "#!/bin/sh" > etc/run/daemon &&
echo "touch launched
touch ./crashed; echo "Failing
\
\
nFailing
\
\
n"; sleep 1; exit 111;
" >> etc/run/daemon &&
chmod 755 etc/run/daemon &&
touch worked
"""
def
test_one_failing_daemon_in_run_will_not_bang_with_watchdog
(
self
):
def
test_one_failing_daemon_in_run_will_not_bang_with_watchdog
(
self
):
"""
"""
Check that a failing service watched by watchdog trigger bang
Check that a failing service watched by watchdog trigger bang
...
@@ -817,13 +805,25 @@ touch worked
...
@@ -817,13 +805,25 @@ touch worked
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
partition
=
computer
.
instance_list
[
0
]
partition
=
computer
.
instance_list
[
0
]
partition
.
requested_state
=
'started'
partition
.
requested_state
=
'started'
partition
.
software
.
setBuildout
(
self
.
RUN_CONTENT
)
RUN_CONTENT
=
textwrap
.
dedent
(
"""
\
#!/bin/sh
mkdir -p etc/run &&
echo "#!/bin/sh" > etc/run/daemon &&
echo "touch launched
touch ./crashed; echo "Failing
\
\
nFailing
\
\
n"; sleep 1; exit 111;
" >> etc/run/daemon &&
chmod 755 etc/run/daemon &&
touch worked
"""
)
partition
.
software
.
setBuildout
(
RUN_CONTENT
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
'var'
])
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
[
'.0_daemon.log'
,
'worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_daemon.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
tries
=
200
tries
=
200
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
daemon_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_daemon.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -922,8 +922,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -922,8 +922,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg
'
])
[
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
...
@@ -931,8 +931,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -931,8 +931,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertTrue
(
timestamp
in
open
(
timestamp_path
,
'r'
).
read
())
self
.
assertTrue
(
timestamp
in
open
(
timestamp_path
,
'r'
).
read
())
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
'stoppedComputerPartition'
])
def
test_partition_timestamp_develop
(
self
):
def
test_partition_timestamp_develop
(
self
):
...
@@ -945,8 +944,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -945,8 +944,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg
'
])
[
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
...
@@ -969,7 +968,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -969,7 +968,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg
'
])
[
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
...
@@ -989,7 +988,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -989,7 +988,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg
'
])
[
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
...
@@ -1012,7 +1011,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -1012,7 +1011,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
'var'
])
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg
'
])
[
'.timestamp'
,
'buildout.cfg'
,
'software_release'
,
'worked
'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
None
instance
.
timestamp
=
None
...
@@ -1199,10 +1198,10 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1199,10 +1198,10 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
'var'
])
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
'worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
tries
=
50
tries
=
50
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -1325,7 +1324,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1325,7 +1324,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
'
worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_wrapper.log'
,
'
buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
tries
=
50
tries
=
50
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -1347,9 +1346,8 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1347,9 +1346,8 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
])
[
'.0_wrapper.log'
,
'worked'
,
'buildout.cfg'
,
'etc'
])
tries
=
50
tries
=
50
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -1361,7 +1359,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1361,7 +1359,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
'
worked'
,
'buildout.cfg'
,
'etc
'
])
[
'.0_wrapper.log'
,
'
buildout.cfg'
,
'etc'
,
'software_release'
,
'worked
'
])
tries
=
50
tries
=
50
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
while
tries
>
0
:
while
tries
>
0
:
...
@@ -1667,9 +1665,10 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest.TestCase):
...
@@ -1667,9 +1665,10 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest.TestCase):
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'fail_worked'
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'fail_worked'
)
fail
=
(
"""#!/usr/bin/env sh
fail
=
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
exit 127"""
%
{
'worked_file'
:
worked_file
})
touch "%s"
exit 127"""
%
worked_file
)
instance
.
setPromise
(
'fail'
,
fail
)
instance
.
setPromise
(
'fail'
,
fail
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
...
...
slapos/tests/slapproxy.py
View file @
27edd2d4
...
@@ -256,15 +256,16 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -256,15 +256,16 @@ class TestRequest (MasterMixin, unittest.TestCase):
"""
"""
def
test_two_request_one_partition_free
(
self
):
def
test_two_request_one_partition_free
(
self
):
"""
"""
If only one partition is available and two different request are made
Since slapproxy does not implement scope, providing two partition_id
first will succeed second will fail
values will still succeed, even if only one partition is available.
"""
"""
self
.
add_free_partition
(
1
)
self
.
add_free_partition
(
1
)
self
.
assertIsInstance
(
self
.
request
(
'http://sr//'
,
None
,
self
.
assertIsInstance
(
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
),
'Maria'
,
'slappart2'
),
slapos
.
slap
.
ComputerPartition
)
slapos
.
slap
.
ComputerPartition
)
with
self
.
assertRaises
(
WrongFormat
):
self
.
assertIsInstance
(
self
.
request
(
'http://sr//'
,
None
,
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart3'
)
'Maria'
,
'slappart3'
),
slapos
.
slap
.
ComputerPartition
)
def
test_two_request_two_partition_free
(
self
):
def
test_two_request_two_partition_free
(
self
):
"""
"""
...
@@ -327,11 +328,11 @@ class TestRequest (MasterMixin, unittest.TestCase):
...
@@ -327,11 +328,11 @@ class TestRequest (MasterMixin, unittest.TestCase):
def
test_two_different_request_from_two_partition
(
self
):
def
test_two_different_request_from_two_partition
(
self
):
"""
"""
Two request from different partitions
Since slapproxy does not implement scope, two request with
will return two differents partitions
different partition_id will still return the same partition.
"""
"""
self
.
add_free_partition
(
2
)
self
.
add_free_partition
(
2
)
self
.
assert
Not
Equal
(
self
.
assertEqual
(
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
).
__dict__
,
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart2'
).
__dict__
,
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart3'
).
__dict__
)
self
.
request
(
'http://sr//'
,
None
,
'Maria'
,
'slappart3'
).
__dict__
)
...
...
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