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
Hide 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
self
.
checkEnvironmentAndCreateStructure
()
self
.
_launchSupervisord
()
slap_computer_usage
=
self
.
slap
.
registerComputer
(
self
.
computer_id
)
computer_partition_usage_list
=
[]
self
.
logger
.
info
(
'Aggregating and sending usage reports...'
)
...
...
@@ -1760,7 +1759,7 @@ stderr_logfile_backups=1
clean_run
=
True
# Loop over the different computer partitions
computer_partition_list
=
self
.
FilterComputerPartitionList
(
s
lap_computer_usage
.
getComputerPartitionList
())
s
elf
.
getComputerPartitionList
())
for
computer_partition
in
computer_partition_list
:
try
:
...
...
@@ -1895,7 +1894,7 @@ stderr_logfile_backups=1
if
self
.
validateXML
(
usage
,
computer_consumption_model
):
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
)
else
:
self
.
logger
.
info
(
'XML file is invalid %s'
%
file_path
)
...
...
@@ -1915,7 +1914,7 @@ stderr_logfile_backups=1
# We test the XML report before sending it
if
self
.
validateXML
(
computer_consumption
,
computer_consumption_model
):
self
.
logger
.
info
(
'XML file generated by asXML is valid'
)
s
lap_computer_usage
.
reportUsage
(
computer_consumption
)
s
elf
.
computer
.
reportUsage
(
computer_consumption
)
else
:
self
.
logger
.
info
(
'XML file generated by asXML is not valid !'
)
raise
ValueError
(
'XML file generated by asXML is not valid !'
)
...
...
@@ -1963,14 +1962,14 @@ stderr_logfile_backups=1
local_partition
.
stop
()
local_partition
.
_updateCertificate
()
try
:
if
not
self
.
api_backward_compatibility
:
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"start
ed"
})
else
:
computer_partition
[
"slap_partition"
].
stopped
()
if
not
self
.
api_backward_compatibility
:
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"stopp
ed"
})
else
:
computer_partition
[
"slap_partition"
].
stopped
()
except
(
SystemExit
,
KeyboardInterrupt
):
self
.
sendPartitionError
(
computer_partition
,
traceback
.
format_exc
(),
logger
=
self
.
logger
)
raise
...
...
@@ -2000,14 +1999,14 @@ stderr_logfile_backups=1
self
.
sendPartitionError
(
computer_partition
,
exc
,
logger
=
self
.
logger
)
try
:
if
destroyed
:
if
not
self
.
api_backward_compatibility
:
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"destroyed"
})
else
:
computer_partition
[
"slap_partition"
].
destroyed
()
if
not
self
.
api_backward_compatibility
:
self
.
slap
.
jio_api_connector
.
put
({
"portal_type"
:
"Software Instance"
,
"reference"
:
computer_partition
.
get
(
"reference"
),
"reported_state"
:
"destroyed"
})
else
:
computer_partition
[
"slap_partition"
].
destroyed
()
except
NotFoundError
:
self
.
logger
.
debug
(
'Ignored slap error while trying to inform about '
'destroying not fully configured Computer Partition %r'
%
...
...
slapos/tests/test_slapgrid.py
View file @
21fdbbc4
...
...
@@ -171,6 +171,7 @@ class BasicMixin(object):
force_stop
=
force_stop
,
slapgrid_jio_uri
=
self
.
master_url
+
"api/"
,
)
self
.
use_jio_api
=
True
self
.
grid
.
_manager_list
=
self
.
manager_list
# monkey patch buildout bootstrap
...
...
@@ -376,6 +377,7 @@ class SlapToolMasterMixin(MasterMixin):
force_stop
=
force_stop
,
)
self
.
grid
.
_manager_list
=
self
.
manager_list
self
.
use_jio_api
=
False
# monkey patch buildout bootstrap
class
ComputerForTest
(
object
):
...
...
@@ -392,6 +394,7 @@ class ComputerForTest(object):
Will set up instances, software and sequence
"""
self
.
sequence
=
[]
self
.
body_sequence
=
[]
self
.
instance_amount
=
instance_amount
self
.
software_amount
=
software_amount
self
.
software_root
=
software_root
...
...
@@ -424,7 +427,7 @@ class ComputerForTest(object):
# Catch API calls
if
url
.
path
.
startswith
(
'/api/'
):
content
=
json
.
loads
(
req
.
body
)
#import pdb; pdb.set_trace(
)
self
.
body_sequence
.
append
(
content
)
if
(
url
.
path
==
'/api/allDocs/'
):
if
content
[
"portal_type"
]
==
"Software Installation"
:
return
json
.
dumps
({
...
...
@@ -435,6 +438,18 @@ class ComputerForTest(object):
"state"
:
x
.
requested_state
}
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/'
):
if
content
[
"portal_type"
]
==
"Software Installation"
:
software
=
self
.
software_list
[
0
]
...
...
@@ -444,7 +459,71 @@ class ComputerForTest(object):
software
.
error
=
True
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
))
if
(
url
.
path
==
'/getFullComputerInformation'
...
...
@@ -572,6 +651,10 @@ class InstanceForTest(object):
self
.
ip_list
=
[(
'interface0'
,
'10.0.8.2'
)]
self
.
full_ip_list
=
[(
'route_interface0'
,
'10.10.2.3'
,
'10.10.0.1'
,
'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
,
):
"""
...
...
@@ -580,8 +663,7 @@ class InstanceForTest(object):
partition
=
slapos
.
slap
.
ComputerPartition
(
computer_id
,
self
.
name
)
partition
.
_software_release_document
=
self
.
getSoftwareRelease
()
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
,
'full_ip_list'
:
self
.
full_ip_list
}
...
...
@@ -638,12 +720,10 @@ class InstanceForTest(object):
os
.
mkdir
(
certificate_repository_path
)
self
.
cert_file
=
os
.
path
.
join
(
certificate_repository_path
,
"%s.crt"
%
self
.
name
)
self
.
certificate
=
str
(
random
.
random
())
with
open
(
self
.
cert_file
,
'w'
)
as
f
:
f
.
write
(
self
.
certificate
)
self
.
key_file
=
os
.
path
.
join
(
certificate_repository_path
,
'%s.key'
%
self
.
name
)
self
.
key
=
str
(
random
.
random
())
with
open
(
self
.
key_file
,
'w'
)
as
f
:
f
.
write
(
self
.
key
)
...
...
@@ -749,8 +829,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation'
,
'/stoppedComputerPartition'
]
)
[
'/
api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_partition_instance_cfg
(
self
):
"""
...
...
@@ -767,8 +847,8 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation'
,
'/stoppedComputerPartition'
]
)
[
'/
api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_free_partition
(
self
):
"""
...
...
@@ -801,8 +881,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
def
test_one_partition_started_fail
(
self
):
...
...
@@ -820,8 +899,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
instance
=
computer
.
instance_list
[
0
]
...
...
@@ -835,10 +913,10 @@ exit 1
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/softwareInstanceError'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
,
'/getHateoasUrl'
,
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
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
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -875,8 +953,7 @@ chmod 755 etc/run/wrapper
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
...
...
@@ -889,8 +966,7 @@ chmod 755 etc/run/wrapper
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
def
test_one_broken_partition_stopped
(
self
):
...
...
@@ -934,8 +1010,9 @@ chmod 755 etc/run/wrapper
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
computer
.
sequence
=
[]
...
...
@@ -951,10 +1028,12 @@ exit 1
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/softwareInstanceError'
])
[
'/getHateoasUrl'
,
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
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
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -971,8 +1050,9 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
instance
.
requested_state
=
'started'
...
...
@@ -989,8 +1069,9 @@ exit 1
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
def
test_one_partition_destroyed
(
self
):
...
...
@@ -1014,8 +1095,9 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
partition
),
[
'.slapgrid'
,
dummy_file_name
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
...
...
@@ -1405,8 +1487,8 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
with
open
(
timestamp_path
)
as
f
:
self
.
assertIn
(
timestamp
,
f
.
read
())
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_partition_timestamp_develop
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -1427,9 +1509,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
def
test_partition_old_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -1446,8 +1529,8 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
str
(
int
(
timestamp
)
-
1
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
def
test_partition_timestamp_new_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -1465,15 +1548,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance
.
timestamp
=
str
(
int
(
timestamp
)
+
1
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
])
self
.
assertEqual
(
[
x
[
0
]
for
x
in
instance
.
sequence
],
[
'/api/get/'
,
'/api/put/'
,
'/api/get/'
,
'/api/put/'
,
'/api/get/'
]
)
def
test_partition_timestamp_no_timestamp
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
...
...
@@ -1491,13 +1569,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
[
instance
.
software
.
software_hash
])
instance
.
timestamp
=
None
self
.
launchSlapgrid
()
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
[
x
[
0
]
for
x
in
instance
.
sequence
],
[
'/api/get/'
,
'/api/put/'
,
'/api/get/'
,
'/api/put/'
]
)
def
test_partition_periodicity_remove_timestamp
(
self
):
"""
...
...
@@ -1562,17 +1637,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
time
.
sleep
(
1
)
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/startedComputerPartition'
,
'/startedComputerPartition'
,
]
)
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'started'
)
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertGreater
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
...
...
@@ -1602,16 +1677,17 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
time
.
sleep
(
1
)
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/stoppedComputerPartition'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
...
...
@@ -1642,17 +1718,19 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
))
time
.
sleep
(
wanted_periodicity
+
1
)
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
time
.
sleep
(
1
)
instance0
.
requested_state
=
'destroyed'
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/stoppedComputerPartition'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
3
][
1
][
"reported_state"
],
'stopped'
)
for
instance
in
computer
.
instance_list
[
1
:]:
self
.
assertEqual
(
instance
.
sequence
,
[
'/stoppedComputerPartition'
]
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'stopped'
)
self
.
assertNotEqual
(
os
.
path
.
getmtime
(
os
.
path
.
join
(
instance0
.
partition_path
,
'.timestamp'
)),
last_runtime
)
...
...
@@ -1716,10 +1794,15 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance0
.
software
.
setBuildout
(
"""#!/bin/sh
exit 42"""
)
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance1
.
sequence
,
[
'/stoppedComputerPartition'
])
self
.
assertTrue
(
instance0
.
error_log
.
startswith
(
"Failed to run buildout profile in direct"
))
self
.
assertEqual
(
instance1
.
sequence
[
1
],
(
'/api/put/'
,
{
'portal_type'
:
'Software Instance'
,
'reference'
:
'1'
,
'reported_state'
:
'stopped'
}
)
)
def
test_one_partition_lacking_software_path_does_not_disturb_others
(
self
):
"""
...
...
@@ -1733,10 +1816,15 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
software
.
srdir
)
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance1
.
sequence
,
[
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'error'
)
self
.
assertIn
(
"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
):
"""
...
...
@@ -1750,10 +1838,12 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
software
.
srbindir
)
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance1
.
sequence
,
[
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
1
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
1
][
1
][
"reported_state"
],
'error'
)
self
.
assertIn
(
"No such file or directory"
,
instance0
.
sequence
[
1
][
1
][
"status_message"
])
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
):
"""
...
...
@@ -1767,10 +1857,12 @@ exit 42""")
instance1
.
software
=
computer
.
software_list
[
1
]
shutil
.
rmtree
(
instance0
.
partition_path
)
self
.
launchSlapgrid
()
self
.
assertEqual
(
instance0
.
sequence
,
[
'/softwareInstanceError'
])
self
.
assertEqual
(
instance1
.
sequence
,
[
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance0
.
sequence
[
0
][
0
],
'/api/put/'
)
self
.
assertEqual
(
instance0
.
sequence
[
0
][
1
][
"reported_state"
],
'error'
)
self
.
assertIn
(
"Partition directory"
,
instance0
.
sequence
[
0
][
1
][
"status_message"
])
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
):
"""
...
...
@@ -1786,7 +1878,8 @@ exit 42""")
instance
.
software
.
setBuildout
(
"""#!/bin/sh
echo %s; echo %s; exit 42"""
%
(
line1
,
line2
))
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
self
.
assertIn
(
line1
,
instance
.
error_log
)
self
.
assertIn
(
line2
,
instance
.
error_log
)
...
...
@@ -1859,7 +1952,8 @@ echo %s; echo %s; exit 42""" % (line1, line2))
[
'etc'
,
'.slapgrid'
,
'buildout.cfg'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
]
)
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
):
...
...
@@ -1885,14 +1979,18 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
self
.
assertEqual
(
instance
.
sequence
[
1
][
1
][
"reported_state"
],
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
# Then destroy the instance
computer
.
sequence
=
[]
instance
.
sequence
=
[]
instance
.
requested_state
=
'destroyed'
# Reset Cache
self
.
grid
.
computer_partition_list
=
None
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# Assert partition directory is empty
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
...
@@ -1904,9 +2002,11 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/destroyedComputerPartition'
])
[
'/api/allDocs/'
,
'/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_partition_list_is_complete_if_empty_destroyed_partition
(
self
):
...
...
@@ -1934,9 +2034,13 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertIsNotCreated
(
wrapper_log
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/destroyedComputerPartition'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/api/allDocs/'
,
'/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
):
"""
...
...
@@ -1956,10 +2060,11 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
[
'/api/allDocs/'
,
'/api/get/'
,
'/api/put/'
])
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
computer
.
sequence
=
[]
...
...
@@ -1982,7 +2087,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/
getFullComputerInformation
'
])
[
'/
api/allDocs
'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
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