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
Eric Zheng
slapos.core
Commits
1a283a07
Commit
1a283a07
authored
Sep 21, 2012
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed problems
parent
a81f5a50
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
130 deletions
+107
-130
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+107
-130
No files found.
slapos/tests/slapgrid.py
View file @
1a283a07
...
@@ -73,6 +73,9 @@ class BasicMixin:
...
@@ -73,6 +73,9 @@ class BasicMixin:
self
.
supervisord_configuration_path
,
self
.
usage_report_periodicity
,
self
.
supervisord_configuration_path
,
self
.
usage_report_periodicity
,
self
.
buildout
,
develop
=
develop
)
self
.
buildout
,
develop
=
develop
)
def
launchSlapgrid
(
self
,
develop
=
False
):
self
.
setSlapgrid
(
develop
=
develop
)
return
self
.
grid
.
processComputerPartitionList
()
def
tearDown
(
self
):
def
tearDown
(
self
):
# XXX: Hardcoded pid, as it is not configurable in slapos
# XXX: Hardcoded pid, as it is not configurable in slapos
...
@@ -226,23 +229,27 @@ class ComputerForTest:
...
@@ -226,23 +229,27 @@ class ComputerForTest:
self
.
software_root
=
software_root
self
.
software_root
=
software_root
self
.
instance_root
=
instance_root
self
.
instance_root
=
instance_root
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
set_instances
()
self
.
setSoftwares
()
self
.
setInstances
()
def
setInstances
(
self
):
def
setInstances
(
self
):
self
.
instance_list
=
range
(
0
,
self
.
instance_amount
)
self
.
instance_list
=
range
(
0
,
self
.
instance_amount
)
for
instance
in
self
.
instance_list
:
for
i
in
self
.
instance_list
:
name
=
str
(
self
.
instance_list
.
index
(
instance
))
name
=
str
(
i
)
instance
=
InstanceForTest
(
self
.
instance_root
,
name
=
name
)
self
.
instance_list
[
i
]
=
InstanceForTest
(
self
.
instance_root
,
name
=
name
,
software
=
self
.
software_list
[
0
])
def
setSoftwares
(
self
):
def
setSoftwares
(
self
):
self
.
software_list
=
range
(
0
,
self
.
software_amount
)
self
.
software_list
=
range
(
0
,
self
.
software_amount
)
for
software
in
self
.
software_list
:
for
i
in
self
.
software_list
:
name
=
str
(
self
.
software_list
.
index
(
software
))
name
=
str
(
i
)
software
=
SoftwareForTest
(
self
.
software_root
,
name
=
name
)
self
.
software_list
[
i
]
=
SoftwareForTest
(
self
.
software_root
,
name
=
name
)
print
self
.
software_list
def
getComputer
(
self
,
computer_id
):
def
getComputer
(
self
,
computer_id
):
slap_computer
=
slapos
.
slap
.
Computer
(
computer_id
)
slap_computer
=
slapos
.
slap
.
Computer
(
computer_id
)
slap_computer
.
_software_release_list
=
[]
slap_computer
.
_software_release_list
=
[]
slap_computer
.
_computer_partition_list
=
[]
for
instance
in
self
.
instance_list
:
for
instance
in
self
.
instance_list
:
slap_computer
.
_computer_partition_list
.
append
(
slap_computer
.
_computer_partition_list
.
append
(
instance
.
getInstance
(
computer_id
))
instance
.
getInstance
(
computer_id
))
...
@@ -251,26 +258,24 @@ class ComputerForTest:
...
@@ -251,26 +258,24 @@ class ComputerForTest:
def
getServerResponse
(
self
):
def
getServerResponse
(
self
):
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
.
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
:
parsed_qs
=
urlparse
.
parse_qs
(
body
)
parsed_qs
=
urlparse
.
parse_qs
(
body
)
if
parsed_url
.
path
==
'getFullComputerInformation'
and
\
if
parsed_url
.
path
==
'getFullComputerInformation'
and
\
'computer_id'
in
parsed_qs
:
'computer_id'
in
parsed_qs
:
self
.
sequence
.
append
(
parsed_url
.
path
)
slap_computer
=
self
.
getComputer
(
parsed_qs
[
'computer_id'
][
0
])
self
.
set_computer
(
parsed_qs
[
'computer_id'
][
0
])
return
(
200
,
{},
xml_marshaller
.
xml_marshaller
.
dumps
(
slap_computer
))
return
(
200
,
{},
xml_marshaller
.
xml_marshaller
.
dumps
(
self
.
slap_computer
))
if
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
if
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
instance
=
self
.
instance_list
[
parsed_qs
[
'computer_partition_id'
][
0
]
]
instance
=
self
.
instance_list
[
int
(
parsed_qs
[
'computer_partition_id'
][
0
])
]
instance
.
sequence
.
append
(
parsed_url
.
path
)
instance
.
sequence
.
append
(
parsed_url
.
path
)
if
parsed_url
.
path
==
'availableComputerPartition'
:
if
parsed_url
.
path
==
'availableComputerPartition'
:
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'startedComputerPartition'
:
if
parsed_url
.
path
==
'startedComputerPartition'
:
self
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
instance
.
state
=
'started'
instance
.
state
=
'started'
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'stoppedComputerPartition'
:
if
parsed_url
.
path
==
'stoppedComputerPartition'
:
self
.
assertEqual
(
parsed_qs
[
'computer_partition_id'
][
0
],
'0'
)
instance
.
state
=
'stopped'
instance
.
state
=
'stopped'
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'softwareInstanceError'
:
if
parsed_url
.
path
==
'softwareInstanceError'
:
...
@@ -278,7 +283,6 @@ class ComputerForTest:
...
@@ -278,7 +283,6 @@ class ComputerForTest:
return
(
200
,
{},
''
)
return
(
200
,
{},
''
)
else
:
else
:
return
(
404
,
{},
''
)
return
(
404
,
{},
''
)
return
server_response
return
server_response
...
@@ -286,9 +290,11 @@ class InstanceForTest:
...
@@ -286,9 +290,11 @@ class InstanceForTest:
"""
"""
Class containing all needed paramaters and function to simulate instances
Class containing all needed paramaters and function to simulate instances
"""
"""
def
__init__
_
(
self
,
instance_root
,
name
,
software
):
def
__init__
(
self
,
instance_root
,
name
,
software
):
self
.
instance_root
=
instance_root
self
.
instance_root
=
instance_root
self
.
requested_state
=
'stopped'
self
.
requested_state
=
'stopped'
self
.
sate
=
None
self
.
error
=
False
self
.
software
=
software
self
.
software
=
software
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
name
=
name
self
.
name
=
name
...
@@ -300,7 +306,7 @@ class InstanceForTest:
...
@@ -300,7 +306,7 @@ class InstanceForTest:
def
getInstance
(
self
,
computer_id
):
def
getInstance
(
self
,
computer_id
):
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
.
_software_release_document
=
self
.
getSoftware
()
partition
.
_software_release_document
=
self
.
getSoftware
Release
()
partition
.
_requested_state
=
self
.
requested_state
partition
.
_requested_state
=
self
.
requested_state
if
self
.
timestamp
is
not
None
:
if
self
.
timestamp
is
not
None
:
partition
.
_parameter_dict
=
{
'timestamp'
:
self
.
timestamp
}
partition
.
_parameter_dict
=
{
'timestamp'
:
self
.
timestamp
}
...
@@ -311,7 +317,9 @@ class InstanceForTest:
...
@@ -311,7 +317,9 @@ class InstanceForTest:
sr
.
_software_release
=
self
.
software
.
name
sr
.
_software_release
=
self
.
software
.
name
return
sr
return
sr
class
SoftwareForTest
:
class
SoftwareForTest
:
def
__init__
(
self
,
software_root
,
name
=
''
):
def
__init__
(
self
,
software_root
,
name
=
''
):
self
.
software_root
=
software_root
self
.
software_root
=
software_root
self
.
name
=
'http://sr%s/'
%
name
self
.
name
=
'http://sr%s/'
%
name
...
@@ -321,24 +329,25 @@ class SoftwareForTest:
...
@@ -321,24 +329,25 @@ class SoftwareForTest:
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
self
.
name
)
slapos
.
grid
.
utils
.
getSoftwareUrlHash
(
self
.
name
)
self
.
srdir
=
os
.
path
.
join
(
self
.
software_root
,
self
.
software_hash
)
self
.
srdir
=
os
.
path
.
join
(
self
.
software_root
,
self
.
software_hash
)
os
.
mkdir
(
self
.
srdir
)
os
.
mkdir
(
self
.
srdir
)
self
.
set
_template_c
fg
()
self
.
set
TemplateC
fg
()
self
.
srbindir
=
os
.
path
.
join
(
self
.
srdir
,
'bin'
)
self
.
srbindir
=
os
.
path
.
join
(
self
.
srdir
,
'bin'
)
os
.
mkdir
(
self
.
srbindir
)
os
.
mkdir
(
self
.
srbindir
)
self
.
set
_b
uildout
()
self
.
set
B
uildout
()
def
set
_template_c
fg
(
self
,
template
=
"""[buildout]"""
):
def
set
TemplateC
fg
(
self
,
template
=
"""[buildout]"""
):
open
(
os
.
path
.
join
(
self
.
srdir
,
'template.cfg'
),
'w'
).
write
(
template
)
open
(
os
.
path
.
join
(
self
.
srdir
,
'template.cfg'
),
'w'
).
write
(
template
)
def
set
_b
uildout
(
self
,
buildout
=
"""#!/bin/sh
def
set
B
uildout
(
self
,
buildout
=
"""#!/bin/sh
touch worked"""
):
touch worked"""
):
open
(
os
.
path
.
join
(
self
.
srbindir
,
'buildout'
),
'w'
).
write
(
buildout
)
open
(
os
.
path
.
join
(
self
.
srbindir
,
'buildout'
),
'w'
).
write
(
buildout
)
os
.
chmod
(
os
.
path
.
join
(
self
.
srbindir
,
'buildout'
),
0755
)
os
.
chmod
(
os
.
path
.
join
(
self
.
srbindir
,
'buildout'
),
0755
)
def
set
_p
eriodicity
(
self
,
periodicity
):
def
set
P
eriodicity
(
self
,
periodicity
):
open
(
os
.
path
.
join
(
self
.
srdir
,
'periodicity'
),
'w'
).
write
(
open
(
os
.
path
.
join
(
self
.
srdir
,
'periodicity'
),
'w'
).
write
(
"""%s"""
%
(
periodicity
))
"""%s"""
%
(
periodicity
))
class
TestSlapgridCPWithMaster
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPWithMaster
(
MasterMixin
,
unittest
.
TestCase
):
def
test_nothing_to_do
(
self
):
def
test_nothing_to_do
(
self
):
...
@@ -635,15 +644,11 @@ chmod 755 etc/run/wrapper
...
@@ -635,15 +644,11 @@ chmod 755 etc/run/wrapper
class
TestSlapgridCPPartitionProcessing
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPPartitionProcessing
(
MasterMixin
,
unittest
.
TestCase
):
def
test_partition_timestamp
(
self
):
def
test_partition_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
self
.
sequence
=
[]
instance
=
computer
.
instance_list
[
0
]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
instance
.
timestamp
=
timestamp
httplib
.
HTTPConnection
.
_callback
=
\
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
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'
,
...
@@ -652,28 +657,23 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -652,28 +657,23 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
timestamp_path
=
os
.
path
.
join
(
partition_path
,
'.timestamp'
)
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
timestamp
in
open
(
timestamp_path
,
'r'
).
read
())
self
.
assertTrue
(
timestamp
in
open
(
timestamp_path
,
'r'
).
read
())
self
.
assertEqual
(
self
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'getFullComputerInformation'
,
[
'availableComputerPartition'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
])
'stoppedComputerPartition'
,
'getFullComputerInformation'
])
def
test_partition_timestamp_develop
(
self
):
def
test_partition_timestamp_develop
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
self
.
sequence
=
[]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
\
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
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'
])
...
@@ -681,30 +681,21 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -681,30 +681,21 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
setSlapgrid
(
develop
=
True
)
self
.
assertTrue
(
self
.
launchSlapgrid
(
develop
=
True
)
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
launchSlapgrid
())
self
.
setSlapgrid
()
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
[
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
])
self
.
assertEqual
(
self
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
])
def
test_partition_old_timestamp
(
self
):
def
test_partition_old_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
self
.
sequence
=
[]
instance
=
computer
.
instance_list
[
0
]
self
.
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
instance
.
timestamp
=
timestamp
httplib
.
HTTPConnection
.
_callback
=
\
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
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'
,
...
@@ -713,70 +704,55 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -713,70 +704,55 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
),
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
[
'.timestamp'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
launchSlapgrid
())
httplib
.
HTTPConnection
.
_callback
=
\
self
.
assertEqual
(
instance
.
sequence
,
self
.
_server_response
(
'stopped'
,
str
(
int
(
self
.
timestamp
)
-
1
))
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
])
def
test_partition_timestamp_new_timestamp
(
self
):
def
test_partition_timestamp_new_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
self
.
sequence
=
[]
self
.
assertTrue
(
self
.
launchSlapgrid
())
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
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'
])
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'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
[
instance
.
software
.
software_hash
])
httplib
.
HTTPConnection
.
_callback
=
\
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
self
.
_server_response
(
'stopped'
,
str
(
int
(
self
.
timestamp
)
+
1
))
self
.
assertTrue
(
self
.
launchSlapgrid
())
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
launchSlapgrid
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
computer
.
sequence
,
self
.
setSlapgrid
()
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
])
'getFullComputerInformation'
])
def
test_partition_timestamp_no_timestamp
(
self
):
def
test_partition_timestamp_no_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
self
.
sequence
=
[]
self
.
launchSlapgrid
()
self
.
timestamp
=
str
(
int
(
time
.
time
()))
self
.
started
=
False
httplib
.
HTTPConnection
.
_callback
=
\
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
()
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'
])
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'
,
'worked'
,
'buildout.cfg'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
software_hash
])
[
instance
.
software
.
software_hash
])
httplib
.
HTTPConnection
.
_callback
=
self
.
_server_response
(
'stopped'
)
instance
.
timestamp
=
None
self
.
setSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
self
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,])
'availableComputerPartition'
,
'stoppedComputerPartition'
,])
...
@@ -792,26 +768,25 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -792,26 +768,25 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
3. We process partition list and wait more than unwanted periodicity
3. We process partition list and wait more than unwanted periodicity
4. We relaunch, partition should not be processed
4. We relaunch, partition should not be processed
"""
"""
self
.
sequence
=
[]
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
self
.
timestamp
=
str
(
int
(
time
.
time
()))
instance
=
computer
.
instance_list
[
0
]
self
.
started
=
False
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
unwanted_periodicity
=
2
unwanted_periodicity
=
2
instance
.
software
.
setPeriodicity
(
unwanted_periodicity
)
self
.
grid
.
force_periodicity
=
True
self
.
grid
.
force_periodicity
=
True
httplib
.
HTTPConnection
.
_callback
=
\
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instance
()
software_hash
=
self
.
_bootstrap
(
periodicity
=
unwanted_periodicity
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
launchSlapgrid
(
)
time
.
sleep
(
unwanted_periodicity
+
1
)
time
.
sleep
(
unwanted_periodicity
+
1
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
grid
.
force_periodicity
=
True
self
.
grid
.
force_periodicity
=
True
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertNotEqual
(
unwanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
unwanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertEqual
(
self
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
])
'stoppedComputerPartition'
,
'getFullComputerInformation'
])
...
@@ -829,27 +804,29 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
...
@@ -829,27 +804,29 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
processed one more time
processed one more time
5. We check that modification time of .timestamp was modified
5. We check that modification time of .timestamp was modified
"""
"""
self
.
sequence
=
[]
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
self
.
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
instance
=
computer
.
instance_list
[
0
]
self
.
started
=
False
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
instance
.
timestamp
=
timestamp
wanted_periodicity
=
3
wanted_periodicity
=
3
httplib
.
HTTPConnection
.
_callback
=
\
instance
.
software
.
setPeriodicity
(
wanted_periodicity
)
self
.
_server_response
(
'stopped'
,
self
.
timestamp
)
partition_path
=
self
.
_create_instanc
e
()
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerRespons
e
()
software_hash
=
self
.
_bootstrap
(
periodicity
=
wanted_periodicity
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
launchSlapgrid
(
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
setSlapgrid
()
last_runtime
=
os
.
path
.
getmtime
(
last_runtime
=
os
.
path
.
getmtime
(
os
.
path
.
join
(
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
self
.
assertTrue
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
launchSlapgrid
(
)
self
.
assertEqual
(
self
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
])
])
self
.
assertGreater
(
self
.
assertGreater
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
partition_path
,
'.timestamp'
)),
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)),
last_runtime
)
last_runtime
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
...
...
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