Commit ab89f093 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: instance must be invalidated before unallocating it

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