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
Thomas Leymonerie
slapos.core
Commits
565dab64
Commit
565dab64
authored
Oct 16, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'return_value'
parents
08063548
0a349a97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
57 deletions
+102
-57
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+55
-16
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+47
-41
No files found.
slapos/grid/slapgrid.py
View file @
565dab64
...
...
@@ -71,6 +71,12 @@ MANDATORY_PARAMETER_LIST = [
COMPUTER_PARTITION_DESTROYED_STATE
=
'destroyed'
# Global variables about return state of slapgrid
SLAPGRID_SUCCESS
=
0
SLAPGRID_FAIL
=
1
SLAPGRID_PROMISE_FAIL
=
2
# XXX hardcoded watchdog_path
WATCHDOG_PATH
=
'/opt/slapos/bin/slapos-watchdog'
...
...
@@ -316,23 +322,29 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
def
realRun
(
argument_tuple
,
method_list
):
clean_run
=
True
slapgrid_object
,
option_dict
=
\
parseArgumentTupleAndReturnSlapgridObject
(
*
argument_tuple
)
pidfile
=
option_dict
.
get
(
'pidfile'
)
if
pidfile
:
setRunning
(
pidfile
)
try
:
failed
=
False
failed_promise
=
False
for
method
in
method_list
:
if
not
getattr
(
slapgrid_object
,
method
)():
clean_run
=
False
# Quite complicated way to figure out if everything went fine
return_value
=
getattr
(
slapgrid_object
,
method
)()
if
return_value
==
SLAPGRID_FAIL
:
failed
=
True
if
return_value
==
SLAPGRID_PROMISE_FAIL
:
failed_promise
=
True
finally
:
if
pidfile
:
setFinished
(
pidfile
)
if
clean_run
:
sys
.
exit
(
0
)
else
:
sys
.
exit
(
1
)
if
failed
:
sys
.
exit
(
SLAPGRID_FAIL
)
if
failed_promise
:
sys
.
exit
(
SLAPGRID_PROMISE_FAIL
)
sys
.
exit
(
SLAPGRID_SUCCESS
)
def
run
(
*
argument_tuple
):
...
...
@@ -520,6 +532,7 @@ class Slapgrid(object):
self
.
checkEnvironmentAndCreateStructure
()
logger
=
logging
.
getLogger
(
'SoftwareReleases'
)
logger
.
info
(
"Processing software releases..."
)
# Boolean to know if every instance has correctly been deployed
clean_run
=
True
for
software_release
in
self
.
computer
.
getSoftwareReleaseList
():
state
=
software_release
.
getState
()
...
...
@@ -600,7 +613,11 @@ class Slapgrid(object):
except
NotFoundError
:
pass
logger
.
info
(
"Finished software releases..."
)
return
clean_run
# Return success value
if
not
clean_run
:
return
SLAPGRID_FAIL
return
SLAPGRID_SUCCESS
def
_launchSupervisord
(
self
):
...
...
@@ -812,9 +829,8 @@ class Slapgrid(object):
# If partition has no SR: skip it.
try
:
software_url
=
computer_partition
.
getSoftwareRelease
().
getURI
()
software_path
=
os
.
path
.
join
(
self
.
software_root
,
getSoftwareUrlHash
(
software_url
))
os
.
path
.
join
(
self
.
software_root
,
getSoftwareUrlHash
(
computer_partition
.
getSoftwareRelease
().
getURI
()))
except
(
NotFoundError
,
TypeError
):
# This is surely free partition. Check it...
if
os
.
listdir
(
computer_partition_path
)
==
[]:
...
...
@@ -833,7 +849,6 @@ class Slapgrid(object):
# Buildout failed: send log but don't print it to output (already done)
except
BuildoutFailedError
,
exception
:
clean_run
=
False
try
:
computer_partition
.
error
(
exception
)
except
(
SystemExit
,
KeyboardInterrupt
):
...
...
@@ -845,7 +860,6 @@ class Slapgrid(object):
# For everything else: log it, send it, continue.
except
Exception
as
exception
:
clean_run
=
False
logger
.
error
(
traceback
.
format_exc
())
try
:
computer_partition
.
error
(
exception
)
...
...
@@ -867,8 +881,11 @@ class Slapgrid(object):
# Prepares environment
self
.
checkEnvironmentAndCreateStructure
()
self
.
_launchSupervisord
()
# Process Computer Partitions
# Boolean to know if every instance has correctly been deployed
clean_run
=
True
# Boolean to know if every promises correctly passed
clean_run_promise
=
True
# Filter all dummy / empty partitions
computer_partition_list
=
self
.
FilterComputerPartitionList
(
...
...
@@ -888,6 +905,18 @@ class Slapgrid(object):
computer_partition
.
error
(
exception
)
raise
except
Slapgrid
.
PromiseError
as
exception
:
clean_run_promise
=
False
try
:
logger
.
error
(
exception
)
computer_partition
.
error
(
exception
)
except
(
SystemExit
,
KeyboardInterrupt
):
raise
except
Exception
:
exception
=
traceback
.
format_exc
()
logger
.
error
(
'Problem during reporting error, continuing:
\
n
'
+
exception
)
# Buildout failed: send log but don't print it to output (already done)
except
BuildoutFailedError
,
exception
:
clean_run
=
False
...
...
@@ -914,7 +943,13 @@ class Slapgrid(object):
exception
)
logger
.
info
(
"Finished computer partitions..."
)
return
clean_run
# Return success value
if
not
clean_run
:
return
SLAPGRID_FAIL
if
not
clean_run_promise
:
return
SLAPGRID_PROMISE_FAIL
return
SLAPGRID_SUCCESS
def
validateXML
(
self
,
to_be_validated
,
xsd_model
):
...
...
@@ -1239,4 +1274,8 @@ class Slapgrid(object):
(
computer_partition
.
getId
(),
server_error
.
args
[
0
]))
logger
.
info
(
"Finished usage reports..."
)
return
clean_run
# Return success value
if
not
clean_run
:
return
SLAPGRID_FAIL
return
SLAPGRID_SUCCESS
slapos/tests/slapgrid.py
View file @
565dab64
...
...
@@ -432,14 +432,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
,
0
,
0
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[])
def
test_one_partition
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -458,7 +458,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -478,7 +478,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
software_amount
=
0
)
partition
=
computer
.
instance_list
[
0
]
partition
.
requested_state
=
'destroyed'
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
[])
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[])
...
...
@@ -489,7 +489,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
partition
=
computer
.
instance_list
[
0
]
partition
.
requested_state
=
'started'
partition
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
...
...
@@ -533,7 +533,7 @@ HEREDOC
)> etc/run/wrapper &&
chmod 755 etc/run/wrapper
"""
%
dict
(
python
=
sys
.
executable
))
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
...
...
@@ -556,7 +556,7 @@ chmod 755 etc/run/wrapper
computer
.
sequence
=
[]
instance
.
requested_state
=
'stopped'
self
.
assert
True
(
self
.
launchSlapgrid
()
)
self
.
assert
Equal
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
...
...
@@ -582,7 +582,7 @@ chmod 755 etc/run/wrapper
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'stopped'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
...
@@ -598,7 +598,7 @@ chmod 755 etc/run/wrapper
instance
.
requested_state
=
'started'
computer
.
sequence
=
[]
self
.
assert
True
(
self
.
launchSlapgrid
()
)
self
.
assert
Equal
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -634,7 +634,7 @@ chmod 755 etc/run/wrapper
dummy_file
.
write
(
'dummy'
)
dummy_file
.
close
()
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
...
@@ -680,7 +680,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
partition
.
requested_state
=
'started'
partition
.
software
.
setBuildout
(
DAEMON_CONTENT
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
...
...
@@ -730,7 +730,7 @@ touch worked
partition
.
requested_state
=
'started'
partition
.
software
.
setBuildout
(
self
.
RUN_CONTENT
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
partition
.
partition_path
),
...
...
@@ -825,7 +825,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -835,7 +835,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
timestamp_path
=
os
.
path
.
join
(
instance
.
partition_path
,
'.timestamp'
)
self
.
setSlapgrid
()
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertTrue
(
timestamp
in
open
(
timestamp_path
,
'r'
).
read
())
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
...
...
@@ -848,7 +848,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -857,8 +857,9 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertTrue
(
self
.
launchSlapgrid
(
develop
=
True
))
self
.
assertTrue
(
self
.
launchSlapgrid
())
self
.
assertEqual
(
self
.
launchSlapgrid
(
develop
=
True
),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
,
...
...
@@ -870,7 +871,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -879,7 +880,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
self
.
assert
True
(
self
.
launchSlapgrid
()
)
self
.
assert
Equal
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
,
[
'availableComputerPartition'
,
'stoppedComputerPartition'
])
...
...
@@ -890,7 +891,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp
=
str
(
int
(
time
.
time
()))
instance
.
timestamp
=
timestamp
self
.
assert
True
(
self
.
launchSlapgrid
()
)
self
.
assert
Equal
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
partition
=
os
.
path
.
join
(
self
.
instance_root
,
'0'
)
...
...
@@ -899,8 +900,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
self
.
assert
True
(
self
.
launchSlapgrid
()
)
self
.
assert
True
(
self
.
launchSlapgrid
()
)
self
.
assert
Equal
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assert
Equal
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
'stoppedComputerPartition'
,
'getFullComputerInformation'
,
...
...
@@ -953,7 +954,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self
.
setSlapgrid
()
self
.
grid
.
force_periodicity
=
True
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertNotEqual
(
unwanted_periodicity
,
self
.
grid
.
maximum_periodicity
)
self
.
assertEqual
(
computer
.
sequence
,
[
'getFullComputerInformation'
,
'availableComputerPartition'
,
...
...
@@ -1104,7 +1105,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.0_wrapper.log'
,
...
...
@@ -1128,7 +1129,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Then destroy the instance
computer
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
self
.
assert
True
(
self
.
grid
.
agregateAndSendUsage
()
)
self
.
assert
Equal
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
...
@@ -1165,7 +1166,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
self
.
assert
True
(
self
.
grid
.
agregateAndSendUsage
()
)
self
.
assert
Equal
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
...
@@ -1199,7 +1200,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
self
.
assert
True
(
self
.
grid
.
agregateAndSendUsage
()
)
self
.
assert
Equal
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
...
@@ -1227,7 +1228,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
instance
=
computer
.
instance_list
[
0
]
instance
.
requested_state
=
'started'
instance
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
os
.
listdir
(
instance
.
partition_path
),
...
...
@@ -1250,7 +1251,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Then run usage report and see if it is still working
computer
.
sequence
=
[]
self
.
assert
True
(
self
.
grid
.
agregateAndSendUsage
()
)
self
.
assert
Equal
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
self
.
assertSortedListEqual
(
...
...
@@ -1288,7 +1289,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
self
.
assertSortedListEqual
(
os
.
listdir
(
self
.
instance_root
),
[
'0'
,
'etc'
,
'var'
])
...
...
@@ -1576,11 +1577,12 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest.TestCase):
fail
=
(
"""#!/usr/bin/env sh
touch "%(worked_file)s"
exit 127"""
%
{
'worked_file'
:
worked_file
})
instance
.
setPromise
(
'fail'
,
fail
)
self
.
assertFalse
(
self
.
grid
.
processComputerPartitionList
())
instance
.
setPromise
(
'fail'
,
fail
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertTrue
(
instance
.
error
)
self
.
assertNotEqual
(
'started'
,
instance
.
state
)
self
.
assertNotEqual
(
'started'
,
instance
.
state
)
def
test_one_succeeding_promise
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -1591,12 +1593,12 @@ exit 127""" % {'worked_file': worked_file})
succeed
=
(
"""#!/usr/bin/env sh
touch "%(worked_file)s"
exit 0"""
%
{
'worked_file'
:
worked_file
})
instance
.
setPromise
(
'succeed'
,
succeed
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
instance
.
setPromise
(
'succeed'
,
succeed
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertFalse
(
instance
.
error
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
def
test_stderr_has_been_sent
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -1616,7 +1618,8 @@ touch "%(worked_file)s"
echo Error 1>&2
exit 127"""
%
{
'worked_file'
:
worked_file
})
os
.
chmod
(
succeed
,
0777
)
self
.
assertFalse
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertEqual
(
instance
.
error_log
,
'Error'
)
...
...
@@ -1641,7 +1644,8 @@ touch "%(worked_file)s"
sleep 5
exit 0"""
%
{
'worked_file'
:
worked_file
})
os
.
chmod
(
succeed
,
0777
)
self
.
assertFalse
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
self
.
assertTrue
(
instance
.
error
)
...
...
@@ -1661,7 +1665,7 @@ touch "%(worked_file)s"
exit 0"""
%
{
'worked_file'
:
worked_file
})
instance
.
setPromise
(
'succeed_%s'
%
i
,
succeed
)
self
.
assert
True
(
self
.
grid
.
processComputerPartitionList
()
)
self
.
assert
Equal
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
for
i
in
range
(
0
,
2
):
worked_file
=
os
.
path
.
join
(
instance
.
partition_path
,
'succeed_%s_worked'
%
i
)
self
.
assertTrue
(
os
.
path
.
isfile
(
worked_file
))
...
...
@@ -1687,7 +1691,8 @@ else
exit 127
fi"""
%
{
'worked_file'
:
worked_file
,
'lockfile'
:
lockfile
})
instance
.
setPromise
(
'promise_%s'
%
i
,
promise
)
self
.
assertFalse
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertEquals
(
instance
.
error
,
1
)
self
.
assertNotEqual
(
'started'
,
instance
.
state
)
...
...
@@ -1710,7 +1715,8 @@ fi
exit 0"""
%
{
'worked_file'
:
worked_file
,
'lockfile'
:
lockfile
})
instance
.
setPromise
(
'promise_%d'
%
i
,
promise
)
self
.
assertFalse
(
self
.
grid
.
processComputerPartitionList
())
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapos
.
grid
.
slapgrid
.
SLAPGRID_PROMISE_FAIL
)
self
.
assertEquals
(
instance
.
error
,
1
)
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