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
Xiaowu Zhang
slapos.core
Commits
e0be4c62
Commit
e0be4c62
authored
Sep 21, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factored tests
parent
513254e9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
185 deletions
+97
-185
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+97
-185
No files found.
slapos/tests/slapgrid.py
View file @
e0be4c62
...
@@ -142,7 +142,7 @@ class MasterMixin(BasicMixin):
...
@@ -142,7 +142,7 @@ class MasterMixin(BasicMixin):
os
.
mkdir
(
partition_path
,
0750
)
os
.
mkdir
(
partition_path
,
0750
)
return
partition_path
return
partition_path
def
_bootstrap
(
self
):
def
_bootstrap
(
self
,
periodicity
=
None
):
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
...
@@ -154,23 +154,15 @@ class MasterMixin(BasicMixin):
...
@@ -154,23 +154,15 @@ class MasterMixin(BasicMixin):
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
if
periodicity
is
not
None
:
open
(
os
.
path
.
join
(
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
(
periodicity
))
return
software_hash
return
software_hash
def
setUp
(
self
):
def
_server_response
(
self
,
_requested_state
,
timestamp
=
None
):
self
.
_patchHttplib
()
self
.
_mock_sleep
()
BasicMixin
.
setUp
(
self
)
def
tearDown
(
self
):
self
.
_unpatchHttplib
()
self
.
_unmock_sleep
()
BasicMixin
.
tearDown
(
self
)
def
_server_response
(
self_test
,
_requested_state
,
timestamp
=
None
):
def
server_response
(
self_httplib
,
path
,
method
,
body
,
header
):
def
server_response
(
self_httplib
,
path
,
method
,
body
,
header
):
parsed_url
=
urlparse
.
urlparse
(
path
.
lstrip
(
'/'
))
parsed_url
=
urlparse
.
urlparse
(
path
.
lstrip
(
'/'
))
self_test
.
sequence
.
append
(
parsed_url
.
path
)
self
.
sequence
.
append
(
parsed_url
.
path
)
if
method
==
'GET'
:
if
method
==
'GET'
:
parsed_qs
=
urlparse
.
parse_qs
(
parsed_url
.
query
)
parsed_qs
=
urlparse
.
parse_qs
(
parsed_url
.
query
)
else
:
else
:
...
@@ -194,24 +186,34 @@ def _server_response (self_test, _requested_state, timestamp=None):
...
@@ -194,24 +186,34 @@ def _server_response (self_test, _requested_state, timestamp=None):
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'startedComputerPartition'
and
\
if
parsed_url
.
path
==
'startedComputerPartition'
and
\
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
self_test
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
self
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
self_test
.
started
=
True
self
.
started
=
True
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'stoppedComputerPartition'
and
\
if
parsed_url
.
path
==
'stoppedComputerPartition'
and
\
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
self_test
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
self
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
self_test
.
stopped
=
True
self
.
stopped
=
True
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'softwareInstanceError'
and
\
if
parsed_url
.
path
==
'softwareInstanceError'
and
\
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
self_test
.
error
=
True
self
.
error
=
True
self_test
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
self
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
else
:
else
:
return
(
404
,
{},
''
)
return
(
404
,
{},
''
)
return
server_response
return
server_response
def
setUp
(
self
):
self
.
_patchHttplib
()
self
.
_mock_sleep
()
BasicMixin
.
setUp
(
self
)
def
tearDown
(
self
):
self
.
_unpatchHttplib
()
self
.
_unmock_sleep
()
BasicMixin
.
tearDown
(
self
)
class
TestSlapgridCPWithMaster
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPWithMaster
(
MasterMixin
,
unittest
.
TestCase
):
...
@@ -238,8 +240,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -238,8 +240,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
def
test_one_partition
(
self
):
def
test_one_partition
(
self
):
self
.
sequence
=
[]
self
.
sequence
=
[]
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
\
_requested_state
=
'stopped'
)
self
.
_server_response
(
_requested_state
=
'stopped'
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
os
.
mkdir
(
self
.
instance_root
)
...
@@ -273,8 +275,8 @@ touch worked""")
...
@@ -273,8 +275,8 @@ touch worked""")
"template.cfg" but "instance.cfg".
"template.cfg" but "instance.cfg".
"""
"""
self
.
sequence
=
[]
self
.
sequence
=
[]
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
\
_requested_state
=
'stopped'
)
self
.
_server_response
(
_requested_state
=
'stopped'
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
os
.
mkdir
(
self
.
instance_root
)
...
@@ -332,7 +334,7 @@ touch worked""")
...
@@ -332,7 +334,7 @@ touch worked""")
def
test_one_partition_started
(
self
):
def
test_one_partition_started
(
self
):
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'started'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'started'
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
@@ -370,7 +372,7 @@ touch worked""")
...
@@ -370,7 +372,7 @@ touch worked""")
def
test_one_partition_started_stopped
(
self
):
def
test_one_partition_started_stopped
(
self
):
self
.
started
=
True
self
.
started
=
True
self
.
sequence
=
[]
self
.
sequence
=
[]
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'started'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'started'
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
os
.
mkdir
(
self
.
instance_root
)
...
@@ -426,7 +428,7 @@ chmod 755 etc/run/wrapper
...
@@ -426,7 +428,7 @@ chmod 755 etc/run/wrapper
self
.
stopped
=
False
self
.
stopped
=
False
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
setSlapgrid
()
self
.
setSlapgrid
()
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'stopped'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'stopped'
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
...
@@ -451,7 +453,7 @@ chmod 755 etc/run/wrapper
...
@@ -451,7 +453,7 @@ chmod 755 etc/run/wrapper
def
test_one_partition_stopped_started
(
self
):
def
test_one_partition_stopped_started
(
self
):
self
.
stopped
=
False
self
.
stopped
=
False
self
.
sequence
=
[]
self
.
sequence
=
[]
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'stopped'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'stopped'
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
os
.
mkdir
(
self
.
instance_root
)
...
@@ -481,7 +483,7 @@ chmod 755 etc/run/wrapper
...
@@ -481,7 +483,7 @@ chmod 755 etc/run/wrapper
self
.
started
=
False
self
.
started
=
False
self
.
sequence
=
[]
self
.
sequence
=
[]
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'started'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'started'
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
...
@@ -505,6 +507,7 @@ chmod 755 etc/run/wrapper
...
@@ -505,6 +507,7 @@ chmod 755 etc/run/wrapper
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertTrue
(
self
.
started
)
self
.
assertTrue
(
self
.
started
)
class
TestSlapgridCPPartitionProcessing
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPPartitionProcessing
(
MasterMixin
,
unittest
.
TestCase
):
def
test_partition_timestamp
(
self
):
def
test_partition_timestamp
(
self
):
...
@@ -512,23 +515,12 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -512,23 +515,12 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
httplib
.
HTTPConnection
.
_callback
=
\
self
,
'stopped'
,
self
.
timestamp
)
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
...
@@ -554,22 +546,10 @@ touch worked""")
...
@@ -554,22 +546,10 @@ touch worked""")
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
httplib
.
HTTPConnection
.
_callback
=
\
self
,
'stopped'
,
self
.
timestamp
)
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
os
.
mkdir
(
self
.
software_root
)
partition_path
=
self
.
_create_instance
()
os
.
mkdir
(
self
.
instance_root
)
software_hash
=
self
.
_bootstrap
()
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
...
@@ -596,23 +576,12 @@ touch worked""")
...
@@ -596,23 +576,12 @@ touch worked""")
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
httplib
.
HTTPConnection
.
_callback
=
\
self
,
'stopped'
,
self
.
timestamp
)
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
os
.
mkdir
(
self
.
software_root
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
...
@@ -623,8 +592,8 @@ touch worked""")
...
@@ -623,8 +592,8 @@ touch worked""")
[
software_hash
])
[
software_hash
])
self
.
setSlapgrid
()
self
.
setSlapgrid
()
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
httplib
.
HTTPConnection
.
_callback
=
\
self
,
'stopped'
,
str
(
int
(
self
.
timestamp
)
-
1
))
self
.
_server_response
(
'stopped'
,
str
(
int
(
self
.
timestamp
)
-
1
))
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
sequence
,
self
.
assertEqual
(
self
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
...
@@ -637,23 +606,11 @@ touch worked""")
...
@@ -637,23 +606,11 @@ touch worked""")
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'stopped'
,
'stopped'
,
self
.
timestamp
)
self
.
timestamp
)
os
.
mkdir
(
self
.
software_root
)
partition_path
=
self
.
_create_instance
()
os
.
mkdir
(
self
.
instance_root
)
software_hash
=
self
.
_bootstrap
()
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
...
@@ -662,9 +619,8 @@ touch worked""")
...
@@ -662,9 +619,8 @@ touch worked""")
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
[
software_hash
])
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
\
'stopped'
,
self
.
_server_response
(
'stopped'
,
str
(
int
(
self
.
timestamp
)
+
1
))
str
(
int
(
self
.
timestamp
)
+
1
))
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
setSlapgrid
()
self
.
setSlapgrid
()
...
@@ -680,23 +636,11 @@ touch worked""")
...
@@ -680,23 +636,11 @@ touch worked""")
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
\
'stopped'
,
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
os
.
mkdir
(
self
.
software_root
)
software_hash
=
self
.
_bootstrap
()
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
'var'
])
...
@@ -705,8 +649,7 @@ touch worked""")
...
@@ -705,8 +649,7 @@ touch worked""")
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
[
software_hash
])
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'stopped'
)
'stopped'
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
sequence
,
self
.
assertEqual
(
self
.
sequence
,
...
@@ -732,26 +675,10 @@ touch worked""")
...
@@ -732,26 +675,10 @@ touch worked""")
unwanted_periodicity
=
2
unwanted_periodicity
=
2
self
.
grid
.
force_periodicity
=
True
self
.
grid
.
force_periodicity
=
True
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
\
'stopped'
,
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
os
.
mkdir
(
self
.
software_root
)
software_hash
=
self
.
_bootstrap
(
periodicity
=
unwanted_periodicity
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
open
(
os
.
path
.
join
(
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
(
unwanted_periodicity
))
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
time
.
sleep
(
unwanted_periodicity
+
1
)
time
.
sleep
(
unwanted_periodicity
+
1
)
...
@@ -782,25 +709,10 @@ touch worked""")
...
@@ -782,25 +709,10 @@ touch worked""")
self
.
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
self
.
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
self
.
started
=
False
self
.
started
=
False
wanted_periodicity
=
3
wanted_periodicity
=
3
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
httplib
.
HTTPConnection
.
_callback
=
\
'stopped'
,
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
os
.
mkdir
(
self
.
software_root
)
software_hash
=
self
.
_bootstrap
(
periodicity
=
wanted_periodicity
)
os
.
mkdir
(
self
.
instance_root
)
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
os
.
mkdir
(
partition_path
,
0750
)
software_hash
=
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
'http://sr/'
)
srdir
=
os
.
path
.
join
(
self
.
software_root
,
software_hash
)
os
.
mkdir
(
srdir
)
open
(
os
.
path
.
join
(
srdir
,
'template.cfg'
),
'w'
).
write
(
"""[buildout]"""
)
open
(
os
.
path
.
join
(
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
wanted_periodicity
)
srbindir
=
os
.
path
.
join
(
srdir
,
'bin'
)
os
.
mkdir
(
srbindir
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
"""#!/bin/sh
touch worked"""
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
...
@@ -842,7 +754,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -842,7 +754,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Start the instance
# Start the instance
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'started'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'started'
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
WRAPPER_CONTENT
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
WRAPPER_CONTENT
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
...
@@ -868,7 +780,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -868,7 +780,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Then destroy the instance
# Then destroy the instance
self
.
sequence
=
[]
self
.
sequence
=
[]
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'destroyed'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'destroyed'
)
self
.
assertTrue
(
self
.
grid
.
agregateAndSendUsage
())
self
.
assertTrue
(
self
.
grid
.
agregateAndSendUsage
())
# Assert partition directory is empty
# Assert partition directory is empty
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
...
@@ -913,7 +825,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -913,7 +825,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Start the instance
# Start the instance
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
started
=
False
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
_server_response
(
self
,
'started'
)
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'started'
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
WRAPPER_CONTENT
)
open
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
'w'
).
write
(
WRAPPER_CONTENT
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
os
.
chmod
(
os
.
path
.
join
(
srbindir
,
'buildout'
),
0755
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
...
...
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