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
1d03e221
Commit
1d03e221
authored
Apr 07, 2023
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_jio_ui_test: Move Slapgrid simulator to jIO API
parent
6b879110
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
66 deletions
+88
-66
master/bt5/slapos_jio_ui_test/ExtensionTemplateItem/portal_components/extension.erp5.SlapOSUiTest.py
...lateItem/portal_components/extension.erp5.SlapOSUiTest.py
+88
-66
No files found.
master/bt5/slapos_jio_ui_test/ExtensionTemplateItem/portal_components/extension.erp5.SlapOSUiTest.py
View file @
1d03e221
...
@@ -3,13 +3,19 @@ from Products.ERP5Type.tests.utils import DummyMailHostMixin,\
...
@@ -3,13 +3,19 @@ from Products.ERP5Type.tests.utils import DummyMailHostMixin,\
createZODBPythonScript
createZODBPythonScript
from
Products.ERP5Security
import
SUPER_USER
from
Products.ERP5Security
import
SUPER_USER
from
erp5.component.test.testSlapOSJIOAPI
import
json_loads_byteified
from
AccessControl.SecurityManagement
import
getSecurityManager
from
AccessControl.SecurityManagement
import
getSecurityManager
from
AccessControl.SecurityManagement
import
setSecurityManager
from
AccessControl.SecurityManagement
import
setSecurityManager
from
AccessControl.SecurityManagement
import
newSecurityManager
from
AccessControl.SecurityManagement
import
newSecurityManager
import
xml_marshaller
import
json
def
callJioApi
(
action
,
portal
,
data_dict
):
portal
.
REQUEST
.
set
(
"live_test"
,
True
)
portal
.
REQUEST
.
set
(
"BODY"
,
json
.
dumps
(
data_dict
))
return
json_loads_byteified
(
getattr
(
portal
.
web_site_module
.
hostingjs
.
api
,
action
)()
)
def
ComputeNode_simulateSlapgridInstance
(
self
,
instance_connection_dict
=
None
,
def
ComputeNode_simulateSlapgridInstance
(
self
,
instance_connection_dict
=
None
,
slave_connection_dict
=
None
):
slave_connection_dict
=
None
):
...
@@ -21,54 +27,53 @@ def ComputeNode_simulateSlapgridInstance(self, instance_connection_dict=None,
...
@@ -21,54 +27,53 @@ def ComputeNode_simulateSlapgridInstance(self, instance_connection_dict=None,
instance_connection_dict
=
{}
instance_connection_dict
=
{}
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
compute_node_reference
=
self
.
getReference
()
compute_node_user_id
=
self
.
getUserId
()
compute_node_user_id
=
self
.
getUserId
()
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
try
:
try
:
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
compute_node_user_id
))
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
compute_node_user_id
))
compute_node_xml
=
portal
.
portal_slap
.
getFullComputerInformation
(
instance_list
=
callJioApi
(
'allDocs'
,
portal
,
{
computer_id
=
self
.
getReference
())
"portal_type"
:
"Software Instance"
,
"compute_node_id"
:
self
.
getReference
()
})[
"result_list"
]
if
not
isinstance
(
compute_node_xml
,
str
):
for
partition
in
instance_list
:
compute_node_xml
=
compute_node_xml
.
getBody
()
if
partition
[
"state"
]
in
(
'started'
,
'stopped'
):
partition
=
callJioApi
(
'get'
,
portal
,
{
slap_compute_node
=
xml_marshaller
.
xml_marshaller
.
loads
(
compute_node_xml
)
"portal_type"
:
"Software Instance"
,
assert
'Computer'
==
slap_compute_node
.
__class__
.
__name__
"reference"
:
partition
[
"reference"
],
})
for
partition
in
slap_compute_node
.
_computer_partition_list
:
instance_reference
=
partition
[
"reference"
]
if
partition
.
_requested_state
in
(
'started'
,
'stopped'
)
\
ip_list
=
partition
[
'ip_list'
]
and
partition
.
_need_modification
==
1
:
instance_reference
=
partition
.
_instance_guid
.
encode
(
'UTF-8'
)
ip_list
=
partition
.
_parameter_dict
[
'ip_list'
]
instance_connection_dict
.
update
(
dict
(
instance_connection_dict
.
update
(
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
],
))
))
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
instance_connection_dict
)
callJioApi
(
"put"
,
portal
,
{
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
"portal_type"
:
"Software Instance"
,
computer_id
=
compute_node_reference
,
"reference"
:
partition
[
"reference"
],
computer_partition_id
=
partition
.
_partition_id
,
"connection_parameters"
:
instance_connection_dict
,
connection_xml
=
connection_xml
})
)
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
instance_user_id
=
portal
.
portal_catalog
.
getResultValue
(
instance_user_id
=
portal
.
portal_catalog
.
getResultValue
(
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
reference
=
instance_reference
,
portal_type
=
"Software Instance"
).
getUserId
()
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
instance_user_id
))
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
instance_user_id
))
for
slave
in
partition
.
_parameter_dict
[
'slave_instance_list'
]:
hosted_instance_list
=
callJioApi
(
"allDocs"
,
portal
,
{
slave_reference
=
slave
[
'slave_reference'
]
"portal_type"
:
"Shared Instance"
,
"host_instance_reference"
:
partition
[
"reference"
],
slave_connection_dict
.
update
(
dict
(
"state"
:
"started"
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
slave_reference
),
})[
"result_list"
]
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
slave_reference
)
for
hosted_instance
in
hosted_instance_list
:
))
hosted_reference
=
hosted_instance
[
'reference'
]
connection_xml
=
xml_marshaller
.
xml_marshaller
.
dumps
(
slave_connection_dict
)
slave_connection_dict
.
update
(
dict
(
self
.
portal
.
portal_slap
.
setComputerPartitionConnectionXml
(
url_1
=
'http://%s/%s'
%
(
ip_list
[
0
][
1
],
hosted_reference
),
computer_id
=
compute_node_reference
,
url_2
=
'http://%s/%s'
%
(
ip_list
[
1
][
1
],
hosted_reference
)
computer_partition_id
=
partition
.
_partition_id
,
))
connection_xml
=
connection_xml
,
callJioApi
(
"allDocs"
,
portal
,
{
slave_reference
=
slave_reference
"portal_type"
:
"Software Instance"
,
)
"reference"
:
hosted_reference
,
"connection_parameters"
:
slave_connection_dict
,
})
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
...
@@ -79,54 +84,71 @@ def ComputeNode_simulateSlapgridSoftware(self):
...
@@ -79,54 +84,71 @@ def ComputeNode_simulateSlapgridSoftware(self):
compute_node_user_id
=
self
.
getUserId
()
compute_node_user_id
=
self
.
getUserId
()
try
:
try
:
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
compute_node_user_id
))
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
compute_node_user_id
))
compute_node_xml
=
portal
.
portal_slap
.
getFullComputerInformation
(
software_release_list
=
callJioApi
(
"allDocs"
,
portal
,
{
computer_id
=
self
.
getReference
())
"portal_type"
:
"Software Installation"
,
if
not
isinstance
(
compute_node_xml
,
str
):
"compute_node_id"
:
self
.
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
:
assert
'Computer'
==
slap_compute_node
.
__class__
.
__name__
if
software_release
[
"state"
]
==
'destroyed'
:
for
software_release
in
slap_compute_node
.
_software_release_list
:
callJioApi
(
"put"
,
portal
,
{
if
software_release
.
_requested_state
==
'destroyed'
:
"portal_type"
:
"Software Installation"
,
portal
.
portal_slap
.
destroyedSoftwareRelease
(
"compute_noode_id"
:
self
.
getReference
(),
software_release
.
_software_release
,
"software_release_uri"
:
software_release
[
"software_release_uri"
],
self
.
getReference
())
"reported_state"
:
"destroyed"
,
})
else
:
else
:
portal
.
portal_slap
.
availableSoftwareRelease
(
callJioApi
(
"put"
,
portal
,
{
software_release
.
_software_release
,
"portal_type"
:
"Software Installation"
,
self
.
getReference
())
"compute_noode_id"
:
self
.
getReference
(),
"software_release_uri"
:
software_release
[
"software_release_uri"
],
"reported_state"
:
"available"
,
})
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
def
ComputeNode_simulateSlapgridFormat
(
self
,
partition_count
=
10
):
def
ComputeNode_simulateSlapgridFormat
(
self
,
partition_count
=
10
):
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
compute_node_dict
=
dict
(
compute_node_dict
=
dict
(
software_root
=
'/opt'
,
compute_node_id
=
self
.
getReference
(),
reference
=
self
.
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
:
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
self
.
getUserId
()))
newSecurityManager
(
None
,
portal
.
acl_users
.
getUserById
(
self
.
getUserId
()))
return
portal
.
portal_slap
.
loadComputerConfigurationFromXML
(
return
callJioApi
(
"put"
,
portal
,
compute_node_dict
)
xml_marshaller
.
xml_marshaller
.
dumps
(
compute_node_dict
))
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
def
restoreDummyMailHost
(
self
):
def
restoreDummyMailHost
(
self
):
"""Restore the replacement of Original Mail Host by Dummy Mail Host.
"""Restore the replacement of Original Mail Host by Dummy Mail Host.
...
...
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