Commit 7042f890 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio_ui_test: Add utility script to simulate slapgrid (instance and format)

This is helpfull to configure configure computers to simulate connection parameters and allocation.
parent affcc2d9
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
import xml_marshaller
def Computer_simulateSlapgridCP(self, instance_connection_dict=None,
slave_connection_dict=None):
if slave_connection_dict is None:
slave_connection_dict = {}
if instance_connection_dict is None:
instance_connection_dict = {}
sm = getSecurityManager()
computer_reference = self.getReference()
computer_user_id = self.getUserId()
portal = self.getPortalObject()
try:
newSecurityManager(None, portal.acl_users.getUserById(computer_user_id))
computer_xml = portal.portal_slap.getFullComputerInformation(
computer_id=self.getReference())
if not isinstance(computer_xml, str):
computer_xml = computer_xml.getBody()
slap_computer = xml_marshaller.xml_marshaller.loads(computer_xml)
assert 'Computer' == slap_computer.__class__.__name__
for partition in slap_computer._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']
instance_connection_dict.update(dict(
url_1 = 'http://%s/' % ip_list[0][1],
url_2 = 'http://%s/' % ip_list[1][1],
))
connection_xml = xml_marshaller.xml_marshaller.dumps(instance_connection_dict)
portal.portal_slap.setComputerPartitionConnectionXml(
computer_id=computer_reference,
computer_partition_id=partition._partition_id,
connection_xml=connection_xml
)
setSecurityManager(sm)
instance_user_id = portal.portal_catalog.getResultValue(
reference=instance_reference, portal_type="Software Instance").getUserId()
newSecurityManager(None, portal.acl_users.getUserById(instance_user_id))
for slave in partition._parameter_dict['slave_instance_list']:
slave_reference = slave['slave_reference']
slave_connection_dict.update(dict(
url_1 = 'http://%s/%s' % (ip_list[0][1], slave_reference),
url_2 = 'http://%s/%s' % (ip_list[1][1], slave_reference)
))
connection_xml = xml_marshaller.xml_marshaller.dumps(slave_connection_dict)
self.portal.portal_slap.setComputerPartitionConnectionXml(
computer_id=computer_reference,
computer_partition_id=partition._partition_id,
connection_xml=connection_xml,
slave_reference=slave_reference
)
finally:
setSecurityManager(sm)
def Computer_simulateSlapgridFormat(self, partition_count=10):
portal = self.getPortalObject()
computer_dict = dict(
software_root='/opt',
reference=self.getReference(),
netmask='255.255.255.0',
address='128.0.0.1',
instance_root='/srv'
)
computer_dict['partition_list'] = []
a = computer_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:
newSecurityManager(None, portal.acl_users.getUserById(self.getUserId()))
return portal.portal_slap.loadComputerConfigurationFromXML(
xml_marshaller.xml_marshaller.dumps(computer_dict))
finally:
setSecurityManager(sm)
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Extension Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>SlapOSUiTest</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>extension.erp5.SlapOSUiTest</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Extension Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
<none/>
</tuple>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Computer_simulateSlapgridCP</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>SlapOSUiTest</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_simulateSlapgridCP</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>Computer_simulateSlapgridFormat</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>SlapOSUiTest</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_simulateSlapgridFormat</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
extension.erp5.SlapOSUiTest
\ No newline at end of file
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