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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
22e943c0
Commit
22e943c0
authored
Apr 06, 2023
by
Cédric Le Ninivin
Committed by
Romain Courteaud
Nov 18, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_erp5: Move Default Scenario Test to jIO API
parent
8394f707
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
348 additions
and
95 deletions
+348
-95
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
...omponents/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
+348
-95
No files found.
master/bt5/slapos_erp5/TestTemplateItem/portal_components/test.erp5.SlapOSTestCaseDefaultScenarioMixin.py
View file @
22e943c0
...
@@ -22,13 +22,14 @@
...
@@ -22,13 +22,14 @@
import
six
import
six
import
six.moves.urllib.parse
import
six.moves.urllib.parse
from
erp5.component.test.testSlapOSCloudSecurityGroup
import
TestSlapOSSecurityMixin
from
erp5.component.test.testSlapOSCloudSecurityGroup
import
TestSlapOSSecurityMixin
from
erp5.component.test.testSlapOSJIOAPI
import
TestSlapOSJIOAPIMixin
from
erp5.component.test.SlapOSTestCaseMixin
import
changeSkin
from
erp5.component.test.SlapOSTestCaseMixin
import
changeSkin
import
re
import
re
import
xml_marshaller
import
xml_marshaller
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
from
AccessControl.SecurityManagement
import
getSecurityManager
,
\
setSecurityManager
setSecurityManager
class
DefaultScenarioMixin
(
TestSlapOSSecurityMixin
):
class
DefaultScenarioMixin
(
TestSlapOSSecurityMixin
,
TestSlapOSJIOAPIMixin
):
def
afterSetUp
(
self
):
def
afterSetUp
(
self
):
TestSlapOSSecurityMixin
.
afterSetUp
(
self
)
TestSlapOSSecurityMixin
.
afterSetUp
(
self
)
...
@@ -41,6 +42,9 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -41,6 +42,9 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
)
)
"""
"""
self.web_site = self.portal.web_site_module.hostingjs
self.callUpdateRevision()
# Enable alarms for regularisation request
# Enable alarms for regularisation request
self.portal.portal_alarms.slapos_crm_create_regularisation_request.setEnabled(True)
self.portal.portal_alarms.slapos_crm_create_regularisation_request.setEnabled(True)
self.portal.portal_alarms.slapos_crm_invalidate_suspended_regularisation_request.setEnabled(True)
self.portal.portal_alarms.slapos_crm_invalidate_suspended_regularisation_request.setEnabled(True)
...
@@ -48,7 +52,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -48,7 +52,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self.portal.portal_alarms.slapos_crm_trigger_stop_acknowledgment_escalation.setEnabled(True)
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_delete_reminder_escalation.setEnabled(True)
self.portal.portal_alarms.slapos_crm_trigger_acknowledgment_escalation.setEnabled(True)
self.portal.portal_alarms.slapos_crm_trigger_acknowledgment_escalation.setEnabled(True)
"""
"""
# Create akarls steps
# Create akarls steps
self
.
createAlarmStep
()
self
.
createAlarmStep
()
...
@@ -168,18 +172,24 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -168,18 +172,24 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
agent
.
setAccessStatus
(
"#access "
)
agent
.
setAccessStatus
(
"#access "
)
def
requestComputeNode
(
self
,
title
,
project_reference
):
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
.
tic
()
self
.
assertIn
(
'marshal'
,
requestXml
)
self
.
callUpdateRevisionAndTic
()
compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
requestXml
)
return
request_data
[
"compute_node_id"
]
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'
):
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
.
tic
()
self
.
c
leanUpRequest
()
self
.
c
allUpdateRevisionAndTic
()
software_installation
=
self
.
portal
.
portal_catalog
.
getResultValue
(
software_installation
=
self
.
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Software Installation'
,
portal_type
=
'Software Installation'
,
...
@@ -204,28 +214,43 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -204,28 +214,43 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
def
formatComputeNode
(
self
,
compute_node
,
partition_count
=
10
):
def
formatComputeNode
(
self
,
compute_node
,
partition_count
=
10
):
compute_node_dict
=
dict
(
compute_node_dict
=
dict
(
software_root
=
'/opt'
,
compute_node_id
=
compute_node
.
getReference
(),
reference
=
compute_node
.
getReference
(),
portal_type
=
"Compute Node"
,
netmask
=
'255.255.255.0'
,
address
=
'128.0.0.1'
,
instance_root
=
'/srv'
)
)
compute_node_dict
[
'partition_list'
]
=
[]
compute_node_dict
[
'
compute_
partition_list'
]
=
[]
a
=
compute_node_dict
[
'partition_list'
].
append
a
=
compute_node_dict
[
'
compute_
partition_list'
].
append
for
i
in
range
(
1
,
partition_count
+
1
):
for
i
in
range
(
1
,
partition_count
+
1
):
a
(
dict
(
a
(
dict
(
reference
=
'part%s'
%
i
,
partition_id
=
'part%s'
%
i
,
tap
=
dict
(
name
=
'tap%s'
%
i
),
ip_list
=
[
address_list
=
[
{
dict
(
addr
=
'p%sa1'
%
i
,
netmask
=
'p%sn1'
%
i
),
"ip-address"
:
'p%sa1'
%
i
,
dict
(
addr
=
'p%sa2'
%
i
,
netmask
=
'p%sn2'
%
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
()
sm
=
getSecurityManager
()
try
:
try
:
self
.
login
(
compute_node
.
getUserId
())
self
.
login
(
compute_node
.
getUserId
())
self
.
portal
.
portal_slap
.
loadComputerConfigurationFromXML
(
self
.
putToApi
(
compute_node_dict
)
xml_marshaller
.
xml_marshaller
.
dumps
(
compute_node_dict
))
self
.
tic
()
self
.
tic
()
self
.
assertEqual
(
partition_count
,
self
.
assertEqual
(
partition_count
,
len
(
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
)))
len
(
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
)))
...
@@ -237,21 +262,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -237,21 +262,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
compute_node_user_id
=
compute_node
.
getUserId
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
try
:
self
.
login
(
compute_node_user_id
)
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
software_release_list
=
self
.
allDocsToApi
({
computer_id
=
compute_node
.
getReference
())
"portal_type"
:
"Software Installation"
,
if
not
isinstance
(
compute_node_xml
,
str
):
"compute_node_id"
:
compute_node
.
getReference
()
compute_node_xml
=
compute_node_xml
.
getBody
()
})[
"result_list"
]
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
for
software_release
in
software_release_list
:
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
if
software_release
[
"state"
]
==
'destroyed'
:
for
software_release
in
slap_compute_node
.
_software_release_list
:
self
.
putToApi
({
if
software_release
.
_requested_state
==
'destroyed'
:
"portal_type"
:
"Software Installation"
,
self
.
portal
.
portal_slap
.
destroyedSoftwareRelease
(
"compute_noode_id"
:
compute_node
.
getReference
(),
software_release
.
_software_release
,
"software_release_uri"
:
software_release
[
"software_release_uri"
],
compute_node
.
getReference
())
"reported_state"
:
"destroyed"
,
})
else
:
else
:
self
.
portal
.
portal_slap
.
availableSoftwareRelease
(
self
.
putToApi
({
software_release
.
_software_release
,
"portal_type"
:
"Software Installation"
,
compute_node
.
getReference
())
"compute_noode_id"
:
compute_node
.
getReference
(),
"software_release_uri"
:
software_release
[
"software_release_uri"
],
"reported_state"
:
"available"
,
})
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
self
.
tic
()
self
.
tic
()
...
@@ -260,24 +289,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -260,24 +289,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
compute_node_user_id
=
compute_node
.
getUserId
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
try
:
self
.
callUpdateRevisionAndTic
()
self
.
login
(
compute_node_user_id
)
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
instance_list
=
self
.
allDocsToApi
({
computer_id
=
compute_node
.
getReference
())
"portal_type"
:
"Software Instance"
,
if
not
isinstance
(
compute_node_xml
,
str
):
"compute_node_id"
:
compute_node
.
getReference
()
compute_node_xml
=
compute_node_xml
.
getBody
()
})[
"result_list"
]
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
destroyed_partition_id_list
=
[]
destroyed_partition_id_list
=
[]
for
partition
in
slap_compute_node
.
_computer_partition_list
:
for
partition
in
instance_list
:
if
partition
.
_requested_state
==
'destroyed'
\
if
partition
[
"state"
]
==
'destroyed'
:
and
partition
.
_need_modification
==
1
:
self
.
putToApi
({
self
.
portal
.
portal_slap
.
destroyedComputerPartition
(
compute_node
.
getReference
(),
"portal_type"
:
"Software Instance"
,
partition
.
_partition_id
.
encode
(
"UTF-8"
)
"reference"
:
partition
[
"reference"
],
)
"reported_state"
:
"destroyed"
destroyed_partition_id_list
.
append
(
partition
.
_partition_id
.
encode
(
"UTF-8"
))
})
destroyed_partition_id_list
.
append
(
partition
[
"compute_partition_id"
])
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
self
.
tic
()
self
.
tic
()
self
.
stepCallSlaposFreeComputePartitionAlarm
()
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
free_partition_id_list
=
[]
free_partition_id_list
=
[]
for
partition
in
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
):
for
partition
in
compute_node
.
contentValues
(
portal_type
=
'Compute Partition'
):
if
partition
.
getReference
()
in
destroyed_partition_id_list
\
if
partition
.
getReference
()
in
destroyed_partition_id_list
\
...
@@ -287,25 +319,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -287,25 +319,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
def
simulateSlapgridCP
(
self
,
compute_node
):
def
simulateSlapgridCP
(
self
,
compute_node
):
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
compute_node_reference
=
compute_node
.
getReference
()
compute_node_user_id
=
compute_node
.
getUserId
()
compute_node_user_id
=
compute_node
.
getUserId
()
try
:
try
:
self
.
login
(
compute_node_user_id
)
self
.
login
(
compute_node_user_id
)
compute_node_xml
=
self
.
portal
.
portal_slap
.
getFullComputerInformation
(
instance_list
=
self
.
allDocsToApi
({
computer_id
=
compute_node
.
getReference
())
"portal_type"
:
"Software Instance"
,
if
not
isinstance
(
compute_node_xml
,
str
):
"compute_node_id"
:
compute_node
.
getReference
()
compute_node_xml
=
compute_node_xml
.
getBody
()
})[
"result_list"
]
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
for
partition
in
instance_list
:
self
.
assertEqual
(
'Computer'
,
slap_compute_node
.
__class__
.
__name__
)
if
partition
[
"state"
]
in
(
'started'
,
'stopped'
):
for
partition
in
slap_compute_node
.
_computer_partition_list
:
partition
=
self
.
getToApi
({
if
partition
.
_requested_state
in
(
'started'
,
'stopped'
)
\
"portal_type"
:
"Software Instance"
,
and
partition
.
_need_modification
==
1
:
"reference"
:
partition
[
"reference"
],
instance_reference
=
partition
.
_instance_guid
.
encode
(
'UTF-8'
)
})
ip_list
=
partition
.
_parameter_dict
[
'ip_list'
]
instance_reference
=
partition
[
"reference"
]
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
dict
(
ip_list
=
partition
[
'ip_list'
]
connection_dict
=
dict
(
url_1
=
'http://%s/'
%
ip_list
[
0
][
1
],
url_1
=
'http://%s/'
%
ip_list
[
0
][
1
],
url_2
=
'http://%s/'
%
ip_list
[
1
][
1
],
url_2
=
'http://%s/'
%
ip_list
[
1
][
1
],
)
)
)
self
.
login
()
self
.
login
()
instance_user_id
=
self
.
portal
.
portal_catalog
.
getResultValue
(
instance_user_id
=
self
.
portal
.
portal_catalog
.
getResultValue
(
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
...
@@ -313,23 +345,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -313,23 +345,27 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
oldsm
=
getSecurityManager
()
oldsm
=
getSecurityManager
()
try
:
try
:
self
.
login
(
instance_user_id
)
self
.
login
(
instance_user_id
)
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
self
.
putToApi
({
computer_id
=
compute_node_reference
,
"portal_type"
:
"Software Instance"
,
computer_partition_id
=
partition
.
_partition_id
,
"reference"
:
partition
[
"reference"
],
connection_xml
=
connection_xml
"connection_parameters"
:
connection_dict
,
)
})
for
slave
in
partition
.
_parameter_dict
[
'slave_instance_list'
]:
hosted_instance_list
=
self
.
allDocsToApi
({
slave_reference
=
slave
[
'slave_reference'
]
"portal_type"
:
"Shared Instance"
,
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
dict
(
"host_instance_reference"
:
partition
[
"reference"
],
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
slave_reference
),
"state"
:
"started"
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
slave_reference
)
})[
"result_list"
]
))
for
hosted_instance
in
hosted_instance_list
:
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
hosted_reference
=
hosted_instance
[
'reference'
]
computer_id
=
compute_node_reference
,
connection_dict
=
dict
(
computer_partition_id
=
partition
.
_partition_id
,
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
hosted_reference
),
connection_xml
=
connection_xml
,
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
hosted_reference
)
slave_reference
=
slave_reference
)
)
self
.
putToApi
({
"portal_type"
:
"Software Instance"
,
"reference"
:
hosted_reference
,
"connection_parameters"
:
connection_dict
,
})
finally
:
finally
:
setSecurityManager
(
oldsm
)
setSecurityManager
(
oldsm
)
...
@@ -338,16 +374,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -338,16 +374,25 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
tic
()
self
.
tic
()
def
personRequestInstanceNotReady
(
self
,
**
kw
):
def
personRequestInstanceNotReady
(
self
,
**
kw
):
response
=
self
.
portal
.
portal_slap
.
requestComputerPartition
(
**
kw
)
kw
[
"portal_type"
]
=
"Software Instance"
status
=
getattr
(
response
,
'status'
,
None
)
response
=
self
.
postToApi
(
kw
)
self
.
assertEqual
(
408
,
status
)
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
()
self
.
tic
()
def
personRequestInstance
(
self
,
**
kw
):
def
personRequestInstance
(
self
,
**
kw
):
response
=
self
.
portal
.
portal_slap
.
requestComputerPartition
(
**
kw
)
kw
[
"portal_type"
]
=
"Software Instance"
self
.
assertTrue
(
isinstance
(
response
,
str
),
"response is not a string: %s"
%
response
)
software_instance
=
self
.
postToApi
(
kw
)
software_instance
=
xml_marshaller
.
xml_marshaller
.
loads
(
response
)
self
.
assertTrue
(
software_instance
.
get
(
"portal_type"
,
""
)
in
(
"Slave Instance"
,
"Software Instance"
))
self
.
assertEqual
(
'SoftwareInstance'
,
software_instance
.
__class__
.
__name__
)
self
.
tic
()
self
.
tic
()
return
software_instance
return
software_instance
...
@@ -358,11 +403,13 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -358,11 +403,13 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
tic
()
self
.
tic
()
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
project_reference
=
project_reference
project_reference
=
project_reference
title
=
instance_title
,
shared
=
True
)
)
# XXX search only for this user
# XXX search only for this user
...
@@ -373,14 +420,17 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -373,14 +420,17 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
)
)
self
.
checkServiceSubscriptionRequest
(
instance_tree
)
self
.
checkServiceSubscriptionRequest
(
instance_tree
)
self
.
tic
()
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstance
(
self
.
personRequestInstance
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
project_reference
=
project_reference
project_reference
=
project_reference
title
=
instance_title
,
shared
=
True
)
)
# now instantiate it on compute_node and set some nice connection dict
# now instantiate it on compute_node and set some nice connection dict
...
@@ -530,12 +580,15 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -530,12 +580,15 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
shared_xml
=
'<marshal><bool>1</bool></marshal>'
,
state
=
'<marshal><string>destroyed</string></marshal>'
,
state
=
'<marshal><string>destroyed</string></marshal>'
,
project_reference
=
project_reference
project_reference
=
project_reference
title
=
instance_title
,
shared
=
True
,
state
=
'destroyed'
,
)
)
# let's find instances of user and check connection strings
# let's find instances of user and check connection strings
...
@@ -572,11 +625,13 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -572,11 +625,13 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
state
=
'<marshal><string>destroyed</string></marshal>'
,
state
=
'<marshal><string>destroyed</string></marshal>'
,
project_reference
=
project_reference
project_reference
=
project_reference
title
=
instance_title
,
state
=
'destroyed'
)
)
# now instantiate it on compute_node and set some nice connection dict
# now instantiate it on compute_node and set some nice connection dict
...
@@ -607,12 +662,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -607,12 +662,14 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
project_reference
=
project_reference
project_reference
=
project_reference
title
=
instance_title
,
)
)
self
.
tic
()
self
.
tic
()
self
.
callUpdateRevisionAndTic
()
# XXX search only for this user
# XXX search only for this user
instance_tree
=
self
.
portal
.
portal_catalog
.
getResultValue
(
instance_tree
=
self
.
portal
.
portal_catalog
.
getResultValue
(
...
@@ -625,10 +682,11 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -625,10 +682,11 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstance
(
self
.
personRequestInstance
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
project_reference
=
project_reference
project_reference
=
project_reference
title
=
instance_title
,
)
)
# now instantiate it on compute_node and set some nice connection dict
# now instantiate it on compute_node and set some nice connection dict
...
@@ -767,8 +825,203 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
...
@@ -767,8 +825,203 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self
.
login
(
person_user_id
)
self
.
login
(
person_user_id
)
self
.
personRequestInstanceNotReady
(
self
.
personRequestInstanceNotReady
(
software_release
=
software_release
,
software_release
_uri
=
software_release
,
software_type
=
software_type
,
software_type
=
software_type
,
partition_reference
=
instance_title
,
partition_reference
=
instance_title
,
project_reference
=
project_reference
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
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