Commit ab89f093 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: instance must be invalidated before unallocating it

parent c620f77b
instance = context
if instance.getSlapState() != 'destroy_requested':
return
if instance.getValidationState() != 'invalidated':
# Node must confirm the destruction before unallocation
return
partition = instance.getAggregateValue(portal_type="Compute Partition")
portal = instance.getPortalObject()
......@@ -13,7 +16,7 @@ if partition is not None:
instance.unallocatePartition()
instance_sql_list = portal.portal_catalog(
portal_type=["Software Instance", "Slave Instance"],
default_aggregate_uid=partition.getUid(),
aggregate__uid=partition.getUid(),
)
count = len(instance_sql_list)
if count == 0:
......
......@@ -228,6 +228,8 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.tic()
software_instance.SoftwareInstance_tryToUnallocatePartition()
......@@ -243,6 +245,8 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.tic()
software_instance.SoftwareInstance_tryToUnallocatePartition()
......@@ -258,6 +262,8 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.tic()
partition.activate(tag="allocate_%s" % partition.getRelativeUrl()\
......@@ -289,6 +295,8 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
'busy')
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.tic()
software_instance.SoftwareInstance_tryToUnallocatePartition()
......@@ -317,6 +325,21 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
self.assertEqual(partition.getRelativeUrl(), software_instance.getAggregate())
self.assertEqual('busy', partition.getSlapState())
def test_SoftwareInstance_tryToUnallocatePartition_script_notInvalidated(self):
instance_tree = self.addInstanceTree()
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,
'destroy_requested')
self.tic()
software_instance.SoftwareInstance_tryToUnallocatePartition()
self.assertEqual(partition.getRelativeUrl(), software_instance.getAggregate())
self.assertEqual('busy', partition.getSlapState())
class TestSlapOSGarbageCollectDestroyedRootTreeAlarm(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