Commit ef1cc06d authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: invalidate Slave Instance allocation on a Compute Node

parent 41e5b151
...@@ -6,7 +6,17 @@ if context.getPortalType() not in ('Software Instance', 'Slave Instance'): ...@@ -6,7 +6,17 @@ if context.getPortalType() not in ('Software Instance', 'Slave Instance'):
raise TypeError('%s is not supported' % context.getPortalType()) raise TypeError('%s is not supported' % context.getPortalType())
software_instance = context software_instance = context
if software_instance.getValidationState() == 'validated' \ if (software_instance.getValidationState() == 'validated') \
and software_instance.getSlapState() == 'destroy_requested' \ and (software_instance.getSlapState() == 'destroy_requested'):
and software_instance.getAggregateValue(portal_type='Compute Partition') is None:
partition = software_instance.getAggregateValue(portal_type='Compute Partition')
if partition is None:
software_instance.invalidate(comment='Invalidated as unallocated and destroyed') software_instance.invalidate(comment='Invalidated as unallocated and destroyed')
elif (partition.getParentValue().getPortalType() == 'Compute Node') and \
(software_instance.getPortalType() == 'Slave Instance'):
# Invalidate ONLY IF the partition is inside a Compute Node, which does not report destruction
software_instance.invalidate(comment='Invalidated as Compute Node does not report destruction of Slave Instance')
# Software Instance allocated on a Compute Node is invalidated by SlapTool
...@@ -1201,6 +1201,54 @@ class TestSlapOSInvalidateDestroyedInstance(SlapOSTestCaseMixin): ...@@ -1201,6 +1201,54 @@ class TestSlapOSInvalidateDestroyedInstance(SlapOSTestCaseMixin):
self.assertEqual(software_instance.getValidationState(), "validated") self.assertEqual(software_instance.getValidationState(), "validated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested") self.assertEqual(software_instance.getSlapState(), "destroy_requested")
def test_tryToInvalidateIfDestroyed_script_allocatedSlaveInstance(self):
instance_tree = self.addInstanceTree(shared=True)
software_instance = instance_tree.getSuccessorValue()
_, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
software_instance.setAggregateValue(partition)
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "invalidated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
def test_tryToInvalidateIfDestroyed_script_allocatedInstanceOnRemoteNode(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
_, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue(),
portal_type="Remote Node"
)
software_instance.setAggregateValue(partition)
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "validated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
def test_tryToInvalidateIfDestroyed_script_allocatedSlaveInstanceOnRemoteNode(self):
instance_tree = self.addInstanceTree(shared=True)
software_instance = instance_tree.getSuccessorValue()
_, partition = self.addComputeNodeAndPartition(
project=instance_tree.getFollowUpValue(),
portal_type="Remote Node"
)
software_instance.setAggregateValue(partition)
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "validated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
class TestSlapOSPropagateRemoteNodeInstance(SlapOSTestCaseMixin): class TestSlapOSPropagateRemoteNodeInstance(SlapOSTestCaseMixin):
################################################################# #################################################################
......
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