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
Titouan Soulard
slapos.core
Commits
1f1e19eb
Commit
1f1e19eb
authored
Apr 06, 2023
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Sep 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_erp5: Move Default Scenario Test to jIO API
parent
77ef158b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
352 additions
and
95 deletions
+352
-95
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
...omponents/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
+348
-94
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.testSlapOSERP5DefaultScenario.py
...tal_components/test.erp5.testSlapOSERP5DefaultScenario.py
+4
-1
No files found.
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
View file @
1f1e19eb
...
...
@@ -22,13 +22,14 @@
import
six
import
six.moves.urllib.parse
from
erp5.component.test.testSlapOSCloudSecurityGroup
import
TestSlapOSSecurityMixin
from
erp5.component.test.testSlapOSJIOAPI
import
TestSlapOSJIOAPIMixin
from
erp5.component.test.SlapOSTestCaseMixin
import
changeSkin
import
re
import
xml_marshaller
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
setSecurityManager
class
DefaultScenarioMixin
(
TestSlapOSSecurityMixin
):
class
DefaultScenarioMixin
(
TestSlapOSSecurityMixin
,
TestSlapOSJIOAPIMixin
):
def
afterSetUp
(
self
):
TestSlapOSSecurityMixin
.
afterSetUp
(
self
)
...
...
@@ -42,6 +43,9 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
)
"""
self.web_site = self.portal.web_site_module.hostingjs
self.callUpdateRevision()
# Enable alarms for regularisation request
self.portal.portal_alarms.slapos_crm_create_regularisation_request.setEnabled(True)
self.portal.portal_alarms.slapos_crm_invalidate_suspended_regularisation_request.setEnabled(True)
...
...
@@ -49,7 +53,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self.portal.portal_alarms.slapos_crm_trigger_stop_acknowledgment_escalation.setEnabled(True)
self.portal.portal_alarms.slapos_crm_trigger_delete_reminder_escalation.setEnabled(True)
self.portal.portal_alarms.slapos_crm_trigger_acknowledgment_escalation.setEnabled(True)
"""
"""
# Create akarls steps
self
.
createAlarmStep
()
...
...
@@ -166,17 +170,24 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
agent
.
setAccessStatus
(
"#access "
)
def
requestComputeNode
(
self
,
title
,
project_reference
):
requestXml
=
self
.
portal
.
portal_slap
.
requestComputer
(
title
,
project_reference
)
#requestXml = self.portal.portal_slap.requestComputer(title, project_reference)
request_data
=
self
.
postToApi
({
"portal_type"
:
"Compute Node"
,
"title"
:
title
})
self
.
tic
()
self
.
assertTrue
(
'marshal'
in
requestXml
)
compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
requestXml
)
compute_node_id
=
getattr
(
compute_node
,
'_computer_id'
,
None
)
self
.
assertNotEqual
(
None
,
compute_node_id
)
return
compute_node_id
.
encode
(
'UTF-8'
)
self
.
callUpdateRevisionAndTic
()
return
request_data
[
"compute_node_id"
]
def
supplySoftware
(
self
,
server
,
url
,
state
=
'available'
):
self
.
portal
.
portal_slap
.
supplySupply
(
url
,
server
.
getReference
(),
state
)
self
.
postToApi
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
server
.
getReference
(),
"software_release_uri"
:
url
,
"state"
:
state
,
})
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
software_installation
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Software Installation'
,
...
...
@@ -218,28 +229,43 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
def
formatComputeNode
(
self
,
compute_node
,
partition_count
=
10
):
compute_node_dict
=
dict
(
software_root
=
'/opt'
,
reference
=
compute_node
.
getReference
(),
netmask
=
'255.255.255.0'
,
address
=
'128.0.0.1'
,
instance_root
=
'/srv'
compute_node_id
=
compute_node
.
getReference
(),
portal_type
=
"Compute Node"
,
)
compute_node_dict
[
'partition_list'
]
=
[]
a
=
compute_node_dict
[
'partition_list'
].
append
compute_node_dict
[
'
compute_
partition_list'
]
=
[]
a
=
compute_node_dict
[
'
compute_
partition_list'
].
append
for
i
in
range
(
1
,
partition_count
+
1
):
a
(
dict
(
reference
=
'part%s'
%
i
,
tap
=
dict
(
name
=
'tap%s'
%
i
),
address_list
=
[
dict
(
addr
=
'p%sa1'
%
i
,
netmask
=
'p%sn1'
%
i
),
dict
(
addr
=
'p%sa2'
%
i
,
netmask
=
'p%sn2'
%
i
)
partition_id
=
'part%s'
%
i
,
ip_list
=
[
{
"ip-address"
:
'p%sa1'
%
i
,
"network-interface"
:
'tap%s'
%
i
,
},
{
"ip-address"
:
'p%sa2'
%
i
,
"network-interface"
:
'tap%s'
%
i
,
},
{
"ip-address"
:
'p%sa1'
%
i
,
"gateway-ip-address"
:
'p%sn1'
%
i
,
"network-interface"
:
'tap%s'
%
i
,
"netmask"
:
'255.255.255.0'
,
"network-address"
:
'128.0.0.1'
,
},
{
"ip-address"
:
'p%sa2'
%
i
,
"gateway-ip-address"
:
'p%sn2'
%
i
,
"network-interface"
:
'tap%s'
%
i
,
"netmask"
:
'255.255.255.0'
,
"network-address"
:
'128.0.0.1'
,
}
]
))
sm
=
getSecurityManager
()
try
:
self
.
login
(
compute_node
.
getUserId
())
self
.
portal
.
portal_slap
.
loadComputerConfigurationFromXML
(
xml_marshaller
.
xml_marshaller
.
dumps
(
compute_node_dict
))
self
.
putToApi
(
compute_node_dict
)
self
.
tic
()
self
.
assertEqual
(
partition_count
,
len
(
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
)))
...
...
@@ -251,21 +277,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
computer_id
=
compute_node
.
getReference
())
if
not
isinstance
(
compute_node_xml
,
str
):
compute_node_xml
=
compute_node_xml
.
getBody
()
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
for
software_release
in
slap_compute_node
.
_software_release_list
:
if
software_release
.
_requested_state
==
'destroyed'
:
self
.
portal
.
portal_slap
.
destroyedSoftwareRelease
(
software_release
.
_software_release
,
compute_node
.
getReference
())
software_release_list
=
self
.
allDocsToApi
({
"portal_type"
:
"Software Installation"
,
"compute_node_id"
:
compute_node
.
getReference
()
})[
"result_list"
]
for
software_release
in
software_release_list
:
if
software_release
[
"state"
]
==
'destroyed'
:
self
.
putToApi
({
"portal_type"
:
"Software Installation"
,
"compute_noode_id"
:
compute_node
.
getReference
(),
"software_release_uri"
:
software_release
[
"software_release_uri"
],
"reported_state"
:
"destroyed"
,
})
else
:
self
.
portal
.
portal_slap
.
availableSoftwareRelease
(
software_release
.
_software_release
,
compute_node
.
getReference
())
self
.
putToApi
({
"portal_type"
:
"Software Installation"
,
"compute_noode_id"
:
compute_node
.
getReference
(),
"software_release_uri"
:
software_release
[
"software_release_uri"
],
"reported_state"
:
"available"
,
})
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
...
...
@@ -274,24 +304,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
sm
=
getSecurityManager
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
self
.
callUpdateRevisionAndTic
()
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
computer_id
=
compute_node
.
getReference
())
if
not
isinstance
(
compute_node_xml
,
str
):
compute_node_xml
=
compute_node_xml
.
getBody
()
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
instance_list
=
self
.
allDocsToApi
({
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
compute_node
.
getReference
()
})[
"result_list"
]
destroyed_partition_id_list
=
[]
for
partition
in
slap_compute_node
.
_computer_partition_list
:
if
partition
.
_requested_state
==
'destroyed'
\
and
partition
.
_need_modification
==
1
:
self
.
portal
.
portal_slap
.
destroyedComputerPartition
(
compute_node
.
getReference
(),
partition
.
_partition_id
.
encode
(
"UTF-8"
)
)
destroyed_partition_id_list
.
append
(
partition
.
_partition_id
.
encode
(
"UTF-8"
))
for
partition
in
instance_list
:
if
partition
[
"state"
]
==
'destroyed'
:
self
.
putToApi
({
"portal_type"
:
"Software Instance"
,
"reference"
:
partition
[
"reference"
],
"reported_state"
:
"destroyed"
})
destroyed_partition_id_list
.
append
(
partition
[
"compute_partition_id"
])
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
self
.
stepCallSlaposFreeComputePartitionAlarm
()
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
free_partition_id_list
=
[]
for
partition
in
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
):
if
partition
.
getReference
()
in
destroyed_partition_id_list
\
...
...
@@ -301,25 +334,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
def
simulateSlapgridCP
(
self
,
compute_node
):
sm
=
getSecurityManager
()
compute_node_reference
=
compute_node
.
getReference
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
computer_id
=
compute_node
.
getReference
())
if
not
isinstance
(
compute_node_xml
,
str
):
compute_node_xml
=
compute_node_xml
.
getBody
()
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
for
partition
in
slap_compute_node
.
_computer_partition_list
:
if
partition
.
_requested_state
in
(
'started'
,
'stopped'
)
\
and
partition
.
_need_modification
==
1
:
instance_reference
=
partition
.
_instance_guid
.
encode
(
'UTF-8'
)
ip_list
=
partition
.
_parameter_dict
[
'ip_list'
]
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
dict
(
instance_list
=
self
.
allDocsToApi
({
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
compute_node
.
getReference
()
})[
"result_list"
]
for
partition
in
instance_list
:
if
partition
[
"state"
]
in
(
'started'
,
'stopped'
):
partition
=
self
.
getToApi
({
"portal_type"
:
"Software Instance"
,
"reference"
:
partition
[
"reference"
],
})
instance_reference
=
partition
[
"reference"
]
ip_list
=
partition
[
'ip_list'
]
connection_dict
=
dict
(
url_1
=
'http://%s/'
%
ip_list
[
0
][
1
],
url_2
=
'http://%s/'
%
ip_list
[
1
][
1
],
)
)
)
self
.
login
()
instance_user_id
=
self
.
portal
.
portal_catalog
.
getResultValue
(
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
...
...
@@ -327,23 +360,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
oldsm
=
getSecurityManager
()
try
:
self
.
login
(
instance_user_id
)
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
computer_id
=
compute_node_reference
,
computer_partition_id
=
partition
.
_partition_id
,
connection_xml
=
connection_xml
)
for
slave
in
partition
.
_parameter_dict
[
'slave_instance_list'
]:
slave_reference
=
slave
[
'slave_reference'
]
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
dict
(
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
slave_reference
),
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
slave_reference
)
))
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
computer_id
=
compute_node_reference
,
computer_partition_id
=
partition
.
_partition_id
,
connection_xml
=
connection_xml
,
slave_reference
=
slave_reference
self
.
putToApi
({
"portal_type"
:
"Software Instance"
,
"reference"
:
partition
[
"reference"
],
"connection_parameters"
:
connection_dict
,
})
hosted_instance_list
=
self
.
allDocsToApi
({
"portal_type"
:
"Shared Instance"
,
"host_instance_reference"
:
partition
[
"reference"
],
"state"
:
"started"
})[
"result_list"
]
for
hosted_instance
in
hosted_instance_list
:
hosted_reference
=
hosted_instance
[
'reference'
]
connection_dict
=
dict
(
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
hosted_reference
),
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
hosted_reference
)
)
self
.
putToApi
({
"portal_type"
:
"Software Instance"
,
"reference"
:
hosted_reference
,
"connection_parameters"
:
connection_dict
,
})
finally
:
setSecurityManager
(
oldsm
)
...
...
@@ -352,16 +389,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
tic
()
def
personRequestInstanceNotReady
(
self
,
**
kw
):
response
=
self
.
portal
.
portal_slap
.
requestComputerPartition
(
**
kw
)
status
=
getattr
(
response
,
'status'
,
None
)
self
.
assertEqual
(
408
,
status
)
kw
[
"portal_type"
]
=
"Software Instance"
response
=
self
.
postToApi
(
kw
)
response
.
pop
(
"$schema"
)
response
.
pop
(
"debug_id"
,
None
)
expected_dict
=
{
"message"
:
"Software Instance Not Ready"
,
"name"
:
"SoftwareInstanceNotReady"
,
"status"
:
102
,
}
if
response
!=
expected_dict
:
self
.
assertIsNone
(
response
[
'compute_node_id'
])
self
.
assertIsNone
(
response
[
'compute_partition_id'
])
self
.
tic
()
def
personRequestInstance
(
self
,
**
kw
):
response
=
self
.
portal
.
portal_slap
.
requestComputerPartition
(
**
kw
)
self
.
assertTrue
(
isinstance
(
response
,
str
),
"response is not a string: %s"
%
response
)
software_instance
=
xml_marshaller
.
xml_marshaller
.
loads
(
response
)
self
.
assertEqual
(
'SoftwareInstance'
,
software_instance
.
__class__
.
__name__
)
kw
[
"portal_type"
]
=
"Software Instance"
software_instance
=
self
.
postToApi
(
kw
)
self
.
assertTrue
(
software_instance
.
get
(
"portal_type"
,
""
)
in
(
"Slave Instance"
,
"Software Instance"
))
self
.
tic
()
return
software_instance
...
...
@@ -372,22 +418,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
tic
()
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
project_reference
=
project_reference
title
=
instance_title
,
shared
=
True
)
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
self
.
login
(
person_user_id
)
self
.
personRequestInstance
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
project_reference
=
project_reference
title
=
instance_title
,
shared
=
True
)
# now instantiate it on compute_node and set some nice connection dict
...
...
@@ -537,12 +588,15 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
state
=
'<marshal><string>destroyed</string></marshal>'
,
project_reference
=
project_reference
title
=
instance_title
,
shared
=
True
,
state
=
'destroyed'
,
)
# let's find instances of user and check connection strings
...
...
@@ -558,11 +612,13 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
state
=
'<marshal><string>destroyed</string></marshal>'
,
project_reference
=
project_reference
title
=
instance_title
,
state
=
'destroyed'
)
# now instantiate it on compute_node and set some nice connection dict
...
...
@@ -591,12 +647,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
project_reference
=
project_reference
title
=
instance_title
,
)
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
# XXX search only for this user
instance_tree
=
self
.
portal
.
portal_catalog
.
getResultValue
(
...
...
@@ -609,10 +667,11 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
personRequestInstance
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
project_reference
=
project_reference
title
=
instance_title
,
)
# now instantiate it on compute_node and set some nice connection dict
...
...
@@ -826,8 +885,203 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
project_reference
=
project_reference
title
=
instance_title
,
)
class
DefaultScenarioMixinSlapTool
(
DefaultScenarioMixin
):
"""
Same as default scenario mixin but with SlapTool methods
"""
def
requestComputeNode
(
self
,
title
):
requestXml
=
self
.
portal
.
portal_slap
.
requestComputer
(
title
)
self
.
tic
()
self
.
assertTrue
(
'marshal'
in
requestXml
)
compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
requestXml
)
compute_node_id
=
getattr
(
compute_node
,
'_computer_id'
,
None
)
self
.
assertNotEqual
(
None
,
compute_node_id
)
return
compute_node_id
.
encode
(
'UTF-8'
)
def
supplySoftware
(
self
,
server
,
url
,
state
=
'available'
):
self
.
portal
.
portal_slap
.
supplySupply
(
url
,
server
.
getReference
(),
state
)
self
.
tic
()
software_installation
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Software Installation'
,
url_string
=
url
,
default_aggregate_uid
=
server
.
getUid
())
self
.
assertNotEqual
(
None
,
software_installation
)
if
state
==
'available'
:
self
.
assertEqual
(
'start_requested'
,
software_installation
.
getSlapState
())
else
:
self
.
assertEqual
(
'destroy_requested'
,
software_installation
.
getSlapState
())
def
formatComputeNode
(
self
,
compute_node
,
partition_count
=
10
):
compute_node_dict
=
dict
(
software_root
=
'/opt'
,
reference
=
compute_node
.
getReference
(),
netmask
=
'255.255.255.0'
,
address
=
'128.0.0.1'
,
instance_root
=
'/srv'
)
compute_node_dict
[
'partition_list'
]
=
[]
a
=
compute_node_dict
[
'partition_list'
].
append
for
i
in
range
(
1
,
partition_count
+
1
):
a
(
dict
(
reference
=
'part%s'
%
i
,
tap
=
dict
(
name
=
'tap%s'
%
i
),
address_list
=
[
dict
(
addr
=
'p%sa1'
%
i
,
netmask
=
'p%sn1'
%
i
),
dict
(
addr
=
'p%sa2'
%
i
,
netmask
=
'p%sn2'
%
i
)
]
))
sm
=
getSecurityManager
()
try
:
self
.
login
(
compute_node
.
getUserId
())
self
.
portal
.
portal_slap
.
loadComputerConfigurationFromXML
(
xml_marshaller
.
xml_marshaller
.
dumps
(
compute_node_dict
))
self
.
tic
()
self
.
assertEqual
(
partition_count
,
len
(
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
)))
finally
:
setSecurityManager
(
sm
)
def
simulateSlapgridSR
(
self
,
compute_node
):
sm
=
getSecurityManager
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
computer_id
=
compute_node
.
getReference
())
if
not
isinstance
(
compute_node_xml
,
str
):
compute_node_xml
=
compute_node_xml
.
getBody
()
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
for
software_release
in
slap_compute_node
.
_software_release_list
:
if
software_release
.
_requested_state
==
'destroyed'
:
self
.
portal
.
portal_slap
.
destroyedSoftwareRelease
(
software_release
.
_software_release
,
compute_node
.
getReference
())
else
:
self
.
portal
.
portal_slap
.
availableSoftwareRelease
(
software_release
.
_software_release
,
compute_node
.
getReference
())
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
def
simulateSlapgridUR
(
self
,
compute_node
):
sm
=
getSecurityManager
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
computer_id
=
compute_node
.
getReference
())
if
not
isinstance
(
compute_node_xml
,
str
):
compute_node_xml
=
compute_node_xml
.
getBody
()
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
destroyed_partition_id_list
=
[]
for
partition
in
slap_compute_node
.
_computer_partition_list
:
if
partition
.
_requested_state
==
'destroyed'
\
and
partition
.
_need_modification
==
1
:
self
.
portal
.
portal_slap
.
destroyedComputerPartition
(
compute_node
.
getReference
(),
partition
.
_partition_id
.
encode
(
"UTF-8"
)
)
destroyed_partition_id_list
.
append
(
partition
.
_partition_id
.
encode
(
"UTF-8"
))
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
self
.
stepCallSlaposFreeComputePartitionAlarm
()
self
.
tic
()
free_partition_id_list
=
[]
for
partition
in
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
):
if
partition
.
getReference
()
in
destroyed_partition_id_list
\
and
partition
.
getSlapState
()
==
'free'
:
free_partition_id_list
.
append
(
partition
.
getReference
())
self
.
assertSameSet
(
destroyed_partition_id_list
,
free_partition_id_list
)
def
simulateSlapgridCP
(
self
,
compute_node
):
sm
=
getSecurityManager
()
compute_node_reference
=
compute_node
.
getReference
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
computer_id
=
compute_node
.
getReference
())
if
not
isinstance
(
compute_node_xml
,
str
):
compute_node_xml
=
compute_node_xml
.
getBody
()
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
for
partition
in
slap_compute_node
.
_computer_partition_list
:
if
partition
.
_requested_state
in
(
'started'
,
'stopped'
)
\
and
partition
.
_need_modification
==
1
:
instance_reference
=
partition
.
_instance_guid
.
encode
(
'UTF-8'
)
ip_list
=
partition
.
_parameter_dict
[
'ip_list'
]
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
dict
(
url_1
=
'http://%s/'
%
ip_list
[
0
][
1
],
url_2
=
'http://%s/'
%
ip_list
[
1
][
1
],
))
self
.
login
()
instance_user_id
=
self
.
portal
.
portal_catalog
.
getResultValue
(
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
oldsm
=
getSecurityManager
()
try
:
self
.
login
(
instance_user_id
)
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
computer_id
=
compute_node_reference
,
computer_partition_id
=
partition
.
_partition_id
,
connection_xml
=
connection_xml
)
for
slave
in
partition
.
_parameter_dict
[
'slave_instance_list'
]:
slave_reference
=
slave
[
'slave_reference'
]
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
dict
(
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
slave_reference
),
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
slave_reference
)
))
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
computer_id
=
compute_node_reference
,
computer_partition_id
=
partition
.
_partition_id
,
connection_xml
=
connection_xml
,
slave_reference
=
slave_reference
)
finally
:
setSecurityManager
(
oldsm
)
finally
:
setSecurityManager
(
sm
)
self
.
tic
()
def
requestParameterBackwardCompatibility
(
self
,
request_dict
):
request_dict
[
"partition_reference"
]
=
request_dict
.
pop
(
"title"
)
if
"software_release_uri"
in
request_dict
:
request_dict
[
"software_release"
]
=
request_dict
.
pop
(
"software_release_uri"
)
if
"shared"
in
request_dict
:
shared
=
request_dict
.
pop
(
"shared"
)
if
shared
:
request_dict
[
"shared_xml"
]
=
'<marshal><bool>1</bool></marshal>'
if
"state"
in
request_dict
:
request_dict
[
"state"
]
=
"<marshal><string>%s</string></marshal>"
%
request_dict
[
"state"
]
return
request_dict
def
personRequestInstanceNotReady
(
self
,
**
kw
):
response
=
self
.
portal
.
portal_slap
.
requestComputerPartition
(
**
self
.
requestParameterBackwardCompatibility
(
kw
))
status
=
getattr
(
response
,
'status'
,
None
)
self
.
assertEqual
(
408
,
status
)
self
.
tic
()
def
personRequestInstance
(
self
,
**
kw
):
response
=
self
.
portal
.
portal_slap
.
requestComputerPartition
(
**
self
.
requestParameterBackwardCompatibility
(
kw
))
self
.
assertTrue
(
isinstance
(
response
,
str
),
"response is not a string: %s"
%
response
)
software_instance
=
xml_marshaller
.
xml_marshaller
.
loads
(
response
)
self
.
assertEqual
(
'SoftwareInstance'
,
software_instance
.
__class__
.
__name__
)
self
.
tic
()
return
software_instance
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.testSlapOSERP5DefaultScenario.py
View file @
1f1e19eb
...
...
@@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from
erp5.component.test.SlapOSTestCaseDefaultScenarioMixin
import
DefaultScenarioMixin
from
erp5.component.test.SlapOSTestCaseDefaultScenarioMixin
import
DefaultScenarioMixin
,
DefaultScenarioMixinSlapTool
from
DateTime
import
DateTime
import
re
...
...
@@ -771,3 +771,6 @@ class TestSlapOSDefaultCRMEscalation(DefaultScenarioMixin):
# check final document state
self
.
assertPersonDocumentCoverage
(
person
)
class
TestSlapOSDefaultScenarioSlapTool
(
TestSlapOSDefaultScenario
,
DefaultScenarioMixinSlapTool
):
pass
\ No newline at end of file
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