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
Cédric Le Ninivin
slapos.core
Commits
21fdbbc4
Commit
21fdbbc4
authored
Jul 29, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapgrid: wip continue working on new API
parent
d37500fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
233 additions
and
129 deletions
+233
-129
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+19
-20
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+214
-109
No files found.
slapos/grid/slapgrid.py
View file @
21fdbbc4
...
@@ -1730,7 +1730,6 @@ stderr_logfile_backups=1
...
@@ -1730,7 +1730,6 @@ stderr_logfile_backups=1
self
.
checkEnvironmentAndCreateStructure
()
self
.
checkEnvironmentAndCreateStructure
()
self
.
_launchSupervisord
()
self
.
_launchSupervisord
()
slap_computer_usage
=
self
.
slap
.
registerComputer
(
self
.
computer_id
)
computer_partition_usage_list
=
[]
computer_partition_usage_list
=
[]
self
.
logger
.
info
(
'Aggregating and sending usage reports...'
)
self
.
logger
.
info
(
'Aggregating and sending usage reports...'
)
...
@@ -1760,7 +1759,7 @@ stderr_logfile_backups=1
...
@@ -1760,7 +1759,7 @@ stderr_logfile_backups=1
clean_run
=
True
clean_run
=
True
# Loop over the different computer partitions
# Loop over the different computer partitions
computer_partition_list
=
self
.
FilterComputerPartitionList
(
computer_partition_list
=
self
.
FilterComputerPartitionList
(
s
lap_computer_usage
.
getComputerPartitionList
())
s
elf
.
getComputerPartitionList
())
for
computer_partition
in
computer_partition_list
:
for
computer_partition
in
computer_partition_list
:
try
:
try
:
...
@@ -1895,7 +1894,7 @@ stderr_logfile_backups=1
...
@@ -1895,7 +1894,7 @@ stderr_logfile_backups=1
if
self
.
validateXML
(
usage
,
computer_consumption_model
):
if
self
.
validateXML
(
usage
,
computer_consumption_model
):
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
s
lap_computer_usage
.
reportUsage
(
usage
)
s
elf
.
computer
.
reportUsage
(
usage
)
filename_delete_list
.
append
(
filename
)
filename_delete_list
.
append
(
filename
)
else
:
else
:
self
.
logger
.
info
(
'XML file is invalid %s'
%
file_path
)
self
.
logger
.
info
(
'XML file is invalid %s'
%
file_path
)
...
@@ -1915,7 +1914,7 @@ stderr_logfile_backups=1
...
@@ -1915,7 +1914,7 @@ stderr_logfile_backups=1
# We test the XML report before sending it
# We test the XML report before sending it
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
s
lap_computer_usage
.
reportUsage
(
computer_consumption
)
s
elf
.
computer
.
reportUsage
(
computer_consumption
)
else
:
else
:
self
.
logger
.
info
(
'XML file generated by asXML is not valid !'
)
self
.
logger
.
info
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
...
@@ -1967,7 +1966,7 @@ stderr_logfile_backups=1
...
@@ -1967,7 +1966,7 @@ stderr_logfile_backups=1
self
.
slap
.
jio_api_connector
.
put
({
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"start
ed"
"reported_state"
:
"stopp
ed"
})
})
else
:
else
:
computer_partition
[
"slap_partition"
].
stopped
()
computer_partition
[
"slap_partition"
].
stopped
()
...
...
slapos/tests/test_slapgrid.py
View file @
21fdbbc4
...
@@ -171,6 +171,7 @@ class BasicMixin(object):
...
@@ -171,6 +171,7 @@ class BasicMixin(object):
force_stop
=
force_stop
,
force_stop
=
force_stop
,
slapgrid_jio_uri
=
self
.
master_url
+
"api/"
,
slapgrid_jio_uri
=
self
.
master_url
+
"api/"
,
)
)
self
.
use_jio_api
=
True
self
.
grid
.
_manager_list
=
self
.
manager_list
self
.
grid
.
_manager_list
=
self
.
manager_list
# monkey patch buildout bootstrap
# monkey patch buildout bootstrap
...
@@ -376,6 +377,7 @@ class SlapToolMasterMixin(MasterMixin):
...
@@ -376,6 +377,7 @@ class SlapToolMasterMixin(MasterMixin):
force_stop
=
force_stop
,
force_stop
=
force_stop
,
)
)
self
.
grid
.
_manager_list
=
self
.
manager_list
self
.
grid
.
_manager_list
=
self
.
manager_list
self
.
use_jio_api
=
False
# monkey patch buildout bootstrap
# monkey patch buildout bootstrap
class
ComputerForTest
(
object
):
class
ComputerForTest
(
object
):
...
@@ -392,6 +394,7 @@ class ComputerForTest(object):
...
@@ -392,6 +394,7 @@ class ComputerForTest(object):
Will set up instances, software and sequence
Will set up instances, software and sequence
"""
"""
self
.
sequence
=
[]
self
.
sequence
=
[]
self
.
body_sequence
=
[]
self
.
instance_amount
=
instance_amount
self
.
instance_amount
=
instance_amount
self
.
software_amount
=
software_amount
self
.
software_amount
=
software_amount
self
.
software_root
=
software_root
self
.
software_root
=
software_root
...
@@ -424,7 +427,7 @@ class ComputerForTest(object):
...
@@ -424,7 +427,7 @@ class ComputerForTest(object):
# Catch API calls
# Catch API calls
if
url
.
path
.
startswith
(
'/api/'
):
if
url
.
path
.
startswith
(
'/api/'
):
content
=
json
.
loads
(
req
.
body
)
content
=
json
.
loads
(
req
.
body
)
#import pdb; pdb.set_trace(
)
self
.
body_sequence
.
append
(
content
)
if
(
url
.
path
==
'/api/allDocs/'
):
if
(
url
.
path
==
'/api/allDocs/'
):
if
content
[
"portal_type"
]
==
"Software Installation"
:
if
content
[
"portal_type"
]
==
"Software Installation"
:
return
json
.
dumps
({
return
json
.
dumps
({
...
@@ -435,6 +438,18 @@ class ComputerForTest(object):
...
@@ -435,6 +438,18 @@ class ComputerForTest(object):
"state"
:
x
.
requested_state
"state"
:
x
.
requested_state
}
for
x
in
self
.
software_list
]
}
for
x
in
self
.
software_list
]
})
})
if
content
[
"portal_type"
]
==
"Software Instance"
:
return
json
.
dumps
({
"result_list"
:
[{
"software_release_uri"
:
x
.
software
.
name
if
x
.
software
else
None
,
"reference"
:
x
.
name
,
"title"
:
x
.
name
,
"portal_type"
:
"Software Instance"
,
"compute_partition_id"
:
x
.
name
,
"state"
:
x
.
requested_state
}
for
x
in
self
.
instance_list
]
})
elif
(
url
.
path
==
'/api/put/'
):
elif
(
url
.
path
==
'/api/put/'
):
if
content
[
"portal_type"
]
==
"Software Installation"
:
if
content
[
"portal_type"
]
==
"Software Installation"
:
software
=
self
.
software_list
[
0
]
software
=
self
.
software_list
[
0
]
...
@@ -444,7 +459,71 @@ class ComputerForTest(object):
...
@@ -444,7 +459,71 @@ class ComputerForTest(object):
software
.
error
=
True
software
.
error
=
True
return
json
.
dumps
({
"id"
:
content
[
"software_release_uri"
]})
return
json
.
dumps
({
"id"
:
content
[
"software_release_uri"
]})
elif
content
[
"portal_type"
]
==
"Software Instance"
:
reference
=
content
[
"reference"
]
requested_instance
=
None
for
instance
in
self
.
instance_list
:
if
instance
.
name
==
reference
:
requested_instance
=
instance
break
if
requested_instance
:
requested_instance
.
sequence
.
append
((
url
.
path
,
content
))
if
"reported_state"
in
content
:
if
content
[
"reported_state"
]
==
"error"
:
instance
.
error_log
=
content
[
"status_message"
]
else
:
requested_instance
.
state
=
content
[
"reported_state"
]
return
json
.
dumps
({
"reference"
:
requested_instance
.
name
,
"portal_type"
:
"Software Instance"
,
"success"
:
"Done"
},
indent
=
2
)
else
:
return
json
.
dumps
({
"status"
:
"404"
,
"message"
:
"No document found with parameters: %s"
%
reference
,
"name"
:
"NotFound"
,
})
elif
(
url
.
path
==
'/api/get/'
):
if
content
[
"portal_type"
]
==
"Software Instance"
:
reference
=
content
[
"reference"
]
requested_instance
=
None
for
instance
in
self
.
instance_list
:
if
instance
.
name
==
reference
:
requested_instance
=
instance
break
if
requested_instance
:
requested_instance
.
sequence
.
append
((
url
.
path
,
content
))
return
json
.
dumps
({
"title"
:
requested_instance
.
name
,
"reference"
:
requested_instance
.
name
,
"software_release_uri"
:
requested_instance
.
software
.
name
,
"software_type"
:
None
,
"state"
:
requested_instance
.
requested_state
,
"connection_parameters"
:
{
},
"parameters"
:
{},
"shared"
:
False
,
"root_instance_title"
:
requested_instance
.
name
,
"ip_list"
:
requested_instance
.
ip_list
,
"X509"
:
{
"certificate"
:
requested_instance
.
certificate
,
"key"
:
requested_instance
.
key
},
"sla_parameters"
:
requested_instance
.
filter_dict
,
"compute_node_id"
:
None
,
"compute_partition_id"
:
requested_instance
.
name
,
"processing_timestamp"
:
requested_instance
.
timestamp
,
"access_status_message"
:
requested_instance
.
error_log
,
"portal_type"
:
"Software Instance"
})
else
:
return
json
.
dumps
({
"status"
:
"404"
,
"message"
:
"No document found with parameters: %s"
%
reference
,
"name"
:
"NotFound"
,
})
raise
ValueError
(
"Unexcepted call to API. URL:%s Content:%s"
%
(
url
.
path
,
req
.
body
))
raise
ValueError
(
"Unexcepted call to API. URL:%s Content:%s"
%
(
url
.
path
,
req
.
body
))
if
(
url
.
path
==
'/getFullComputerInformation'
if
(
url
.
path
==
'/getFullComputerInformation'
...
@@ -572,6 +651,10 @@ class InstanceForTest(object):
...
@@ -572,6 +651,10 @@ class InstanceForTest(object):
self
.
ip_list
=
[(
'interface0'
,
'10.0.8.2'
)]
self
.
ip_list
=
[(
'interface0'
,
'10.0.8.2'
)]
self
.
full_ip_list
=
[(
'route_interface0'
,
'10.10.2.3'
,
'10.10.0.1'
,
self
.
full_ip_list
=
[(
'route_interface0'
,
'10.10.2.3'
,
'10.10.0.1'
,
'255.0.0.0'
,
'10.0.0.0'
)]
'255.0.0.0'
,
'10.0.0.0'
)]
self
.
certificate
=
str
(
random
.
random
())
self
.
key
=
str
(
random
.
random
())
self
.
filter_dict
=
{}
def
getInstance
(
self
,
computer_id
,
):
def
getInstance
(
self
,
computer_id
,
):
"""
"""
...
@@ -580,7 +663,6 @@ class InstanceForTest(object):
...
@@ -580,7 +663,6 @@ class InstanceForTest(object):
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
.
_software_release_document
=
self
.
getSoftwareRelease
()
partition
.
_software_release_document
=
self
.
getSoftwareRelease
()
partition
.
_requested_state
=
self
.
requested_state
partition
.
_requested_state
=
self
.
requested_state
if
getattr
(
self
,
'filter_dict'
,
None
):
partition
.
_filter_dict
=
self
.
filter_dict
partition
.
_filter_dict
=
self
.
filter_dict
partition
.
_parameter_dict
=
{
'ip_list'
:
self
.
ip_list
,
partition
.
_parameter_dict
=
{
'ip_list'
:
self
.
ip_list
,
'full_ip_list'
:
self
.
full_ip_list
'full_ip_list'
:
self
.
full_ip_list
...
@@ -638,12 +720,10 @@ class InstanceForTest(object):
...
@@ -638,12 +720,10 @@ class InstanceForTest(object):
os
.
mkdir
(
certificate_repository_path
)
os
.
mkdir
(
certificate_repository_path
)
self
.
cert_file
=
os
.
path
.
join
(
certificate_repository_path
,
self
.
cert_file
=
os
.
path
.
join
(
certificate_repository_path
,
"%s.crt"
%
self
.
name
)
"%s.crt"
%
self
.
name
)
self
.
certificate
=
str
(
random
.
random
())
with
open
(
self
.
cert_file
,
'w'
)
as
f
:
with
open
(
self
.
cert_file
,
'w'
)
as
f
:
f
.
write
(
self
.
certificate
)
f
.
write
(
self
.
certificate
)
self
.
key_file
=
os
.
path
.
join
(
certificate_repository_path
,
self
.
key_file
=
os
.
path
.
join
(
certificate_repository_path
,
'%s.key'
%
self
.
name
)
'%s.key'
%
self
.
name
)
self
.
key
=
str
(
random
.
random
())
with
open
(
self
.
key_file
,
'w'
)
as
f
:
with
open
(
self
.
key_file
,
'w'
)
as
f
:
f
.
write
(
self
.
key
)
f
.
write
(
self
.
key
)
...
@@ -749,8 +829,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -749,8 +829,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation'
,
[
'/
api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_partition_instance_cfg
(
self
):
def
test_one_partition_instance_cfg
(
self
):
"""
"""
...
@@ -767,8 +847,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -767,8 +847,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation'
,
[
'/
api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_free_partition
(
self
):
def
test_one_free_partition
(
self
):
"""
"""
...
@@ -801,8 +881,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -801,8 +881,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
def
test_one_partition_started_fail
(
self
):
def
test_one_partition_started_fail
(
self
):
...
@@ -820,8 +899,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -820,8 +899,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
...
@@ -835,10 +913,10 @@ exit 1
...
@@ -835,10 +913,10 @@ exit 1
'etc'
,
'software_release'
,
'worked'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
,
'/getHateoasUrl'
,
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/getFullComputerInformation'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertTrue
(
instance
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
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
)
...
@@ -875,8 +953,7 @@ chmod 755 etc/run/wrapper
...
@@ -875,8 +953,7 @@ chmod 755 etc/run/wrapper
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -889,8 +966,7 @@ chmod 755 etc/run/wrapper
...
@@ -889,8 +966,7 @@ chmod 755 etc/run/wrapper
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
'/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
):
...
@@ -934,8 +1010,9 @@ chmod 755 etc/run/wrapper
...
@@ -934,8 +1010,9 @@ chmod 755 etc/run/wrapper
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/startedComputerPartition'
])
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
computer
.
sequence
=
[]
...
@@ -952,9 +1029,11 @@ exit 1
...
@@ -952,9 +1029,11 @@ exit 1
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/api/allDocs/'
,
'/softwareInstanceError'
])
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertTrue
(
instance
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
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
)
...
@@ -971,8 +1050,9 @@ exit 1
...
@@ -971,8 +1050,9 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/stoppedComputerPartition'
])
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
instance
.
requested_state
=
'started'
instance
.
requested_state
=
'started'
...
@@ -989,8 +1069,9 @@ exit 1
...
@@ -989,8 +1069,9 @@ exit 1
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/api/allDocs/'
,
'/startedComputerPartition'
])
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
def
test_one_partition_destroyed
(
self
):
def
test_one_partition_destroyed
(
self
):
...
@@ -1014,8 +1095,9 @@ exit 1
...
@@ -1014,8 +1095,9 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
dummy_file_name
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
dummy_file_name
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/stoppedComputerPartition'
])
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
...
@@ -1405,8 +1487,8 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1405,8 +1487,8 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
with
open
(
timestamp_path
)
as
f
:
with
open
(
timestamp_path
)
as
f
:
self
.
assertIn
(
timestamp
,
f
.
read
())
self
.
assertIn
(
timestamp
,
f
.
read
())
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
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
)
...
@@ -1427,9 +1509,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1427,9 +1509,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
slapgrid
.
SLAPGRID_SUCCESS
)
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
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
)
...
@@ -1446,8 +1529,8 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1446,8 +1529,8 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
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
)
...
@@ -1465,15 +1548,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1465,15 +1548,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
[
'/getHateoasUrl'
,
[
x
[
0
]
for
x
in
instance
.
sequence
],
'/getFullComputerInformation'
,
[
'/api/get/'
,
'/api/put/'
,
'/api/get/'
,
'/api/put/'
,
'/api/get/'
]
'/stoppedComputerPartition'
,
)
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/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
)
...
@@ -1491,13 +1569,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1491,13 +1569,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
[
instance
.
software
.
software_hash
])
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
None
instance
.
timestamp
=
None
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
[
'/getHateoasUrl'
,
[
x
[
0
]
for
x
in
instance
.
sequence
],
'/getFullComputerInformation'
,
[
'/api/get/'
,
'/api/put/'
,
'/api/get/'
,
'/api/put/'
]
'/stoppedComputerPartition'
,
)
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
def
test_partition_periodicity_remove_timestamp
(
self
):
def
test_partition_periodicity_remove_timestamp
(
self
):
"""
"""
...
@@ -1562,17 +1637,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1562,17 +1637,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/startedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
'/startedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
]
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'started'
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
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
)
...
@@ -1602,16 +1677,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1602,16 +1677,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
'.timestamp'
)),
last_runtime
)
last_runtime
)
...
@@ -1642,17 +1718,19 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1642,17 +1718,19 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
instance0
.
requested_state
=
'destroyed'
instance0
.
requested_state
=
'destroyed'
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
for
instance
in
computer
.
instance_list
[
1
:]:
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
'.timestamp'
)),
last_runtime
)
last_runtime
)
...
@@ -1716,10 +1794,15 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1716,10 +1794,15 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance0
.
software
.
setBuildout
(
"""#!/bin/sh
instance0
.
software
.
setBuildout
(
"""#!/bin/sh
exit 42"""
)
exit 42"""
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertTrue
(
instance0
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance1
.
sequence
[
1
],
self
.
assertEqual
(
instance1
.
sequence
,
(
[
'/stoppedComputerPartition'
])
'/api/put/'
,
{
'portal_type'
:
'Software Instance'
,
'reference'
:
'1'
,
'reported_state'
:
'stopped'
}
)
)
def
test_one_partition_lacking_software_path_does_not_disturb_others
(
self
):
def
test_one_partition_lacking_software_path_does_not_disturb_others
(
self
):
"""
"""
...
@@ -1733,10 +1816,15 @@ exit 42""")
...
@@ -1733,10 +1816,15 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
software
.
srdir
)
shutil
.
rmtree
(
instance0
.
software
.
srdir
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'error'
)
self
.
assertEqual
(
instance1
.
sequence
,
self
.
assertIn
(
[
'/stoppedComputerPartition'
])
"Software Release http://sr0/ is not present on system"
,
instance0
.
sequence
[
1
][
1
][
"status_message"
]
)
self
.
assertIn
(
"Cannot deploy instance."
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
self
.
assertEqual
(
instance1
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance1
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_one_partition_lacking_software_bin_path_does_not_disturb_others
(
self
):
def
test_one_partition_lacking_software_bin_path_does_not_disturb_others
(
self
):
"""
"""
...
@@ -1750,10 +1838,12 @@ exit 42""")
...
@@ -1750,10 +1838,12 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
software
.
srbindir
)
shutil
.
rmtree
(
instance0
.
software
.
srbindir
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'error'
)
self
.
assertEqual
(
instance1
.
sequence
,
self
.
assertIn
(
"No such file or directory"
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
[
'/stoppedComputerPartition'
])
self
.
assertIn
(
"sbin/buildout"
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
self
.
assertEqual
(
instance1
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance1
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_one_partition_lacking_path_does_not_disturb_others
(
self
):
def
test_one_partition_lacking_path_does_not_disturb_others
(
self
):
"""
"""
...
@@ -1767,10 +1857,12 @@ exit 42""")
...
@@ -1767,10 +1857,12 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
partition_path
)
shutil
.
rmtree
(
instance0
.
partition_path
)
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
self
.
assertEqual
(
instance0
.
sequence
[
0
][
0
],
'/api/put/'
)
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance0
.
sequence
[
0
][
1
][
"reported_state"
],
'error'
)
self
.
assertEqual
(
instance1
.
sequence
,
self
.
assertIn
(
"Partition directory"
,
instance0
.
sequence
[
0
][
1
][
"status_message"
])
[
'/stoppedComputerPartition'
])
self
.
assertIn
(
"does not exist"
,
instance0
.
sequence
[
0
][
1
][
"status_message"
])
self
.
assertEqual
(
instance1
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance1
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_one_partition_buildout_fail_is_correctly_logged
(
self
):
def
test_one_partition_buildout_fail_is_correctly_logged
(
self
):
"""
"""
...
@@ -1786,7 +1878,8 @@ exit 42""")
...
@@ -1786,7 +1878,8 @@ exit 42""")
instance
.
software
.
setBuildout
(
"""#!/bin/sh
instance
.
software
.
setBuildout
(
"""#!/bin/sh
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance
.
sequence
,
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
"error"
)
# We don't care of actual formatting, we just want to have full log
# We don't care of actual formatting, we just want to have full log
self
.
assertIn
(
line1
,
instance
.
error_log
)
self
.
assertIn
(
line1
,
instance
.
error_log
)
self
.
assertIn
(
line2
,
instance
.
error_log
)
self
.
assertIn
(
line2
,
instance
.
error_log
)
...
@@ -1859,7 +1952,8 @@ echo %s; echo %s; exit 42""" % (line1, line2))
...
@@ -1859,7 +1952,8 @@ echo %s; echo %s; exit 42""" % (line1, line2))
[
'etc'
,
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
]
[
'etc'
,
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
]
)
)
self
.
assertFalse
(
os
.
path
.
exists
(
promise_ran
))
self
.
assertFalse
(
os
.
path
.
exists
(
promise_ran
))
self
.
assertFalse
(
instance
.
sequence
)
self
.
assertEqual
(
len
(
instance
.
sequence
),
1
)
self
.
assertEqual
(
instance
.
sequence
[
0
][
0
],
"/api/get/"
)
class
TestSlapgridUsageReport
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridUsageReport
(
MasterMixin
,
unittest
.
TestCase
):
...
@@ -1885,14 +1979,18 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1885,14 +1979,18 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
# Then destroy the instance
# Then destroy the instance
computer
.
sequence
=
[]
computer
.
sequence
=
[]
instance
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
instance
.
requested_state
=
'destroyed'
# Reset Cache
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
# Assert partition directory is empty
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
@@ -1904,9 +2002,11 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1904,9 +2002,11 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/stoppedComputerPartition'
,
'/api/put/'
,
'/destroyedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'destroyed'
)
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
):
...
@@ -1934,9 +2034,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1934,9 +2034,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertEqual
(
self
.
assertEqual
(
computer
.
sequence
,
computer
.
sequence
,
[
'/api/allDocs/'
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/destroyedComputerPartition'
])
'/api/put/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
0
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'destroyed'
)
self
.
assertEqual
(
instance
.
state
,
'destroyed'
)
def
test_slapgrid_not_destroy_bad_instance
(
self
):
def
test_slapgrid_not_destroy_bad_instance
(
self
):
"""
"""
...
@@ -1956,10 +2060,11 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1956,10 +2060,11 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/api/allDocs/'
,
'/api/get/'
,
'/startedComputerPartition'
])
'/api/put/'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
# 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
=
[]
...
@@ -1982,7 +2087,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
...
@@ -1982,7 +2087,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation
'
])
[
'/
api/allDocs
'
])
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
):
...
...
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