Commit 6567cc8b authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: one day, I'll stop using boolean as argument...

parent 0991dfca
...@@ -611,8 +611,9 @@ class SlapOSTestCaseMixin(testSlapOSMixin): ...@@ -611,8 +611,9 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
url_string='type%s' % self.generateNewId(), url_string='type%s' % self.generateNewId(),
) )
# XXX XXX XXX XXX replqce is_allocated by allocation="prepare" "allocate" None def bootstrapAllocableInstanceTree(self, allocation_state='possible', shared=False, node="compute"):
def bootstrapAllocableInstanceTree(self, is_allocated=False, shared=False, node="compute"): if allocation_state not in ('impossible', 'possible', 'allocated'):
raise ValueError('Not supported allocation_state: %s' % allocation_state)
project = self.addProject() project = self.addProject()
person = self.makePerson(project) person = self.makePerson(project)
software_product = self._makeSoftwareProduct(project) software_product = self._makeSoftwareProduct(project)
...@@ -659,60 +660,61 @@ class SlapOSTestCaseMixin(testSlapOSMixin): ...@@ -659,60 +660,61 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
person.requestSoftwareInstance(**request_kw) person.requestSoftwareInstance(**request_kw)
instance_tree = self.portal.REQUEST.get('request_instance_tree') instance_tree = self.portal.REQUEST.get('request_instance_tree')
if (node == "instance") and (shared): if allocation_state in ('possible', 'allocated'):
real_compute_node = self.portal.compute_node_module.newContent( if (node == "instance") and (shared):
portal_type="Compute Node", real_compute_node = self.portal.compute_node_module.newContent(
follow_up_value=project, portal_type="Compute Node",
reference='TEST-%s' % self.generateNewId(), follow_up_value=project,
allocation_scope="open", reference='TEST-%s' % self.generateNewId(),
capacity_scope='open' allocation_scope="open",
) capacity_scope='open'
# The edit above will update capacity scope due the interaction workflow )
# The line above force capacity scope to be open, keeping the previous # The edit above will update capacity scope due the interaction workflow
# behaviour. # The line above force capacity scope to be open, keeping the previous
real_compute_node.edit(capacity_scope='open') # behaviour.
real_compute_node.validate() real_compute_node.edit(capacity_scope='open')
partition = real_compute_node.newContent( real_compute_node.validate()
portal_type='Compute Partition', partition = real_compute_node.newContent(
reference='reference%s' % self.generateNewId() portal_type='Compute Partition',
) reference='reference%s' % self.generateNewId()
node_instance_tree = self.portal.instance_tree_module.newContent( )
title='TEST-%s' % self.generateNewId(), node_instance_tree = self.portal.instance_tree_module.newContent(
) title='TEST-%s' % self.generateNewId(),
software_instance = self.portal.software_instance_module.newContent( )
portal_type="Software Instance", software_instance = self.portal.software_instance_module.newContent(
follow_up_value=project, portal_type="Software Instance",
specialise_value=node_instance_tree, follow_up_value=project,
url_string=release_variation.getUrlString(), specialise_value=node_instance_tree,
title='TEST-%s' % self.generateNewId(), url_string=release_variation.getUrlString(),
reference='TEST-%s' % self.generateNewId(), title='TEST-%s' % self.generateNewId(),
source_reference='TEST-%s' % self.generateNewId(), reference='TEST-%s' % self.generateNewId(),
destination_reference='TEST-%s' % self.generateNewId(), source_reference='TEST-%s' % self.generateNewId(),
ssl_certificate='TEST-%s' % self.generateNewId(), destination_reference='TEST-%s' % self.generateNewId(),
ssl_key='TEST-%s' % self.generateNewId(), ssl_certificate='TEST-%s' % self.generateNewId(),
) ssl_key='TEST-%s' % self.generateNewId(),
self.tic() )
compute_node.edit(specialise_value=software_instance) self.tic()
software_instance.edit(aggregate_value=partition) compute_node.edit(specialise_value=software_instance)
self.portal.portal_workflow._jumpToStateFor(software_instance, 'start_requested') software_instance.edit(aggregate_value=partition)
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated') self.portal.portal_workflow._jumpToStateFor(software_instance, 'start_requested')
partition.validate() self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
partition.markFree() partition.validate()
partition.markBusy() partition.markFree()
elif (node == "instance") and (not shared): partition.markBusy()
raise NotImplementedError('can not allocate on instance node') elif (node == "instance") and (not shared):
else: raise NotImplementedError('can not allocate on instance node')
partition = compute_node.newContent( else:
portal_type='Compute Partition', partition = compute_node.newContent(
reference='reference%s' % self.generateNewId() portal_type='Compute Partition',
) reference='reference%s' % self.generateNewId()
)
partition.validate() partition.validate()
partition.markFree() partition.markFree()
#compute_node.validate() #compute_node.validate()
if is_allocated: if allocation_state == 'allocated':
instance = instance_tree.getSuccessorValue() instance = instance_tree.getSuccessorValue()
instance.edit(aggregate_value=partition) instance.edit(aggregate_value=partition)
if not ((node == "instance") and (shared)): if not ((node == "instance") and (shared)):
......
...@@ -6,8 +6,8 @@ from unittest import skip ...@@ -6,8 +6,8 @@ from unittest import skip
class TestSlapOSAllocation(SlapOSTestCaseMixin): class TestSlapOSAllocation(SlapOSTestCaseMixin):
def makeAllocableSoftwareInstance(self, is_allocated=False, shared=False, node="compute"): def makeAllocableSoftwareInstance(self, allocation_state='possible', shared=False, node="compute"):
software_product, release_variation, type_variation, compute_node, partition, instance_tree = self.bootstrapAllocableInstanceTree(is_allocated=is_allocated, shared=shared, node=node) software_product, release_variation, type_variation, compute_node, partition, instance_tree = self.bootstrapAllocableInstanceTree(allocation_state=allocation_state, shared=shared, node=node)
self.addAllocationSupply("for compute node", compute_node, software_product, self.addAllocationSupply("for compute node", compute_node, software_product,
release_variation, type_variation) release_variation, type_variation)
real_compute_node = partition.getParentValue() real_compute_node = partition.getParentValue()
...@@ -17,17 +17,6 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin): ...@@ -17,17 +17,6 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
) )
self.tic() self.tic()
"""
if not shared:
partition = compute_node.newContent(
portal_type='Compute Partition',
reference='reference%s' % self.generateNewId()
)
partition.validate()
partition.markFree()
self.tic()"""
self.assertEqual(real_compute_node.getAllocationScope(), "open") self.assertEqual(real_compute_node.getAllocationScope(), "open")
self.assertEqual(real_compute_node.getCapacityScope(), "open") self.assertEqual(real_compute_node.getCapacityScope(), "open")
...@@ -226,7 +215,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin): ...@@ -226,7 +215,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True') @simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
def test_alarm_software_instance_allocated(self): def test_alarm_software_instance_allocated(self):
software_instance, _, _ = self.makeAllocableSoftwareInstance(is_allocated=True) software_instance, _, _ = self.makeAllocableSoftwareInstance(allocation_state='allocated')
with TemporaryAlarmScript(self.portal, 'SoftwareInstance_tryToAllocatePartition'): with TemporaryAlarmScript(self.portal, 'SoftwareInstance_tryToAllocatePartition'):
self.portal.portal_alarms.slapos_allocate_instance.activeSense() self.portal.portal_alarms.slapos_allocate_instance.activeSense()
...@@ -238,7 +227,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin): ...@@ -238,7 +227,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True') @simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
def test_alarm_slave_instance_allocated(self): def test_alarm_slave_instance_allocated(self):
software_instance, _, _ = self.makeAllocableSoftwareInstance(is_allocated=True, shared=True, node="instance") software_instance, _, _ = self.makeAllocableSoftwareInstance(allocation_state='allocated', shared=True, node="instance")
with TemporaryAlarmScript(self.portal, 'SoftwareInstance_tryToAllocatePartition'): with TemporaryAlarmScript(self.portal, 'SoftwareInstance_tryToAllocatePartition'):
self.portal.portal_alarms.slapos_allocate_instance.activeSense() self.portal.portal_alarms.slapos_allocate_instance.activeSense()
......
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