Commit 90ce6b73 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: test compute network sla

parent 0a3dc431
......@@ -6,8 +6,23 @@ from unittest import skip
class TestSlapOSAllocation(SlapOSTestCaseMixin):
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)
def makeAllocableComputeNode(self, project, software_product,
release_variation, type_variation):
compute_node, partition = self._makeComputeNode(project)
self.addAllocationSupply("for compute node", compute_node, software_product,
release_variation, type_variation)
self._installSoftware(
compute_node,
release_variation.getUrlString()
)
self.tic()
return compute_node, partition
def makeAllocableSoftwareInstanceAndProduct(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()
......@@ -22,6 +37,11 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
software_instance = instance_tree.getSuccessorValue()
return software_instance, compute_node, partition, software_product, release_variation, type_variation
def makeAllocableSoftwareInstance(self, allocation_state='possible', shared=False, node="compute"):
software_instance, compute_node, partition, _, _, _ = \
self.makeAllocableSoftwareInstanceAndProduct(allocation_state=allocation_state, shared=shared, node=node)
return software_instance, compute_node, partition
def _installSoftware(self, compute_node, url):
......@@ -291,40 +311,41 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
def test_allocation_network_guid(self):
self._makeTree(self.project)
software_instance, compute_node, partition = self.makeAllocableSoftwareInstance()
self._makeComputeNode(self.project)
new_id = self.generateNewId()
computer_network = self.portal.computer_network_module.newContent(
portal_type='Computer Network',
title="live_test_%s" % new_id,
reference="live_test_%s" % new_id)
reference="live_test_%s" % new_id,
follow_up_value=software_instance.getFollowUpValue()
)
computer_network.validate()
self.compute_node.edit(
subordination_value=computer_network)
self._installSoftware(self.compute_node,
self.software_instance.getUrlString())
compute_node.edit(
subordination_value=computer_network
)
self.tic()
self.assertEqual(None, self.software_instance.getAggregateValue(
self.assertEqual(None, software_instance.getAggregateValue(
portal_type='Compute Partition'))
self.software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
<instance>
<parameter id='network_guid'>%s</parameter>
</instance>""" % '%s_foo' % \
self.partition.getParentValue().getSubordinationReference())
self.software_instance.SoftwareInstance_tryToAllocatePartition()
partition.getParentValue().getSubordinationReference())
software_instance.SoftwareInstance_tryToAllocatePartition()
self.assertEqual(None,
self.software_instance.getAggregate(portal_type='Compute Partition'))
software_instance.getAggregate(portal_type='Compute Partition'))
self.software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
<instance>
<parameter id='network_guid'>%s</parameter>
</instance>""" % '%s' % \
self.partition.getParentValue().getSubordinationReference())
self.software_instance.SoftwareInstance_tryToAllocatePartition()
self.assertEqual(self.partition.getRelativeUrl(),
self.software_instance.getAggregate(portal_type='Compute Partition'))
partition.getParentValue().getSubordinationReference())
software_instance.SoftwareInstance_tryToAllocatePartition()
self.assertEqual(partition.getRelativeUrl(),
software_instance.getAggregate(portal_type='Compute Partition'))
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
def test_allocation_mode_unique_by_network_one_network(self):
......@@ -340,11 +361,13 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
<instance>
<parameter id='mode'>unique_by_network</parameter>
</instance>"""
self._makeTree(self.project)
compute_node1 = self._makeComputeNode(self.project)[0]
compute_node2 = self._makeComputeNode(self.project)[0]
self._installSoftware(compute_node1, self.software_instance.getUrlString())
self._installSoftware(compute_node2, self.software_instance.getUrlString())
software_instance, compute_node1, _, software_product, release_variation, type_variation = \
self.makeAllocableSoftwareInstanceAndProduct()
instance_tree = software_instance.getSpecialiseValue()
project = compute_node1.getFollowUpValue()
compute_node2, _ = self.makeAllocableComputeNode(project, software_product, release_variation, type_variation)
new_id = self.generateNewId()
computer_network = self.portal.computer_network_module.newContent(
......@@ -355,7 +378,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
compute_node1.edit(subordination_value=computer_network)
compute_node2.edit(subordination_value=computer_network)
self.assertEqual(None, self.software_instance.getAggregateValue(
self.assertEqual(None, software_instance.getAggregateValue(
portal_type='Compute Partition'))
software_instance2 = self.portal.software_instance_module\
......@@ -363,38 +386,38 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
software_instance2.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTSI-%s" % self.generateNewId(),
url_string=self.software_instance.getUrlString(),
source_reference=self.generateNewSoftwareType(),
url_string=software_instance.getUrlString(),
source_reference=software_instance.getSourceReference(),
text_content=self.generateSafeXml(),
sla_xml=sla_xml,
specialise=self.instance_tree.getRelativeUrl(),
follow_up_value=self.project
specialise_value=instance_tree,
follow_up_value=project
)
self.portal.portal_workflow._jumpToStateFor(software_instance2, 'start_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance2, 'validated')
self.tic()
self.assertEqual(None,
self.software_instance.getAggregateValue(portal_type='Compute Partition'))
software_instance.getAggregateValue(portal_type='Compute Partition'))
self.assertEqual(self.software_instance.getSlapState(), 'start_requested')
self.assertEqual(self.software_instance.getValidationState(), 'validated')
self.assertEqual(software_instance.getSlapState(), 'start_requested')
self.assertEqual(software_instance.getValidationState(), 'validated')
self.software_instance.setSlaXml(sla_xml)
self.software_instance.SoftwareInstance_tryToAllocatePartition()
software_instance.setSlaXml(sla_xml)
software_instance.SoftwareInstance_tryToAllocatePartition()
self.tic()
portal_workflow = self.software_instance.portal_workflow
last_workflow_item = portal_workflow.getInfoFor(ob=self.software_instance,
portal_workflow = software_instance.portal_workflow
last_workflow_item = portal_workflow.getInfoFor(ob=software_instance,
name='comment', wf_id='edit_workflow')
self.assertEqual(None,last_workflow_item)
self.assertEqual(None, last_workflow_item)
self.assertNotEqual(None,
self.software_instance.getAggregateValue(portal_type='Compute Partition'))
software_instance.getAggregateValue(portal_type='Compute Partition'))
self.assertEqual(
computer_network.getReference(),
self.software_instance.getAggregateValue(portal_type='Compute Partition')\
.getParentValue().getSubordinationReference(),
software_instance.getAggregateValue(portal_type='Compute Partition')\
.getParentValue().getSubordinationReference(),
)
self.tic()
......@@ -415,15 +438,19 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
instance tree.
Test with 3 instances and 3 existing compute_nodes on 2 different networks.
"""
self.tic()
sla_xml = """<?xml version='1.0' encoding='utf-8'?>
<instance>
<parameter id='mode'>unique_by_network</parameter>
</instance>"""
self._makeTree(self.project)
compute_node1, partition1 = self._makeComputeNode(self.project)
compute_node2 = self._makeComputeNode(self.project)[0]
compute_node3, partition3 = self._makeComputeNode(self.project)
software_instance, compute_node1, partition1, software_product, release_variation, type_variation = \
self.makeAllocableSoftwareInstanceAndProduct()
instance_tree = software_instance.getSpecialiseValue()
project = compute_node1.getFollowUpValue()
compute_node2, _ = self.makeAllocableComputeNode(project, software_product, release_variation, type_variation)
compute_node3, partition3 = self.makeAllocableComputeNode(project, software_product, release_variation, type_variation)
computer_network1 = self._makeComputerNetwork()
computer_network2 = self._makeComputerNetwork()
......@@ -431,25 +458,19 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
compute_node2.edit(subordination_value=computer_network1)
compute_node3.edit(subordination_value=computer_network2)
self._installSoftware(compute_node1, self.software_instance.getUrlString())
self._installSoftware(compute_node2, self.software_instance.getUrlString())
self._installSoftware(compute_node3, self.software_instance.getUrlString())
self.assertEqual(None, self.software_instance.getAggregateValue(
portal_type='Compute Partition'))
self.tic()
self.assertEqual(None, self.requested_software_instance.getAggregateValue(
self.assertEqual(None, software_instance.getAggregateValue(
portal_type='Compute Partition'))
self.software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
<instance>
<parameter id='mode'>unique_by_network</parameter>
<parameter id='computer_guid'>%s</parameter>
</instance>""" % compute_node1.getReference())
self.software_instance.SoftwareInstance_tryToAllocatePartition()
software_instance.SoftwareInstance_tryToAllocatePartition()
self.assertEqual(
self.software_instance.getAggregate(portal_type='Compute Partition'),
software_instance.getAggregate(portal_type='Compute Partition'),
partition1.getRelativeUrl(),
)
......@@ -458,16 +479,16 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
software_instance2.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTSI-%s" % self.generateNewId(),
url_string=self.software_instance.getUrlString(),
source_reference=self.generateNewSoftwareType(),
url_string=software_instance.getUrlString(),
source_reference=software_instance.getSourceReference(),
text_content=self.generateSafeXml(),
sla_xml=sla_xml,
specialise=self.instance_tree.getRelativeUrl(),
follow_up_value=self.project
specialise=instance_tree.getRelativeUrl(),
follow_up_value=project
)
self.portal.portal_workflow._jumpToStateFor(software_instance2, 'start_requested')
software_instance2.validate()
self.commit()
self.tic()
software_instance2.SoftwareInstance_tryToAllocatePartition()
self.assertEqual(
software_instance2.getAggregate(portal_type='Compute Partition'),
......@@ -479,12 +500,12 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
software_instance3.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTSI-%s" % self.generateNewId(),
url_string=self.software_instance.getUrlString(),
url_string=software_instance.getUrlString(),
source_reference=self.generateNewSoftwareType(),
text_content=self.generateSafeXml(),
sla_xml=sla_xml,
specialise=self.instance_tree.getRelativeUrl(),
follow_up_value=self.project
specialise=instance_tree.getRelativeUrl(),
follow_up_value=project
)
self.portal.portal_workflow._jumpToStateFor(software_instance3, 'start_requested')
software_instance3.validate()
......@@ -502,22 +523,19 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
Test that when we request instance with mode as 'unique_by_network',
instance is not deployed on compute_node with no network.
"""
self._makeTree(self.project)
self._makeComputeNode(self.project)
self._installSoftware(self.compute_node,
self.software_instance.getUrlString())
software_instance, _, _ = self.makeAllocableSoftwareInstance()
self.assertEqual(None, self.software_instance.getAggregateValue(
self.assertEqual(None, software_instance.getAggregateValue(
portal_type='Compute Partition'))
self.software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
<instance>
<parameter id='mode'>unique_by_network</parameter>
</instance>""")
self.software_instance.SoftwareInstance_tryToAllocatePartition()
software_instance.SoftwareInstance_tryToAllocatePartition()
self.assertEqual(
None,
self.software_instance.getAggregate(portal_type='Compute Partition')
software_instance.getAggregate(portal_type='Compute Partition')
)
@simulate('Person_isAllowedToAllocate', '*args, **kwargs', 'return True')
......@@ -537,8 +555,8 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
else:
return self.serialize_call()
self._makeTree(self.project)
self.software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
software_instance, _, _ = self.makeAllocableSoftwareInstance()
software_instance.setSlaXml("""<?xml version='1.0' encoding='utf-8'?>
<instance>
<parameter id='mode'>unique_by_network</parameter>
</instance>""")
......@@ -548,7 +566,7 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
try:
Base.serialize = verify_serialize_call
self.assertRaises(DummyTestException,
self.software_instance.SoftwareInstance_tryToAllocatePartition)
software_instance.SoftwareInstance_tryToAllocatePartition)
finally:
Base.serialize = Base.serialize_call
......@@ -565,22 +583,22 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
<instance>
<parameter id='mode'>unique_by_network</parameter>
</instance>"""
self._makeTree(self.project)
compute_node1 = self._makeComputeNode(self.project)[0]
compute_node2 = self._makeComputeNode(self.project)[0]
self._installSoftware(compute_node1, self.software_instance.getUrlString())
self._installSoftware(compute_node2, self.software_instance.getUrlString())
software_instance, compute_node1, _, software_product, release_variation, type_variation = \
self.makeAllocableSoftwareInstanceAndProduct()
instance_tree = software_instance.getSpecialiseValue()
project = compute_node1.getFollowUpValue()
compute_node2, _ = self.makeAllocableComputeNode(project, software_product, release_variation, type_variation)
computer_network = self._makeComputerNetwork()
new_id = self.generateNewId()
computer_network = self.portal.computer_network_module.newContent(
portal_type='Computer Network',
title="live_test_%s" % new_id,
reference="live_test_%s" % new_id)
computer_network.validate()
compute_node1.edit(subordination_value=computer_network)
compute_node2.edit(subordination_value=computer_network)
self.assertEqual(None, self.software_instance.getAggregateValue(
self.tic()
self.assertEqual(None, software_instance.getAggregateValue(
portal_type='Compute Partition'))
software_instance2 = self.portal.software_instance_module\
......@@ -588,12 +606,12 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
software_instance2.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTSI-%s" % self.generateNewId(),
url_string=self.software_instance.getUrlString(),
source_reference=self.generateNewSoftwareType(),
url_string=software_instance.getUrlString(),
source_reference=software_instance.getSourceReference(),
text_content=self.generateSafeXml(),
sla_xml=sla_xml,
specialise=self.instance_tree.getRelativeUrl(),
follow_up_value=self.project
specialise_value=instance_tree,
follow_up_value=project
)
self.portal.portal_workflow._jumpToStateFor(software_instance2, 'start_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance2, 'validated')
......@@ -601,27 +619,27 @@ class TestSlapOSAllocation(SlapOSTestCaseMixin):
self.assertEqual(None,
self.software_instance.getAggregateValue(portal_type='Compute Partition'))
software_instance.getAggregateValue(portal_type='Compute Partition'))
self.assertEqual(self.software_instance.getSlapState(), 'start_requested')
self.assertEqual(self.software_instance.getValidationState(), 'validated')
self.assertEqual(software_instance.getSlapState(), 'start_requested')
self.assertEqual(software_instance.getValidationState(), 'validated')
self.software_instance.setSlaXml(sla_xml)
self.software_instance.SoftwareInstance_tryToAllocatePartition()
software_instance.setSlaXml(sla_xml)
software_instance.SoftwareInstance_tryToAllocatePartition()
software_instance2.SoftwareInstance_tryToAllocatePartition()
portal_workflow = self.software_instance.portal_workflow
last_workflow_item = portal_workflow.getInfoFor(ob=self.software_instance,
portal_workflow = software_instance.portal_workflow
last_workflow_item = portal_workflow.getInfoFor(ob=software_instance,
name='comment', wf_id='edit_workflow')
self.assertEqual(None,last_workflow_item)
self.assertEqual(None, last_workflow_item)
self.assertNotEqual(None,
self.software_instance.getAggregateValue(portal_type='Compute Partition'))
software_instance.getAggregateValue(portal_type='Compute Partition'))
# First is deployed
self.assertEqual(
computer_network.getReference(),
self.software_instance.getAggregateValue(portal_type='Compute Partition')\
.getParentValue().getSubordinationReference(),
software_instance.getAggregateValue(portal_type='Compute Partition')\
.getParentValue().getSubordinationReference(),
)
# But second is not yet deployed because of pending activities containing tag
self.assertEqual(
......
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