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):
url_string='type%s' % self.generateNewId(),
)
# XXX XXX XXX XXX replqce is_allocated by allocation="prepare" "allocate" None
def bootstrapAllocableInstanceTree(self, is_allocated=False, shared=False, node="compute"):
def bootstrapAllocableInstanceTree(self, allocation_state='possible', shared=False, node="compute"):
if allocation_state not in ('impossible', 'possible', 'allocated'):
raise ValueError('Not supported allocation_state: %s' % allocation_state)
project = self.addProject()
person = self.makePerson(project)
software_product = self._makeSoftwareProduct(project)
......@@ -659,60 +660,61 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
person.requestSoftwareInstance(**request_kw)
instance_tree = self.portal.REQUEST.get('request_instance_tree')
if (node == "instance") and (shared):
real_compute_node = self.portal.compute_node_module.newContent(
portal_type="Compute Node",
follow_up_value=project,
reference='TEST-%s' % self.generateNewId(),
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
# behaviour.
real_compute_node.edit(capacity_scope='open')
real_compute_node.validate()
partition = real_compute_node.newContent(
portal_type='Compute Partition',
reference='reference%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",
follow_up_value=project,
specialise_value=node_instance_tree,
url_string=release_variation.getUrlString(),
title='TEST-%s' % self.generateNewId(),
reference='TEST-%s' % self.generateNewId(),
source_reference='TEST-%s' % self.generateNewId(),
destination_reference='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)
software_instance.edit(aggregate_value=partition)
self.portal.portal_workflow._jumpToStateFor(software_instance, 'start_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
partition.validate()
partition.markFree()
partition.markBusy()
elif (node == "instance") and (not shared):
raise NotImplementedError('can not allocate on instance node')
else:
partition = compute_node.newContent(
portal_type='Compute Partition',
reference='reference%s' % self.generateNewId()
)
if allocation_state in ('possible', 'allocated'):
if (node == "instance") and (shared):
real_compute_node = self.portal.compute_node_module.newContent(
portal_type="Compute Node",
follow_up_value=project,
reference='TEST-%s' % self.generateNewId(),
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
# behaviour.
real_compute_node.edit(capacity_scope='open')
real_compute_node.validate()
partition = real_compute_node.newContent(
portal_type='Compute Partition',
reference='reference%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",
follow_up_value=project,
specialise_value=node_instance_tree,
url_string=release_variation.getUrlString(),
title='TEST-%s' % self.generateNewId(),
reference='TEST-%s' % self.generateNewId(),
source_reference='TEST-%s' % self.generateNewId(),
destination_reference='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)
software_instance.edit(aggregate_value=partition)
self.portal.portal_workflow._jumpToStateFor(software_instance, 'start_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
partition.validate()
partition.markFree()
partition.markBusy()
elif (node == "instance") and (not shared):
raise NotImplementedError('can not allocate on instance node')
else:
partition = compute_node.newContent(
portal_type='Compute Partition',
reference='reference%s' % self.generateNewId()
)
partition.validate()
partition.markFree()
partition.validate()
partition.markFree()
#compute_node.validate()
if is_allocated:
if allocation_state == 'allocated':
instance = instance_tree.getSuccessorValue()
instance.edit(aggregate_value=partition)
if not ((node == "instance") and (shared)):
......
......@@ -6,8 +6,8 @@ from unittest import skip
class TestSlapOSAllocation(SlapOSTestCaseMixin):
def makeAllocableSoftwareInstance(self, is_allocated=False, 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)
def makeAllocableSoftwareInstance(self, allocation_state='possible', shared=False, node="compute"):
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,
release_variation, type_variation)
real_compute_node = partition.getParentValue()
......@@ -17,17 +17,6 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
)
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.getCapacityScope(), "open")
......@@ -226,7 +215,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
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'):
self.portal.portal_alarms.slapos_allocate_instance.activeSense()
......@@ -238,7 +227,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
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'):
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