Commit f58dd784 authored by Romain Courteaud's avatar Romain Courteaud

slapos_*: check the Software Type Variation's capacity

This part was not following the new design.
Use the new Type variation document to define how much a instance consumes the compute node capacity.
parent 6ca56f45
......@@ -50,42 +50,13 @@ if can_allocate:
if compute_node_capacity_quantity != default_maximum_value:
compute_node.edit(capacity_quantity=compute_node_capacity_quantity)
software_release_capacity_dict = {}
consumed_capacity = 0
def getSoftwareReleaseCapacity(instance):
software_release_url = instance.getUrlString()
software_type = instance.getSourceReference()
if "%s-%s" % (software_release_url, software_type) in software_release_capacity_dict:
return software_release_capacity_dict["%s-%s" % (software_release_url, software_type)]
software_release = portal.portal_catalog.getResultValue(
portal_type='Software Release',
url_string={'query': software_release_url, 'key': 'ExactMatch'})
software_release_capacity = None
if software_release is not None:
# Search for Software Product Individual Variation with same reference
software_product = software_release.getAggregateValue()
if software_product is not None:
for variation in software_product.searchFolder(
portal_type="Software Product Individual Variation",
reference=software_type):
software_release_capacity = variation.getCapacityQuantity(None)
if software_release_capacity is not None:
break
if software_release_capacity is None:
software_release_capacity = software_product.getCapacityQuantity(None)
if software_release_capacity is None:
software_release_capacity = software_release.getCapacityQuantity(1)
if software_release_capacity is None:
software_release_capacity = 1
software_release_capacity_dict["%s-%s" % (software_release_url, software_type)] = software_release_capacity
return software_release_capacity
_, _, type_variation = instance.InstanceTree_getSoftwareProduct()
if type_variation is None:
return 1
return type_variation.getCapacityQuantity(1)
if allocated_instance is not None:
software_release_capacity = getSoftwareReleaseCapacity(allocated_instance)
......
......@@ -626,6 +626,20 @@ class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin):
self.assertEqual("Compute Node reported an error",
compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_ComputeNode_checkAndUpdateCapacityScope_script_softwareProductCapacity(self):
_, _, type_variation, compute_node, _, _ = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
compute_node.setAccessStatus("#access ok")
type_variation.setCapacityQuantity(9999999999999)
compute_node.log(type_variation)
self.tic()
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual('Compute Node capacity limit exceeded',
compute_node.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSGarbageCollectStoppedRootTreeAlarm(SlapOSTestCaseMixin):
#################################################################
......
......@@ -287,7 +287,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: \'\\n\'.join(sorted([x.getTitle() for x in here.contentValues(portal_type=\'Software Product Type Variation\')]))</string> </value>
<value> <string>python: \'\\n\'.join(sorted(["%s (%i)" % (x.getTitle(), x.getCapacityQuantity(1)) for x in here.contentValues(portal_type=\'Software Product Type Variation\')]))</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -104,6 +104,7 @@
<value>
<list>
<string>my_title</string>
<string>my_capacity_quantity</string>
</list>
</value>
</item>
......
<?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_capacity_quantity</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_integer_field</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>Capacity Consumption</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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