Commit 3e30e668 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: reduce number of accessed instances

parent f58dd784
...@@ -59,20 +59,24 @@ if can_allocate: ...@@ -59,20 +59,24 @@ if can_allocate:
return type_variation.getCapacityQuantity(1) return type_variation.getCapacityQuantity(1)
if allocated_instance is not None: if allocated_instance is not None:
software_release_capacity = getSoftwareReleaseCapacity(allocated_instance) consumed_capacity += getSoftwareReleaseCapacity(allocated_instance)
consumed_capacity += software_release_capacity
if consumed_capacity >= compute_node_capacity_quantity: if consumed_capacity >= compute_node_capacity_quantity:
can_allocate = False can_allocate = False
comment = 'Compute Node capacity limit exceeded (%s >= %s)' % (consumed_capacity, compute_node_capacity_quantity) comment = 'Compute Node capacity limit exceeded (%s >= %s)' % (consumed_capacity, compute_node_capacity_quantity)
if can_allocate: if can_allocate:
for instance in portal.portal_catalog.portal_catalog( for sql_instance in portal.portal_catalog.portal_catalog(
default_aggregate_relative_url='%s/%%' % compute_node.getRelativeUrl(), default_aggregate_relative_url='%s/%%' % compute_node.getRelativeUrl(),
portal_type=['Software Instance', 'Slave Instance'], portal_type=['Software Instance', 'Slave Instance'],
validation_state='validated'): validation_state='validated',
group_by=['url_string', 'source_reference'],
select_list=['COUNT(*)', 'url_string', 'source_reference']
):
software_release_capacity = getSoftwareReleaseCapacity(instance.getObject()) assert sql_instance.url_string == sql_instance.getUrlString()
consumed_capacity += software_release_capacity assert sql_instance.source_reference == sql_instance.getSourceReference()
assert 1 <= sql_instance['COUNT(*)']
consumed_capacity += getSoftwareReleaseCapacity(sql_instance) * sql_instance['COUNT(*)']
if consumed_capacity >= compute_node_capacity_quantity: if consumed_capacity >= compute_node_capacity_quantity:
can_allocate = False can_allocate = False
comment = 'Compute Node capacity limit exceeded' comment = 'Compute Node capacity limit exceeded'
......
...@@ -632,7 +632,47 @@ class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin): ...@@ -632,7 +632,47 @@ class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin):
compute_node.setAccessStatus("#access ok") compute_node.setAccessStatus("#access ok")
type_variation.setCapacityQuantity(9999999999999) 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'])
def test_ComputeNode_checkAndUpdateCapacityScope_script_softwareProductCapacityMultipleInstance(self):
_, _, type_variation, compute_node, _, instance_tree = self.bootstrapAllocableInstanceTree(allocation_state='allocated')
compute_node.setAccessStatus("#access ok")
compute_node.edit(capacity_quantity=6)
type_variation.setCapacityQuantity(3)
self.tic()
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', compute_node.getCapacityScope())
partition = compute_node.newContent(
portal_type='Compute Partition',
reference='reference%s' % self.generateNewId()
)
partition.validate()
partition.markFree()
self.tic()
with TemporaryAlarmScript(self.portal, 'Item_getSubscriptionStatus', "'subscribed'"):
instance_tree.getDestinationSectionValue().requestSoftwareInstance(
software_release=instance_tree.getUrlString(),
software_type=instance_tree.getSourceReference(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateEmptyXml(),
shared=False,
software_title=instance_tree.getTitle() + '2',
state='started',
project_reference=instance_tree.getFollowUpReference()
)
new_instance = self.portal.REQUEST.get('request_instance')
new_instance.edit(aggregate_value=partition)
partition.markBusy()
self.tic() self.tic()
compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node.ComputeNode_checkAndUpdateCapacityScope()
......
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