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
Klaus Wölfel
slapos.core
Commits
aec034d4
Commit
aec034d4
authored
May 17, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
general, light cleanup
parent
e9682562
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
202 additions
and
188 deletions
+202
-188
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+202
-188
No files found.
slapos/tests/slapgrid.py
View file @
aec034d4
...
@@ -129,11 +129,11 @@ class BasicMixin:
...
@@ -129,11 +129,11 @@ class BasicMixin:
pass
pass
slapos
.
grid
.
utils
.
bootstrapBuildout
=
dummy
slapos
.
grid
.
utils
.
bootstrapBuildout
=
dummy
def
launchSlapgrid
(
self
,
develop
=
False
):
def
launchSlapgrid
(
self
,
develop
=
False
):
self
.
setSlapgrid
(
develop
=
develop
)
self
.
setSlapgrid
(
develop
=
develop
)
return
self
.
grid
.
processComputerPartitionList
()
return
self
.
grid
.
processComputerPartitionList
()
def
launchSlapgridSoftware
(
self
,
develop
=
False
):
def
launchSlapgridSoftware
(
self
,
develop
=
False
):
self
.
setSlapgrid
(
develop
=
develop
)
self
.
setSlapgrid
(
develop
=
develop
)
return
self
.
grid
.
processSoftwareReleaseList
()
return
self
.
grid
.
processSoftwareReleaseList
()
...
@@ -192,7 +192,7 @@ class MasterMixin(BasicMixin):
...
@@ -192,7 +192,7 @@ class MasterMixin(BasicMixin):
"""Overrides httplib"""
"""Overrides httplib"""
import
mock.httplib
import
mock.httplib
self
.
saved_httplib
=
dict
()
self
.
saved_httplib
=
{}
for
fake
in
vars
(
mock
.
httplib
):
for
fake
in
vars
(
mock
.
httplib
):
self
.
saved_httplib
[
fake
]
=
getattr
(
httplib
,
fake
,
None
)
self
.
saved_httplib
[
fake
]
=
getattr
(
httplib
,
fake
,
None
)
...
@@ -259,38 +259,38 @@ class ComputerForTest:
...
@@ -259,38 +259,38 @@ class ComputerForTest:
"""
"""
Will set requested amount of software
Will set requested amount of software
"""
"""
self
.
software_list
=
range
(
0
,
self
.
software_amount
)
self
.
software_list
=
[
for
i
in
self
.
software_list
:
SoftwareForTest
(
self
.
software_root
,
name
=
str
(
i
))
name
=
str
(
i
)
for
i
in
range
(
self
.
software_amount
)
self
.
software_list
[
i
]
=
SoftwareForTest
(
self
.
software_root
,
name
=
name
)
]
def
setInstances
(
self
):
def
setInstances
(
self
):
"""
"""
Will set requested amount of instance giving them by default first software
Will set requested amount of instance giving them by default first software
"""
"""
self
.
instance_list
=
range
(
0
,
self
.
instance_amount
)
if
self
.
software_list
:
for
i
in
self
.
instance_list
:
name
=
str
(
i
)
if
len
(
self
.
software_list
)
is
not
0
:
software
=
self
.
software_list
[
0
]
software
=
self
.
software_list
[
0
]
else
:
else
:
software
=
None
software
=
None
self
.
instance_list
[
i
]
=
InstanceForTest
(
self
.
instance_root
,
name
=
name
,
software
=
software
)
def
getComputer
(
self
,
computer_id
):
self
.
instance_list
=
[
InstanceForTest
(
self
.
instance_root
,
name
=
str
(
i
),
software
=
software
)
for
i
in
range
(
self
.
instance_amount
)
]
def
getComputer
(
self
,
computer_id
):
"""
"""
Will return current requested state of computer
Will return current requested state of computer
"""
"""
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
=
[]
software
.
getSoftware
(
computer_id
)
for
instance
in
self
.
instance_list
:
for
software
in
self
.
software_list
slap_computer
.
_computer_partition_list
.
append
(
]
instance
.
getInstance
(
computer_id
))
slap_computer
.
_computer_partition_list
=
[
for
software
in
self
.
software_list
:
instance
.
getInstance
(
computer_id
)
slap_computer
.
_software_release_list
.
append
(
for
instance
in
self
.
instance_list
software
.
getSoftware
(
computer_id
))
]
return
slap_computer
return
slap_computer
def
setServerResponse
(
self
):
def
setServerResponse
(
self
):
...
@@ -371,10 +371,10 @@ class InstanceForTest:
...
@@ -371,10 +371,10 @@ class InstanceForTest:
self
.
header_list
=
[]
self
.
header_list
=
[]
self
.
name
=
name
self
.
name
=
name
self
.
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
self
.
name
)
self
.
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
self
.
name
)
os
.
mkdir
(
self
.
partition_path
,
0750
)
os
.
mkdir
(
self
.
partition_path
,
0
o
750
)
self
.
timestamp
=
None
self
.
timestamp
=
None
def
getInstance
(
self
,
computer_id
):
def
getInstance
(
self
,
computer_id
):
"""
"""
Will return current requested state of instance
Will return current requested state of instance
"""
"""
...
@@ -386,7 +386,7 @@ class InstanceForTest:
...
@@ -386,7 +386,7 @@ class InstanceForTest:
partition
.
_parameter_dict
=
{
'timestamp'
:
self
.
timestamp
}
partition
.
_parameter_dict
=
{
'timestamp'
:
self
.
timestamp
}
return
partition
return
partition
def
getSoftwareRelease
(
self
):
def
getSoftwareRelease
(
self
):
"""
"""
Return software release for Instance
Return software release for Instance
"""
"""
...
@@ -396,7 +396,7 @@ class InstanceForTest:
...
@@ -396,7 +396,7 @@ class InstanceForTest:
return
sr
return
sr
else
:
return
None
else
:
return
None
def
setPromise
(
self
,
promise_name
,
promise_content
):
def
setPromise
(
self
,
promise_name
,
promise_content
):
"""
"""
This function will set promise and return its path
This function will set promise and return its path
"""
"""
...
@@ -405,7 +405,7 @@ class InstanceForTest:
...
@@ -405,7 +405,7 @@ class InstanceForTest:
os
.
makedirs
(
promise_path
)
os
.
makedirs
(
promise_path
)
promise
=
os
.
path
.
join
(
promise_path
,
promise_name
)
promise
=
os
.
path
.
join
(
promise_path
,
promise_name
)
open
(
promise
,
'w'
).
write
(
promise_content
)
open
(
promise
,
'w'
).
write
(
promise_content
)
os
.
chmod
(
promise
,
0777
)
os
.
chmod
(
promise
,
0
o
777
)
def
setCertificate
(
self
,
certificate_repository_path
):
def
setCertificate
(
self
,
certificate_repository_path
):
if
not
os
.
path
.
exists
(
certificate_repository_path
):
if
not
os
.
path
.
exists
(
certificate_repository_path
):
...
@@ -440,7 +440,7 @@ class SoftwareForTest:
...
@@ -440,7 +440,7 @@ class SoftwareForTest:
os
.
mkdir
(
self
.
srbindir
)
os
.
mkdir
(
self
.
srbindir
)
self
.
setBuildout
()
self
.
setBuildout
()
def
getSoftware
(
self
,
computer_id
):
def
getSoftware
(
self
,
computer_id
):
"""
"""
Will return current requested state of software
Will return current requested state of software
"""
"""
...
@@ -449,21 +449,21 @@ class SoftwareForTest:
...
@@ -449,21 +449,21 @@ class SoftwareForTest:
return
software
return
software
def
setTemplateCfg
(
self
,
template
=
"""[buildout]"""
):
def
setTemplateCfg
(
self
,
template
=
"""[buildout]"""
):
"""
"""
Set template.cfg
Set template.cfg
"""
"""
open
(
os
.
path
.
join
(
self
.
srdir
,
'template.cfg'
),
'w'
).
write
(
template
)
open
(
os
.
path
.
join
(
self
.
srdir
,
'template.cfg'
),
'w'
).
write
(
template
)
def
setBuildout
(
self
,
buildout
=
"""#!/bin/sh
def
setBuildout
(
self
,
buildout
=
"""#!/bin/sh
touch worked"""
):
touch worked"""
):
"""
"""
Set a buildout exec in bin
Set a buildout exec in bin
"""
"""
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'
),
0
o
755
)
def
setPeriodicity
(
self
,
periodicity
):
def
setPeriodicity
(
self
,
periodicity
):
"""
"""
Set a periodicity file
Set a periodicity file
"""
"""
...
@@ -476,14 +476,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
...
@@ -476,14 +476,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
def
test_nothing_to_do
(
self
):
def
test_nothing_to_do
(
self
):
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
0
,
0
)
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
0
,
0
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[])
def
test_one_partition
(
self
):
def
test_one_partition
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
@@ -499,7 +499,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
...
@@ -499,7 +499,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
Check that slapgrid processes instance is profile is not named
Check that slapgrid processes instance is profile is not named
"template.cfg" but "instance.cfg".
"template.cfg" but "instance.cfg".
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
@@ -514,18 +514,19 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
...
@@ -514,18 +514,19 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
"""
"""
Test if slapgrid cp don't process "free" partition
Test if slapgrid cp don't process "free" partition
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
computer
=
ComputerForTest
(
self
.
software_root
,
software_amount
=
0
)
self
.
instance_root
,
software_amount
=
0
)
partition
=
computer
.
instance_list
[
0
]
partition
=
computer
.
instance_list
[
0
]
partition
.
requested_state
=
'destroyed'
partition
.
requested_state
=
'destroyed'
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
partition
.
partition_path
),
[])
self
.
assertItemsEqual
(
os
.
listdir
(
partition
.
partition_path
),
[])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[])
self
.
assertEqual
(
partition
.
sequence
,
[])
self
.
assertEqual
(
partition
.
sequence
,
[])
def
test_one_partition_started
(
self
):
def
test_one_partition_started
(
self
):
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
(
WRAPPER_CONTENT
)
partition
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
...
@@ -540,16 +541,16 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
...
@@ -540,16 +541,16 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest2.TestCase):
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
def
test_one_partition_started_stopped
(
self
):
def
test_one_partition_started_stopped
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
...
@@ -570,7 +571,7 @@ while True:
...
@@ -570,7 +571,7 @@ while True:
HEREDOC
HEREDOC
)> etc/run/wrapper &&
)> etc/run/wrapper &&
chmod 755 etc/run/wrapper
chmod 755 etc/run/wrapper
"""
%
dict
(
python
=
sys
.
executable
)
)
"""
%
{
'python'
:
sys
.
executable
}
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
...
@@ -583,12 +584,12 @@ chmod 755 etc/run/wrapper
...
@@ -583,12 +584,12 @@ chmod 755 etc/run/wrapper
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
os
.
path
.
getsize
(
wrapper_log
)
os
.
path
.
getsize
(
wrapper_log
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
computer
.
sequence
=
[]
instance
.
requested_state
=
'stopped'
instance
.
requested_state
=
'stopped'
...
@@ -600,7 +601,7 @@ chmod 755 etc/run/wrapper
...
@@ -600,7 +601,7 @@ chmod 755 etc/run/wrapper
expected_text
=
'Signal handler called with signal 15'
expected_text
=
'Signal handler called with signal 15'
while
tries
>
0
:
while
tries
>
0
:
tries
-=
1
tries
-=
1
found
=
expected_text
in
open
(
wrapper_log
,
'r'
).
read
()
found
=
expected_text
in
open
(
wrapper_log
).
read
()
if
found
:
if
found
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
...
@@ -608,7 +609,7 @@ chmod 755 etc/run/wrapper
...
@@ -608,7 +609,7 @@ chmod 755 etc/run/wrapper
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
])
'stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_broken_partition_stopped
(
self
):
def
test_one_broken_partition_stopped
(
self
):
"""
"""
...
@@ -616,7 +617,7 @@ chmod 755 etc/run/wrapper
...
@@ -616,7 +617,7 @@ chmod 755 etc/run/wrapper
processes will be stopped even if instance is broken (buildout fails
processes will be stopped even if instance is broken (buildout fails
to run) but status is still started.
to run) but status is still started.
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
...
@@ -637,7 +638,7 @@ while True:
...
@@ -637,7 +638,7 @@ while True:
HEREDOC
HEREDOC
)> etc/run/wrapper &&
)> etc/run/wrapper &&
chmod 755 etc/run/wrapper
chmod 755 etc/run/wrapper
"""
%
dict
(
python
=
sys
.
executable
)
)
"""
%
{
'python'
:
sys
.
executable
}
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
...
@@ -650,13 +651,13 @@ chmod 755 etc/run/wrapper
...
@@ -650,13 +651,13 @@ chmod 755 etc/run/wrapper
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
os
.
path
.
getsize
(
wrapper_log
)
os
.
path
.
getsize
(
wrapper_log
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
computer
.
sequence
=
[]
instance
.
requested_state
=
'stopped'
instance
.
requested_state
=
'stopped'
...
@@ -672,7 +673,7 @@ exit 1
...
@@ -672,7 +673,7 @@ exit 1
expected_text
=
'Signal handler called with signal 15'
expected_text
=
'Signal handler called with signal 15'
while
tries
>
0
:
while
tries
>
0
:
tries
-=
1
tries
-=
1
found
=
expected_text
in
open
(
wrapper_log
,
'r'
).
read
()
found
=
expected_text
in
open
(
wrapper_log
).
read
()
if
found
:
if
found
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
...
@@ -684,7 +685,7 @@ exit 1
...
@@ -684,7 +685,7 @@ exit 1
def
test_one_partition_stopped_started
(
self
):
def
test_one_partition_stopped_started
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'stopped'
instance
.
requested_state
=
'stopped'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
...
@@ -699,7 +700,7 @@ exit 1
...
@@ -699,7 +700,7 @@ exit 1
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
])
'stoppedComputerPartition'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -717,11 +718,11 @@ exit 1
...
@@ -717,11 +718,11 @@ exit 1
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
def
test_one_partition_destroyed
(
self
):
def
test_one_partition_destroyed
(
self
):
"""
"""
...
@@ -731,12 +732,10 @@ exit 1
...
@@ -731,12 +732,10 @@ exit 1
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'destroyed'
instance
.
requested_state
=
'destroyed'
dummy_file_name
=
'dummy_file'
dummy_file_name
=
'dummy_file'
dummy_file
=
open
(
with
open
(
os
.
path
.
join
(
instance
.
partition_path
,
dummy_file_name
),
'w'
)
as
dummy_file
:
os
.
path
.
join
(
instance
.
partition_path
,
dummy_file_name
),
'w'
)
dummy_file
.
write
(
'dummy'
)
dummy_file
.
write
(
'dummy'
)
dummy_file
.
close
()
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
...
@@ -758,10 +757,11 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -758,10 +757,11 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
self
.
watchdog_banged
=
os
.
path
.
join
(
self
.
_tempdir
,
'watchdog_banged'
)
self
.
watchdog_banged
=
os
.
path
.
join
(
self
.
_tempdir
,
'watchdog_banged'
)
watchdog_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'watchdog'
)
watchdog_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'watchdog'
)
open
(
watchdog_path
,
'w'
).
write
(
open
(
watchdog_path
,
'w'
).
write
(
WATCHDOG_TEMPLATE
%
dict
(
python_path
=
sys
.
executable
,
WATCHDOG_TEMPLATE
%
{
sys_path
=
sys
.
path
,
'python_path'
:
sys
.
executable
,
watchdog_banged
=
self
.
watchdog_banged
))
'sys_path'
:
sys
.
path
,
os
.
chmod
(
watchdog_path
,
0755
)
'watchdog_banged'
:
self
.
watchdog_banged
})
os
.
chmod
(
watchdog_path
,
0o755
)
self
.
grid
.
watchdog_path
=
watchdog_path
self
.
grid
.
watchdog_path
=
watchdog_path
slapos
.
grid
.
slapgrid
.
WATCHDOG_PATH
=
watchdog_path
slapos
.
grid
.
slapgrid
.
WATCHDOG_PATH
=
watchdog_path
...
@@ -794,7 +794,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -794,7 +794,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Failing'
in
open
(
daemon_log
,
'r'
).
read
())
self
.
assertTrue
(
'Failing'
in
open
(
daemon_log
).
read
())
tries
=
200
tries
=
200
while
tries
>
0
:
while
tries
>
0
:
tries
-=
1
tries
-=
1
...
@@ -802,7 +802,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -802,7 +802,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
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
).
read
())
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
):
"""
"""
...
@@ -816,7 +816,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -816,7 +816,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
4.Wait for it to fail
4.Wait for it to fail
5.Check that file generated by monkeypacthed bang do not appear
5.Check that file generated by monkeypacthed bang do not appear
"""
"""
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'
...
@@ -846,7 +846,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -846,7 +846,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Failing'
in
open
(
daemon_log
,
'r'
).
read
())
self
.
assertTrue
(
'Failing'
in
open
(
daemon_log
).
read
())
tries
=
200
tries
=
200
while
tries
>
0
:
while
tries
>
0
:
tries
-=
1
tries
-=
1
...
@@ -863,22 +863,24 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -863,22 +863,24 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
Certificates used for the bang are also checked
Certificates used for the bang are also checked
(ie: watchdog id in process name)
(ie: watchdog id in process name)
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
certificate_repository_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'partition_pki'
)
certificate_repository_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'partition_pki'
)
instance
.
setCertificate
(
certificate_repository_path
)
instance
.
setCertificate
(
certificate_repository_path
)
watchdog
=
Watchdog
(
dict
(
master_url
=
'https://127.0.0.1/'
,
watchdog
=
Watchdog
({
computer_id
=
self
.
computer_id
,
'master_url'
:
'https://127.0.0.1/'
,
certificate_repository_path
=
certificate_repository_path
))
'computer_id'
:
self
.
computer_id
,
'certificate_repository_path'
:
certificate_repository_path
})
for
event
in
watchdog
.
process_state_events
:
for
event
in
watchdog
.
process_state_events
:
instance
.
sequence
=
[]
instance
.
sequence
=
[]
instance
.
header_list
=
[]
instance
.
header_list
=
[]
headers
=
dict
(
eventname
=
event
)
headers
=
{
'eventname'
:
event
}
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
%
(
'daemon'
+
getWatchdogID
(),
instance
.
name
)
%
(
'daemon'
+
getWatchdogID
(),
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,[
'softwareInstanceBang'
])
self
.
assertEqual
(
instance
.
sequence
,
[
'softwareInstanceBang'
])
self
.
assertEqual
(
instance
.
header_list
[
0
][
'key'
],
instance
.
key
)
self
.
assertEqual
(
instance
.
header_list
[
0
][
'key'
],
instance
.
key
)
self
.
assertEqual
(
instance
.
header_list
[
0
][
'certificate'
],
instance
.
certificate
)
self
.
assertEqual
(
instance
.
header_list
[
0
][
'certificate'
],
instance
.
certificate
)
...
@@ -887,20 +889,22 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -887,20 +889,22 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
Test that a process going to a mode not watched by watchdog
Test that a process going to a mode not watched by watchdog
in supervisord is not banged if watched by watchdog
in supervisord is not banged if watched by watchdog
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
watchdog
=
Watchdog
(
dict
(
master_url
=
self
.
master_url
,
watchdog
=
Watchdog
({
computer_id
=
self
.
computer_id
,
'master_url'
:
self
.
master_url
,
certificate_repository_path
=
None
))
'computer_id'
:
self
.
computer_id
,
'certificate_repository_path'
:
None
})
for
event
in
[
'EVENT'
,
'PROCESS_STATE'
,
'PROCESS_STATE_RUNNING'
,
for
event
in
[
'EVENT'
,
'PROCESS_STATE'
,
'PROCESS_STATE_RUNNING'
,
'PROCESS_STATE_BACKOFF'
,
'PROCESS_STATE_STOPPED'
]:
'PROCESS_STATE_BACKOFF'
,
'PROCESS_STATE_STOPPED'
]:
computer
.
sequence
=
[]
computer
.
sequence
=
[]
headers
=
dict
(
eventname
=
event
)
headers
=
{
'eventname'
:
event
}
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
%
(
'daemon'
+
getWatchdogID
(),
instance
.
name
)
%
(
'daemon'
+
getWatchdogID
(),
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,[])
self
.
assertEqual
(
instance
.
sequence
,
[])
def
test_not_watched_by_watchdog_do_not_bang
(
self
):
def
test_not_watched_by_watchdog_do_not_bang
(
self
):
...
@@ -909,25 +913,27 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
...
@@ -909,25 +913,27 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest2.TestCase):
is not banged if not watched by watchdog
is not banged if not watched by watchdog
(ie: no watchdog id in process name)
(ie: no watchdog id in process name)
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
watchdog
=
Watchdog
(
dict
(
master_url
=
self
.
master_url
,
watchdog
=
Watchdog
({
computer_id
=
self
.
computer_id
,
'master_url'
:
self
.
master_url
,
certificate_repository_path
=
None
))
'computer_id'
:
self
.
computer_id
,
'certificate_repository_path'
:
None
})
for
event
in
watchdog
.
process_state_events
:
for
event
in
watchdog
.
process_state_events
:
computer
.
sequence
=
[]
computer
.
sequence
=
[]
headers
=
dict
(
eventname
=
event
)
headers
=
{
'eventname'
:
event
}
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
%
(
'daemon'
,
instance
.
name
)
%
(
'daemon'
,
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
computer
.
sequence
,[])
self
.
assertEqual
(
computer
.
sequence
,
[])
class
TestSlapgridCPPartitionProcessing
(
MasterMixin
,
unittest2
.
TestCase
):
class
TestSlapgridCPPartitionProcessing
(
MasterMixin
,
unittest2
.
TestCase
):
def
test_partition_timestamp
(
self
):
def
test_partition_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
...
@@ -941,13 +947,13 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -941,13 +947,13 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
self
.
setSlapgrid
()
self
.
setSlapgrid
()
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
).
read
())
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
def
test_partition_timestamp_develop
(
self
):
def
test_partition_timestamp_develop
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
...
@@ -965,10 +971,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -965,10 +971,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
])
'availableComputerPartition'
,
'stoppedComputerPartition'
])
def
test_partition_old_timestamp
(
self
):
def
test_partition_old_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
...
@@ -986,7 +992,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -986,7 +992,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
def
test_partition_timestamp_new_timestamp
(
self
):
def
test_partition_timestamp_new_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
...
@@ -1003,11 +1009,11 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1003,11 +1009,11 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
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
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
instance
.
timestamp
=
timestamp
...
@@ -1024,7 +1030,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1024,7 +1030,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
])
'availableComputerPartition'
,
'stoppedComputerPartition'
])
def
test_partition_periodicity_remove_timestamp
(
self
):
def
test_partition_periodicity_remove_timestamp
(
self
):
...
@@ -1032,7 +1038,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1032,7 +1038,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
Check that if periodicity forces run of buildout for a partition, it
Check that if periodicity forces run of buildout for a partition, it
removes the .timestamp file.
removes the .timestamp file.
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
...
@@ -1066,7 +1072,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1066,7 +1072,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.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
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()))
timestamp
=
str
(
int
(
time
.
time
()))
...
@@ -1082,7 +1088,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1082,7 +1088,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
setSlapgrid
()
self
.
setSlapgrid
()
self
.
grid
.
force_periodicity
=
True
self
.
grid
.
force_periodicity
=
True
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertNotEqual
(
unwanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
unwanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'startedComputerPartition'
,
'getFullComputerInformation'
])
'startedComputerPartition'
,
'getFullComputerInformation'
])
...
@@ -1101,7 +1107,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1101,7 +1107,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
software with periodicity was runned and not the other
software with periodicity was runned and not the other
5. We check that modification time of .timestamp was modified
5. We check that modification time of .timestamp was modified
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
20
,
20
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
20
,
20
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
instance0
.
timestamp
=
timestamp
instance0
.
timestamp
=
timestamp
...
@@ -1132,9 +1138,9 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1132,9 +1138,9 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
self
.
assertGreater
(
self
.
assertGreater
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
last_runtime
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
def
test_one_partition_stopped_is_not_processed_after_periodicity
(
self
):
def
test_one_partition_stopped_is_not_processed_after_periodicity
(
self
):
...
@@ -1142,7 +1148,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1142,7 +1148,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
Check that periodicity doesn't force processing a partition if it is not
Check that periodicity doesn't force processing a partition if it is not
started.
started.
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
20
,
20
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
20
,
20
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
instance0
.
timestamp
=
timestamp
instance0
.
timestamp
=
timestamp
...
@@ -1171,16 +1177,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1171,16 +1177,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
self
.
assertEqual
(
self
.
assertEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
last_runtime
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
def
test_one_partition_destroyed_is_not_processed_after_periodicity
(
self
):
def
test_one_partition_destroyed_is_not_processed_after_periodicity
(
self
):
"""
"""
Check that periodicity doesn't force processing a partition if it is not
Check that periodicity doesn't force processing a partition if it is not
started.
started.
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
20
,
20
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
20
,
20
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
timestamp
=
str
(
int
(
time
.
time
()
-
5
))
instance0
.
timestamp
=
timestamp
instance0
.
timestamp
=
timestamp
...
@@ -1211,16 +1217,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
...
@@ -1211,16 +1217,16 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest2.TestCase):
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
self
.
assertEqual
(
self
.
assertEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
last_runtime
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertNotEqual
(
wanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
def
test_one_partition_buildout_fail_does_not_disturb_others
(
self
):
def
test_one_partition_buildout_fail_does_not_disturb_others
(
self
):
"""
"""
1. We set up two instance one using a corrupted buildout
1. We set up two instance one using a corrupted buildout
2. One will fail but the other one will be processed correctly
2. One will fail but the other one will be processed correctly
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
instance1
=
computer
.
instance_list
[
1
]
instance1
=
computer
.
instance_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
...
@@ -1237,7 +1243,7 @@ exit 42""")
...
@@ -1237,7 +1243,7 @@ exit 42""")
1. We set up two instance but remove software path of one
1. We set up two instance but remove software path of one
2. One will fail but the other one will be processed correctly
2. One will fail but the other one will be processed correctly
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
instance1
=
computer
.
instance_list
[
1
]
instance1
=
computer
.
instance_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
...
@@ -1253,7 +1259,7 @@ exit 42""")
...
@@ -1253,7 +1259,7 @@ exit 42""")
1. We set up two instance but remove software bin path of one
1. We set up two instance but remove software bin path of one
2. One will fail but the other one will be processed correctly
2. One will fail but the other one will be processed correctly
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
instance1
=
computer
.
instance_list
[
1
]
instance1
=
computer
.
instance_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
...
@@ -1269,7 +1275,7 @@ exit 42""")
...
@@ -1269,7 +1275,7 @@ exit 42""")
1. We set up two instances but remove path of one
1. We set up two instances but remove path of one
2. One will fail but the other one will be processed correctly
2. One will fail but the other one will be processed correctly
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
2
,
2
)
instance0
=
computer
.
instance_list
[
0
]
instance0
=
computer
.
instance_list
[
0
]
instance1
=
computer
.
instance_list
[
1
]
instance1
=
computer
.
instance_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
...
@@ -1309,7 +1315,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1309,7 +1315,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
"""
"""
Test than an instance in "destroyed" state is correctly destroyed
Test than an instance in "destroyed" state is correctly destroyed
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
...
@@ -1324,13 +1330,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1324,13 +1330,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'availableComputerPartition'
,
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
# Then destroy the instance
# Then destroy the instance
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -1357,7 +1363,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1357,7 +1363,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
[
'getFullComputerInformation'
,
[
'getFullComputerInformation'
,
'stoppedComputerPartition'
,
'stoppedComputerPartition'
,
'destroyedComputerPartition'
])
'destroyedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
def
test_partition_list_is_complete_if_empty_destroyed_partition
(
self
):
def
test_partition_list_is_complete_if_empty_destroyed_partition
(
self
):
...
@@ -1400,7 +1406,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1400,7 +1406,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
"""
"""
Checks that slapgrid-ur don't destroy instance not to be destroyed.
Checks that slapgrid-ur don't destroy instance not to be destroyed.
"""
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
...
@@ -1415,13 +1421,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1415,13 +1421,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'availableComputerPartition'
,
'startedComputerPartition'
])
'startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
# Then run usage report and see if it is still working
# Then run usage report and see if it is still working
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -1436,7 +1442,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1436,7 +1442,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
if
os
.
path
.
getsize
(
wrapper_log
)
>
0
:
break
break
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
,
'r'
).
read
())
self
.
assertTrue
(
'Working'
in
open
(
wrapper_log
).
read
())
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
])
[
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
])
...
@@ -1449,7 +1455,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
...
@@ -1449,7 +1455,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest2.TestCase):
time
.
sleep
(
0.1
)
time
.
sleep
(
0.1
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
])
[
'getFullComputerInformation'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
def
test_slapgrid_instance_ignore_free_instance
(
self
):
def
test_slapgrid_instance_ignore_free_instance
(
self
):
...
@@ -1531,7 +1537,7 @@ instance_root = /srv/slapgrid
...
@@ -1531,7 +1537,7 @@ instance_root = /srv/slapgrid
master_url = https://slap.vifib.com/
master_url = https://slap.vifib.com/
computer_id = your computer id
computer_id = your computer id
buildout = /path/to/buildout/binary
buildout = /path/to/buildout/binary
"""
%
dict
(
fake_file
=
self
.
fake_file_descriptor
.
name
)
)
"""
)
self
.
slapos_config_descriptor
.
seek
(
0
)
self
.
slapos_config_descriptor
.
seek
(
0
)
self
.
default_arg_tuple
=
(
self
.
default_arg_tuple
=
(
'--cert_file'
,
self
.
fake_file_descriptor
.
name
,
'--cert_file'
,
self
.
fake_file_descriptor
.
name
,
...
@@ -1604,8 +1610,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
...
@@ -1604,8 +1610,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
Check if giving --all triggers "develop" option.
Check if giving --all triggers "develop" option.
"""
"""
parser
=
parseArgumentTupleAndReturnSlapgridObject
parser
=
parseArgumentTupleAndReturnSlapgridObject
argument_tuple
=
(
"--all"
,)
+
self
.
default_arg_tuple
slapgrid_object
=
parser
(
'--all'
,
*
self
.
default_arg_tuple
)[
0
]
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertTrue
(
slapgrid_object
.
develop
)
self
.
assertTrue
(
slapgrid_object
.
develop
)
def
test_backward_compatibility_not_all
(
self
):
def
test_backward_compatibility_not_all
(
self
):
...
@@ -1614,8 +1619,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
...
@@ -1614,8 +1619,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
option to be False.
option to be False.
"""
"""
parser
=
parseArgumentTupleAndReturnSlapgridObject
parser
=
parseArgumentTupleAndReturnSlapgridObject
argument_tuple
=
self
.
default_arg_tuple
slapgrid_object
=
parser
(
*
self
.
default_arg_tuple
)[
0
]
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertFalse
(
slapgrid_object
.
develop
)
self
.
assertFalse
(
slapgrid_object
.
develop
)
def
test_force_periodicity_if_periodicity_not_given
(
self
):
def
test_force_periodicity_if_periodicity_not_given
(
self
):
...
@@ -1624,8 +1628,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
...
@@ -1624,8 +1628,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
option to be false.
option to be false.
"""
"""
parser
=
parseArgumentTupleAndReturnSlapgridObject
parser
=
parseArgumentTupleAndReturnSlapgridObject
argument_tuple
=
self
.
default_arg_tuple
slapgrid_object
=
parser
(
*
self
.
default_arg_tuple
)[
0
]
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertFalse
(
slapgrid_object
.
force_periodicity
)
self
.
assertFalse
(
slapgrid_object
.
force_periodicity
)
def
test_force_periodicity_if_periodicity_given
(
self
):
def
test_force_periodicity_if_periodicity_given
(
self
):
...
@@ -1633,8 +1636,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
...
@@ -1633,8 +1636,7 @@ class TestSlapgridArgumentTuple(SlapgridInitialization):
Check if giving --maximum-periodicity triggers "force_periodicity" option.
Check if giving --maximum-periodicity triggers "force_periodicity" option.
"""
"""
parser
=
parseArgumentTupleAndReturnSlapgridObject
parser
=
parseArgumentTupleAndReturnSlapgridObject
argument_tuple
=
(
"--maximum-periodicity"
,
"40"
)
+
self
.
default_arg_tuple
slapgrid_object
=
parser
(
'--maximum-periodicity'
,
'40'
,
*
self
.
default_arg_tuple
)[
0
]
slapgrid_object
=
parser
(
*
argument_tuple
)[
0
]
self
.
assertTrue
(
slapgrid_object
.
force_periodicity
)
self
.
assertTrue
(
slapgrid_object
.
force_periodicity
)
class
TestSlapgridConfigurationFile
(
SlapgridInitialization
):
class
TestSlapgridConfigurationFile
(
SlapgridInitialization
):
...
@@ -1654,7 +1656,7 @@ buildout = /path/to/buildout/binary
...
@@ -1654,7 +1656,7 @@ buildout = /path/to/buildout/binary
upload-to-binary-cache-url-blacklist =
upload-to-binary-cache-url-blacklist =
http://1
http://1
http://2/bla
http://2/bla
"""
%
dict
(
fake_file
=
self
.
fake_file_descriptor
.
name
)
)
"""
)
self
.
slapos_config_descriptor
.
seek
(
0
)
self
.
slapos_config_descriptor
.
seek
(
0
)
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
*
self
.
default_arg_tuple
)[
0
]
*
self
.
default_arg_tuple
)[
0
]
...
@@ -1682,7 +1684,7 @@ buildout = /path/to/buildout/binary
...
@@ -1682,7 +1684,7 @@ buildout = /path/to/buildout/binary
download-from-binary-cache-url-blacklist =
download-from-binary-cache-url-blacklist =
http://1
http://1
http://2/bla
http://2/bla
"""
%
dict
(
fake_file
=
self
.
fake_file_descriptor
.
name
)
)
"""
)
self
.
slapos_config_descriptor
.
seek
(
0
)
self
.
slapos_config_descriptor
.
seek
(
0
)
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
*
self
.
default_arg_tuple
)[
0
]
*
self
.
default_arg_tuple
)[
0
]
...
@@ -1714,7 +1716,7 @@ upload-to-binary-cache-url-blacklist =
...
@@ -1714,7 +1716,7 @@ upload-to-binary-cache-url-blacklist =
download-from-binary-cache-url-blacklist =
download-from-binary-cache-url-blacklist =
http://3
http://3
http://4/bla
http://4/bla
"""
%
dict
(
fake_file
=
self
.
fake_file_descriptor
.
name
)
)
"""
)
self
.
slapos_config_descriptor
.
seek
(
0
)
self
.
slapos_config_descriptor
.
seek
(
0
)
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
*
self
.
default_arg_tuple
)[
0
]
*
self
.
default_arg_tuple
)[
0
]
...
@@ -1743,7 +1745,7 @@ buildout = /path/to/buildout/binary
...
@@ -1743,7 +1745,7 @@ buildout = /path/to/buildout/binary
binary-cache-url-blacklist =
binary-cache-url-blacklist =
http://1
http://1
http://2/bla
http://2/bla
"""
%
dict
(
fake_file
=
self
.
fake_file_descriptor
.
name
)
)
"""
)
self
.
slapos_config_descriptor
.
seek
(
0
)
self
.
slapos_config_descriptor
.
seek
(
0
)
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
slapgrid_object
=
parseArgumentTupleAndReturnSlapgridObject
(
*
self
.
default_arg_tuple
)[
0
]
*
self
.
default_arg_tuple
)[
0
]
...
@@ -1759,7 +1761,7 @@ binary-cache-url-blacklist =
...
@@ -1759,7 +1761,7 @@ binary-cache-url-blacklist =
class
TestSlapgridCPWithMasterPromise
(
MasterMixin
,
unittest2
.
TestCase
):
class
TestSlapgridCPWithMasterPromise
(
MasterMixin
,
unittest2
.
TestCase
):
def
test_one_failing_promise
(
self
):
def
test_one_failing_promise
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
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'
)
...
@@ -1780,9 +1782,10 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest2.TestCase):
...
@@ -1780,9 +1782,10 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest2.TestCase):
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
self
.
fake_waiting_time
=
0.1
self
.
fake_waiting_time
=
0.1
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_worked'
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_worked'
)
succeed
=
(
"""#!/usr/bin/env sh
succeed
=
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
exit 0"""
%
{
'worked_file'
:
worked_file
})
touch "%s"
exit 0"""
%
worked_file
)
instance
.
setPromise
(
'succeed'
,
succeed
)
instance
.
setPromise
(
'succeed'
,
succeed
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
...
@@ -1791,7 +1794,7 @@ exit 0""" % {'worked_file': worked_file})
...
@@ -1791,7 +1794,7 @@ exit 0""" % {'worked_file': worked_file})
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
def
test_stderr_has_been_sent
(
self
):
def
test_stderr_has_been_sent
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
httplib
.
HTTPConnection
.
_callback
=
computer
.
getServerResponse
()
...
@@ -1803,11 +1806,12 @@ exit 0""" % {'worked_file': worked_file})
...
@@ -1803,11 +1806,12 @@ exit 0""" % {'worked_file': worked_file})
succeed
=
os
.
path
.
join
(
promise_path
,
'stderr_writer'
)
succeed
=
os
.
path
.
join
(
promise_path
,
'stderr_writer'
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'stderr_worked'
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'stderr_worked'
)
with
open
(
succeed
,
'w'
)
as
f
:
with
open
(
succeed
,
'w'
)
as
f
:
f
.
write
(
"""#!/usr/bin/env sh
f
.
write
(
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
echo Error 1>&2
touch "%s"
exit 127"""
%
{
'worked_file'
:
worked_file
})
echo Error 1>&2
os
.
chmod
(
succeed
,
0777
)
exit 127"""
%
worked_file
))
os
.
chmod
(
succeed
,
0o777
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
...
@@ -1818,7 +1822,7 @@ exit 127""" % {'worked_file': worked_file})
...
@@ -1818,7 +1822,7 @@ exit 127""" % {'worked_file': worked_file})
def
test_timeout_works
(
self
):
def
test_timeout_works
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
...
@@ -1829,11 +1833,12 @@ exit 127""" % {'worked_file': worked_file})
...
@@ -1829,11 +1833,12 @@ exit 127""" % {'worked_file': worked_file})
succeed
=
os
.
path
.
join
(
promise_path
,
'timed_out_promise'
)
succeed
=
os
.
path
.
join
(
promise_path
,
'timed_out_promise'
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'timed_out_worked'
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'timed_out_worked'
)
with
open
(
succeed
,
'w'
)
as
f
:
with
open
(
succeed
,
'w'
)
as
f
:
f
.
write
(
"""#!/usr/bin/env sh
f
.
write
(
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
sleep 5
touch "%s"
exit 0"""
%
{
'worked_file'
:
worked_file
})
sleep 5
os
.
chmod
(
succeed
,
0777
)
exit 0"""
%
worked_file
))
os
.
chmod
(
succeed
,
0o777
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
...
@@ -1842,28 +1847,29 @@ exit 0""" % {'worked_file': worked_file})
...
@@ -1842,28 +1847,29 @@ exit 0""" % {'worked_file': worked_file})
self
.
assertIsNone
(
instance
.
state
)
self
.
assertIsNone
(
instance
.
state
)
def
test_two_succeeding_promises
(
self
):
def
test_two_succeeding_promises
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
self
.
fake_waiting_time
=
0.1
self
.
fake_waiting_time
=
0.1
for
i
in
range
(
0
,
2
):
for
i
in
range
(
2
):
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_%s_worked'
%
i
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_%s_worked'
%
i
)
succeed
=
(
"""#!/usr/bin/env sh
succeed
=
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
exit 0"""
%
{
'worked_file'
:
worked_file
})
touch "%s"
exit 0"""
%
worked_file
)
instance
.
setPromise
(
'succeed_%s'
%
i
,
succeed
)
instance
.
setPromise
(
'succeed_%s'
%
i
,
succeed
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
for
i
in
range
(
0
,
2
):
for
i
in
range
(
2
):
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_%s_worked'
%
i
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_%s_worked'
%
i
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertFalse
(
instance
.
error
)
self
.
assertFalse
(
instance
.
error
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
def
test_one_succeeding_one_failing_promises
(
self
):
def
test_one_succeeding_one_failing_promises
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
self
.
fake_waiting_time
=
0.1
self
.
fake_waiting_time
=
0.1
...
@@ -1871,42 +1877,50 @@ exit 0""" % {'worked_file': worked_file})
...
@@ -1871,42 +1877,50 @@ exit 0""" % {'worked_file': worked_file})
for
i
in
range
(
2
):
for
i
in
range
(
2
):
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_worked_%d'
%
i
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_worked_%d'
%
i
)
lockfile
=
os
.
path
.
join
(
instance
.
partition_path
,
'lock'
)
lockfile
=
os
.
path
.
join
(
instance
.
partition_path
,
'lock'
)
promise
=
(
"""#!/usr/bin/env sh
promise
=
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
if [ ! -f %(lockfile)s ]
touch "%(worked_file)s"
then
if [ ! -f %(lockfile)s ]
then
touch "%(lockfile)s"
touch "%(lockfile)s"
exit 0
exit 0
else
else
exit 127
exit 127
fi"""
%
{
'worked_file'
:
worked_file
,
'lockfile'
:
lockfile
})
fi"""
%
{
instance
.
setPromise
(
'promise_%s'
%
i
,
promise
)
'worked_file'
:
worked_file
,
'lockfile'
:
lockfile
})
instance
.
setPromise
(
'promise_%s'
%
i
,
promise
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertEquals
(
instance
.
error
,
1
)
self
.
assertEquals
(
instance
.
error
,
1
)
self
.
assertNotEqual
(
'started'
,
instance
.
state
)
self
.
assertNotEqual
(
'started'
,
instance
.
state
)
def
test_one_succeeding_one_timing_out_promises
(
self
):
def
test_one_succeeding_one_timing_out_promises
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
self
.
fake_waiting_time
=
0.1
self
.
fake_waiting_time
=
0.1
for
i
in
range
(
2
):
for
i
in
range
(
2
):
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_worked_%d'
%
i
)
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'promise_worked_%d'
%
i
)
lockfile
=
os
.
path
.
join
(
instance
.
partition_path
,
'lock'
)
lockfile
=
os
.
path
.
join
(
instance
.
partition_path
,
'lock'
)
promise
=
(
"""#!/usr/bin/env sh
promise
=
textwrap
.
dedent
(
"""
\
touch "%(worked_file)s"
#!/usr/bin/env sh
if [ ! -f %(lockfile)s ]
touch "%(worked_file)s"
then
if [ ! -f %(lockfile)s ]
then
touch "%(lockfile)s"
touch "%(lockfile)s"
else
else
sleep 5
sleep 5
fi
fi
exit 0"""
%
{
'worked_file'
:
worked_file
,
'lockfile'
:
lockfile
})
exit 0"""
%
{
'worked_file'
:
worked_file
,
'lockfile'
:
lockfile
})
instance
.
setPromise
(
'promise_%d'
%
i
,
promise
)
instance
.
setPromise
(
'promise_%d'
%
i
,
promise
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertEquals
(
instance
.
error
,
1
)
self
.
assertEquals
(
instance
.
error
,
1
)
self
.
assertNotEqual
(
instance
.
state
,
'started'
)
self
.
assertNotEqual
(
instance
.
state
,
'started'
)
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