Commit f77ba5b7 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: test compute network sla

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