Commit 1d03e221 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

slapos_jio_ui_test: Move Slapgrid simulator to jIO API

parent 6b879110
...@@ -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()
if not isinstance(compute_node_xml, str): })["result_list"]
compute_node_xml = compute_node_xml.getBody()
for partition in instance_list:
slap_compute_node = xml_marshaller.xml_marshaller.loads(compute_node_xml) if partition["state"] in ('started', 'stopped'):
assert 'Computer' == slap_compute_node.__class__.__name__ partition = callJioApi('get', portal, {
"portal_type": "Software Instance",
for partition in slap_compute_node._computer_partition_list: "reference": partition["reference"],
if partition._requested_state in ('started', 'stopped') \ })
and partition._need_modification == 1: instance_reference = partition["reference"]
instance_reference = partition._instance_guid.encode('UTF-8') ip_list = partition['ip_list']
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"],
"state": "started"
})["result_list"]
for hosted_instance in hosted_instance_list:
hosted_reference = hosted_instance['reference']
slave_connection_dict.update(dict( slave_connection_dict.update(dict(
url_1 = 'http://%s/%s' % (ip_list[0][1], slave_reference), url_1 = 'http://%s/%s' % (ip_list[0][1], hosted_reference),
url_2 = 'http://%s/%s' % (ip_list[1][1], slave_reference) url_2 = 'http://%s/%s' % (ip_list[1][1], hosted_reference)
)) ))
connection_xml = xml_marshaller.xml_marshaller.dumps(slave_connection_dict) callJioApi("allDocs", portal, {
self.portal.portal_slap.setComputerPartitionConnectionXml( "portal_type": "Software Instance",
computer_id=compute_node_reference, "reference": hosted_reference,
computer_partition_id=partition._partition_id, "connection_parameters": slave_connection_dict,
connection_xml=connection_xml, })
slave_reference=slave_reference
)
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment