Commit c8419ac2 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud:

* allocate slave on instance from the same instance tree
* method to request and allocate slave instance from an instance tree
parent 4266e82b
......@@ -3,6 +3,7 @@
<item>SlapOSMasterUpgradeConstraint</item>
</portal_type>
<portal_type id="Allocation Supply">
<item>AllocationSupply</item>
<item>SlapOSVirtualMasterSourceProjectConstraint</item>
</portal_type>
<portal_type id="Allocation Supply Cell">
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AllocationSupply</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>mode</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/boolean</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slave_on_same_instance_tree_allocable_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
<value> <string>w</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -65,7 +65,10 @@
<item>
<key> <string>center</string> </key>
<value>
<list/>
<list>
<string>my_aggregate_title_list</string>
<string>my_slave_on_same_instance_tree_allocable</string>
</list>
</value>
</item>
<item>
......@@ -88,7 +91,6 @@
<key> <string>right</string> </key>
<value>
<list>
<string>my_aggregate_title_list</string>
<string>my_destination_project_title</string>
<string>my_destination_title</string>
<string>my_translated_validation_state_title</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_slave_on_same_instance_tree_allocable</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_checkbox</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Allocate Slave On Same Instance Tree</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -13,11 +13,9 @@ query_kw = {
}
if software_instance_portal_type == "Slave Instance":
query_kw['free_for_request'] = 0
compute_node_portal_type = 'Instance Node'
elif software_instance_portal_type == "Software Instance":
query_kw['free_for_request'] = 1
query_kw['software_release_url'] = software_release_url
compute_node_portal_type = 'Compute Node'
else:
raise NotImplementedError("Unknown portal type %s"%
software_instance_portal_type)
......@@ -50,17 +48,28 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr
if not allocation_cell_list:
raise ValueError('No Allocation Supply allowing this operation')
# Only partition with Instances from the same Instance Tree
instance_tree_partition_value_list = [sql_obj.getAggregateValue() \
for sql_obj in context.getPortalObject().portal_catalog(
portal_type=['Software Instance'],
specialise__uid=instance_tree.getUid(),
) if ((sql_obj.getAggregateValue() is not None) and (sql_obj.getUrlString() == software_release_url) and (sql_obj.getSourceReference() == software_type))
]
# Get the list of allowed Compute Node, Instance Node
compute_node_list_list = [x.getParentValue().getParentValue().getAggregateValueList(portal_type=compute_node_portal_type) for x in allocation_cell_list]
compute_node_list_list = [(x.getParentValue().getParentValue().getAggregateValueList(), x.getParentValue().getParentValue().isSlaveOnSameInstanceTreeAllocable()) for x in allocation_cell_list]
parent_uid_list = []
partition_uid_list = []
for compute_node_list in compute_node_list_list:
for compute_node_list, is_slave_on_same_instance_tree_allocable in compute_node_list_list:
for compute_node in compute_node_list:
if compute_node.getPortalType() == 'Compute Node':
parent_uid_list.append(compute_node.getUid())
if is_slave_on_same_instance_tree_allocable:
partition_uid_list.extend([x.getUid() for x in instance_tree_partition_value_list if (x.getParentValue().getUid() == compute_node.getUid())])
elif compute_node.getPortalType() == 'Instance Node':
shared_instance = compute_node.getSpecialiseValue(portal_type='Software Instance')
if shared_instance is not None:
if (shared_instance is not None):
# No need to search for original software type/url
#query_kw['software_release_url'] = software_release_url
#query_kw['software_type'] = software_type
......@@ -69,6 +78,7 @@ for compute_node_list in compute_node_list_list:
partition_uid_list.append(shared_partition.getUid())
else:
raise NotImplementedError('Unsupported Node type: %s' % compute_node.getPortalType())
if len(parent_uid_list) == 0:
# Ensure nothing will be found
parent_uid_list.append(-1)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>project_uid, software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, subscription_reference=None, is_root_slave=False, test_mode=False</string> </value>
<value> <string>instance_tree, project_uid, software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, subscription_reference=None, test_mode=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -120,13 +120,13 @@ def assignComputePartition(software_instance, instance_tree):
subscription_reference, instance_tree.isRootSlave()])
"""
compute_partition_relative_url = person.Person_findPartition(
instance_tree,
software_instance.getFollowUpUid(portal_type='Project'),
software_instance.getUrlString(),
software_instance.getSourceReference(),
software_instance.getPortalType(),
sla_dict, computer_network_query,
subscription_reference,
instance_tree.isRootSlave()
subscription_reference
)
return compute_partition_relative_url, tag
......
......@@ -417,6 +417,66 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
portal_type='Internet Protocol Address')],
connection_dict.values())
def checkInstanceTreeSlaveInstanceAllocation(
self,
person_user_id,
person_reference,
instance_tree_title, instance_title, software_release, software_type,
server,
project_reference
):
self.login(person_user_id)
# let's find instance of user
instance_tree_list = [q.getObject() for q in
self._getCurrentInstanceTreeList()
if q.getTitle() == instance_tree_title]
self.assertEqual(1, len(instance_tree_list))
instance_tree = instance_tree_list[0]
software_instance = instance_tree.getSuccessorValue()
self.login()
instance_user_id = software_instance.getUserId()
compute_partition = software_instance.getAggregateValue()
computer_id = compute_partition.getParentValue().getReference()
computer_partition_id = compute_partition.getTitle()
self.login(instance_user_id)
response = self.portal.portal_slap.requestComputerPartition(
computer_id=computer_id,
computer_partition_id=computer_partition_id,
software_release=software_release,
software_type=software_type,
partition_reference=instance_title,
shared_xml='<marshal><bool>2</bool></marshal>',
project_reference=project_reference
)
status = getattr(response, 'status', None)
self.assertEqual(408, status)
self.tic()
self.stepCallSlaposAllocateInstanceAlarm()
self.tic()
# now instantiate it on compute_node and set some nice connection dict
self.simulateSlapgridCP(server)
# let's find instances of user and check connection strings
slave_instance = software_instance.getSuccessorValue()
connection_dict = slave_instance.getConnectionXmlAsDict()
self.assertSameSet(('url_1', 'url_2'), connection_dict.keys())
self.login()
partition = slave_instance.getAggregateValue()
self.assertSameSet(
['http://%s/%s' % (q.getIpAddress(), slave_instance.getReference())
for q in partition.contentValues(
portal_type='Internet Protocol Address')],
connection_dict.values())
def checkSlaveInstanceUnallocation(self, person_user_id,
person_reference, instance_title,
software_release, software_type, server,
......
Alarm Tool | SlapOSMasterUpgradeConstraint
Allocation Supply Cell | AllocationSupplyPath
Allocation Supply Line | AllocationSupplyPath
Allocation Supply | AllocationSupply
Allocation Supply | SlapOSVirtualMasterSourceProjectConstraint
Assignment | SlaposAssignmentConstraint
Compute Node | ComputeNodeSlapOSMetadata
......
......@@ -21,4 +21,5 @@ ComputeNodeSlapOSMetadata
SlapOSReferenceConstraint
SlapOSVirtualMasterConstraint
SlapOSVirtualMasterSourceProjectConstraint
AllocationSupplyPath
\ No newline at end of file
AllocationSupplyPath
AllocationSupply
\ 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