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
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
e3b07565
Commit
e3b07565
authored
Aug 23, 2024
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_erp5: Test timestamp with start/stop use cases
parent
b9929aeb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
217 additions
and
20 deletions
+217
-20
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.testSlapOSERP5AllocationScenario.py
..._components/test.erp5.testSlapOSERP5AllocationScenario.py
+217
-20
No files found.
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.testSlapOSERP5AllocationScenario.py
View file @
e3b07565
...
...
@@ -147,16 +147,16 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
parameter_dict
=
software_instance
.
_asParameterDict
()
timestamp
=
parameter_dict
[
'timestamp'
]
self
.
assertTrue
(
int
(
timestamp
)
>
before_timestamp
,
self
.
assertTrue
(
timestamp
>
before_timestamp
,
"timestamp: %s < begin:%s"
%
(
timestamp
,
before_timestamp
))
# At first we expect that partition is modified later them
# bang_timestamp
partition
=
software_instance
.
getAggregateValue
()
partition_timestamp
=
str
(
int
(
float
(
partition
.
getModificationDate
())
*
1e6
)
)
partition_timestamp
=
int
(
float
(
partition
.
getModificationDate
())
*
1e6
)
self
.
assertEqual
(
timestamp
,
partition_timestamp
)
instance_timestamp
=
str
(
int
(
software_instance
.
getBangTimestamp
()
))
instance_timestamp
=
int
(
software_instance
.
getBangTimestamp
(
))
self
.
assertTrue
(
partition_timestamp
>
instance_timestamp
,
"partition: %s < instance:%s"
%
(
partition_timestamp
,
instance_timestamp
))
...
...
@@ -165,14 +165,14 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
parameter_dict
=
software_instance
.
_asParameterDict
()
timestamp_after_bang
=
parameter_dict
[
'timestamp'
]
self
.
assertTrue
(
int
(
timestamp_after_bang
)
>
int
(
timestamp
)
,
self
.
assertTrue
(
timestamp_after_bang
>
timestamp
,
"after_bang: %s < before_bang:%s"
%
(
timestamp_after_bang
,
timestamp
))
self
.
assertEqual
(
partition_timestamp
,
str
(
int
(
float
(
partition
.
getModificationDate
())
*
1e6
)
))
int
(
float
(
partition
.
getModificationDate
())
*
1e6
))
instance_timestamp
=
str
(
int
(
software_instance
.
getBangTimestamp
()
))
self
.
assertTrue
(
int
(
partition_timestamp
)
<
int
(
instance_timestamp
)
,
instance_timestamp
=
int
(
software_instance
.
getBangTimestamp
(
))
self
.
assertTrue
(
partition_timestamp
<
instance_timestamp
,
"partition: %s > instance:%s"
%
(
partition_timestamp
,
instance_timestamp
))
self
.
assertEqual
(
timestamp_after_bang
,
instance_timestamp
)
...
...
@@ -184,10 +184,10 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
timestamp
=
parameter_dict
[
'timestamp'
]
self
.
assertNotEqual
(
timestamp
,
str
(
int
(
software_instance
.
getBangTimestamp
()
)))
int
(
software_instance
.
getBangTimestamp
(
)))
self
.
assertEqual
(
str
(
int
(
float
(
partition
.
getModificationDate
())
*
1e6
)
),
timestamp
)
self
.
assertTrue
(
int
(
timestamp_after_bang
)
<
int
(
timestamp
)
,
self
.
assertEqual
(
int
(
float
(
partition
.
getModificationDate
())
*
1e6
),
timestamp
)
self
.
assertTrue
(
timestamp_after_bang
<
timestamp
,
"after_bang: %s > after_edit:%s"
%
(
timestamp_after_bang
,
timestamp
))
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
...
...
@@ -246,7 +246,7 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertTrue
(
int
(
timestamp
)
>
before_timestamp
,
self
.
assertTrue
(
timestamp
>
before_timestamp
,
"timestamp: %s < begin:%s"
%
(
timestamp
,
before_timestamp
))
self
.
login
(
owner_person
.
getUserId
())
...
...
@@ -282,11 +282,11 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertTrue
(
int
(
timestamp
)
>
int
(
before_allocation_timestamp
)
,
"timestamp: %s < be
gin
:%s"
%
(
timestamp
,
before_allocation_timestamp
))
self
.
assertTrue
(
timestamp
>
before_allocation_timestamp
,
"timestamp: %s < be
fore_allocation_timestamp
:%s"
%
(
timestamp
,
before_allocation_timestamp
))
self
.
assertTrue
(
int
(
timestamp
)
>
int
(
before_allocation_instance_timestamp
)
,
"timestamp: %s < be
gi
n:%s"
%
(
timestamp
,
before_allocation_instance_timestamp
))
self
.
assertTrue
(
timestamp
>
before_allocation_instance_timestamp
,
"timestamp: %s < be
fore_instance_allocatio
n:%s"
%
(
timestamp
,
before_allocation_instance_timestamp
))
slave_instance
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Slave Instance'
,
title
=
slave_instance_title
)
...
...
@@ -294,17 +294,214 @@ class TestSlapOSAllocationScenario(TestSlapOSAllocationScenarioMixin):
# The slave instance was bang so that's why timestamp was updated,
# this ensure response to server is updated.
self
.
assertEqual
(
timestamp
,
str
(
int
(
slave_instance
.
getBangTimestamp
()
)))
int
(
slave_instance
.
getBangTimestamp
(
)))
parameter_slave_list
=
partition_parameter_dict
[
'_parameter_dict'
][
'slave_instance_list'
]
self
.
assertEqual
(
len
(
parameter_slave_list
),
1
)
self
.
assertEqual
(
parameter_slave_list
[
0
][
'timestamp'
],
timestamp
)
self
.
login
(
owner_person
.
getUserId
())
self
.
checkSlaveInstanceUnallocation
(
owner_person
.
getUserId
(),
self
.
checkSlaveInstanceUnallocation
(
owner_person
.
getUserId
(),
owner_person
.
getReference
(),
slave_instance_title
,
slave_server_software
,
slave_instance_type
,
compute_node
,
project
.
getReference
())
self
.
tic
()
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
# Ensure compute node gets the proper timestamp
partition_parameter_dict
=
[
d
for
d
in
computer_information_dict
[
'_computer_partition_list'
]
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
parameter_slave_list
=
partition_parameter_dict
[
'_parameter_dict'
][
'slave_instance_list'
]
self
.
assertEqual
(
len
(
parameter_slave_list
),
0
)
timestamp_before_unallocation
=
timestamp
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertNotEqual
(
timestamp_before_unallocation
,
timestamp
)
self
.
assertTrue
(
timestamp
>
timestamp_before_unallocation
,
"timestamp: %s < before_unallocation:%s"
%
(
timestamp
,
timestamp_before_unallocation
))
self
.
removeSoftwareReleaseFromComputer
(
owner_person
,
compute_node
,
software_release
)
self
.
checkERP5StateBeforeExit
()
def
test_stopped_slave_instance_allocation_scenario
(
self
):
project
,
owner_person
=
self
.
bootstrapVirtualMasterTestWithProject
()
self
.
logout
()
# and install some software on them
software_release
=
self
.
generateNewSoftwareReleaseUrl
()
software_type
=
'public type'
compute_node
=
self
.
createComputeNodeForOwner
(
computer_owner
=
owner_person
,
project
=
project
,
software_release
=
software_release
,
software_type
=
software_type
)
before_timestamp
=
int
(
float
(
DateTime
())
*
1e6
)
instance_title
=
'Public title %s'
%
self
.
generateNewId
()
self
.
checkInstanceAllocation
(
owner_person
.
getUserId
(),
owner_person
.
getReference
(),
instance_title
,
software_release
,
software_type
,
compute_node
,
project
.
getReference
())
self
.
login
(
owner_person
.
getUserId
())
# let's find instances of user and check connection strings
partition_reference
=
[
q
.
getSuccessorValue
().
getAggregateReference
()
for
q
in
self
.
_getCurrentInstanceTreeList
()
if
q
.
getTitle
()
==
instance_title
][
0
]
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
# Ensure compute node gets the proper timestamp
partition_parameter_dict
=
[
d
for
d
in
computer_information_dict
[
'_computer_partition_list'
]
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertTrue
(
timestamp
>
before_timestamp
,
"timestamp: %s < begin:%s"
%
(
timestamp
,
before_timestamp
))
self
.
login
(
owner_person
.
getUserId
())
instance_node_title
=
'Shared Instance for %s'
%
owner_person
.
getReference
()
# Convert the Software Instance into an Instance Node
# to explicitely mark it as accepting Slave Instance
software_instance
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Software Instance'
,
title
=
instance_title
)
before_allocation_instance_timestamp
=
software_instance
.
getBangTimestamp
()
instance_node
=
self
.
addInstanceNode
(
instance_node_title
,
software_instance
)
slave_server_software
=
self
.
generateNewSoftwareReleaseUrl
()
slave_instance_type
=
'slave type'
software_product
,
slave_software_release
,
software_type
=
self
.
addSoftwareProduct
(
'share product'
,
project
,
slave_server_software
,
slave_instance_type
)
self
.
addAllocationSupply
(
"for instance node"
,
instance_node
,
software_product
,
slave_software_release
,
software_type
)
slave_instance_title
=
'Slave title %s'
%
self
.
generateNewId
()
self
.
checkSlaveInstanceAllocation
(
owner_person
.
getUserId
(),
owner_person
.
getReference
(),
slave_instance_title
,
slave_server_software
,
slave_instance_type
,
compute_node
,
project
.
getReference
())
self
.
login
(
owner_person
.
getUserId
())
before_allocation_timestamp
=
timestamp
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
# Ensure compute node gets the proper timestamp
partition_parameter_dict
=
[
d
for
d
in
computer_information_dict
[
'_computer_partition_list'
]
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertTrue
(
timestamp
>
before_allocation_timestamp
,
"timestamp: %s < before_allocation_timestamp:%s"
%
(
timestamp
,
before_allocation_timestamp
))
self
.
assertTrue
(
timestamp
>
before_allocation_instance_timestamp
,
"timestamp: %s < before_instance_allocation:%s"
%
(
timestamp
,
before_allocation_instance_timestamp
))
slave_instance
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Slave Instance'
,
title
=
slave_instance_title
)
# The slave instance was bang so that's why timestamp was updated,
# this ensure response to server is updated.
self
.
assertEqual
(
timestamp
,
int
(
slave_instance
.
getBangTimestamp
()))
parameter_slave_list
=
partition_parameter_dict
[
'_parameter_dict'
][
'slave_instance_list'
]
self
.
assertEqual
(
len
(
parameter_slave_list
),
1
)
self
.
assertEqual
(
parameter_slave_list
[
0
][
'timestamp'
],
timestamp
)
self
.
login
(
owner_person
.
getUserId
())
self
.
personRequestInstance
(
software_release
=
slave_server_software
,
software_type
=
slave_instance_type
,
partition_reference
=
slave_instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
state
=
'<marshal><string>stopped</string></marshal>'
,
project_reference
=
project
.
getReference
()
)
self
.
simulateSlapgridCP
(
compute_node
)
self
.
tic
()
self
.
assertEqual
(
slave_instance
.
getSlapState
(),
'stop_requested'
)
before_stop_timestamp
=
timestamp
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
# Ensure compute node gets the proper timestamp
partition_parameter_dict
=
[
d
for
d
in
computer_information_dict
[
'_computer_partition_list'
]
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertTrue
(
timestamp
>
before_stop_timestamp
,
"timestamp: %s < before_stop_timestamp:%s"
%
(
timestamp
,
before_stop_timestamp
))
self
.
assertEqual
(
timestamp
,
int
(
software_instance
.
getBangTimestamp
()))
# no entry expected
parameter_slave_list
=
partition_parameter_dict
[
'_parameter_dict'
][
'slave_instance_list'
]
self
.
assertEqual
(
len
(
parameter_slave_list
),
0
)
# Start again and re-check if the timestamp was updated
self
.
login
(
owner_person
.
getUserId
())
self
.
personRequestInstance
(
software_release
=
slave_server_software
,
software_type
=
slave_instance_type
,
partition_reference
=
slave_instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
state
=
'<marshal><string>started</string></marshal>'
,
project_reference
=
project
.
getReference
()
)
self
.
simulateSlapgridCP
(
compute_node
)
self
.
tic
()
before_start_timestamp
=
timestamp
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
# Ensure compute node gets the proper timestamp
partition_parameter_dict
=
[
d
for
d
in
computer_information_dict
[
'_computer_partition_list'
]
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertTrue
(
timestamp
>
before_start_timestamp
,
"timestamp: %s < before_start_timestamp:%s"
%
(
timestamp
,
before_start_timestamp
))
# The slave instance was bang so that's why timestamp was updated,
# this ensure response to server is updated.
self
.
assertEqual
(
timestamp
,
int
(
slave_instance
.
getBangTimestamp
()))
parameter_slave_list
=
partition_parameter_dict
[
'_parameter_dict'
][
'slave_instance_list'
]
self
.
assertEqual
(
len
(
parameter_slave_list
),
1
)
self
.
assertEqual
(
parameter_slave_list
[
0
][
'timestamp'
],
timestamp
)
self
.
login
(
owner_person
.
getUserId
())
self
.
checkSlaveInstanceUnallocation
(
owner_person
.
getUserId
(),
owner_person
.
getReference
(),
slave_instance_title
,
slave_server_software
,
slave_instance_type
,
compute_node
,
project
.
getReference
())
self
.
tic
()
computer_information_dict
=
compute_node
.
_getCacheComputeNodeInformation
(
None
)
# Ensure compute node gets the proper timestamp
partition_parameter_dict
=
[
d
for
d
in
computer_information_dict
[
'_computer_partition_list'
]
if
d
[
'partition_id'
]
==
partition_reference
][
0
]
parameter_slave_list
=
partition_parameter_dict
[
'_parameter_dict'
][
'slave_instance_list'
]
self
.
assertEqual
(
len
(
parameter_slave_list
),
0
)
timestamp_before_unallocation
=
timestamp
timestamp
=
partition_parameter_dict
[
'_parameter_dict'
][
'timestamp'
]
self
.
assertNotEqual
(
timestamp_before_unallocation
,
timestamp
)
self
.
assertTrue
(
timestamp
>
timestamp_before_unallocation
,
"timestamp: %s < before_unallocation:%s"
%
(
timestamp
,
timestamp_before_unallocation
))
self
.
removeSoftwareReleaseFromComputer
(
owner_person
,
compute_node
,
software_release
)
...
...
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