Commit b81c9725 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Remove old unallocated instances if Allocation is disallowed

parent 912d4117
...@@ -11,7 +11,7 @@ if instance.getValidationState() != 'validated' \ ...@@ -11,7 +11,7 @@ if instance.getValidationState() != 'validated' \
return return
latest_comment = portal.portal_workflow.getInfoFor(instance, 'comment', wf_id='edit_workflow') latest_comment = portal.portal_workflow.getInfoFor(instance, 'comment', wf_id='edit_workflow')
if latest_comment != 'Allocation failed: no free Computer Partition': if latest_comment not in ('Allocation failed: no free Computer Partition', 'Allocation failed: Allocation disallowed'):
# No nothing if allocation alarm didn't run on it # No nothing if allocation alarm didn't run on it
return return
......
...@@ -1763,6 +1763,24 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -1763,6 +1763,24 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
hosting_subscription = instance.getSpecialiseValue() hosting_subscription = instance.getSpecialiseValue()
self.assertEqual('start_requested', hosting_subscription.getSlapState()) self.assertEqual('start_requested', hosting_subscription.getSlapState())
def test_tryToGarbageCollect_recent_allocation_try_found_allocation_disallowed(self):
instance = self.createInstance()
self.tic()
instance.workflow_history['edit_workflow'].append({
'comment':'Allocation failed: Allocation disallowed',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': '',
'time': addToDate(DateTime(), to_add={'day': -2}),
'action': 'edit'
})
instance.Instance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('start_requested', instance.getSlapState())
hosting_subscription = instance.getSpecialiseValue()
self.assertEqual('start_requested', hosting_subscription.getSlapState())
def test_tryToGarbageCollect_complex_tree(self): def test_tryToGarbageCollect_complex_tree(self):
instance = self.createInstance() instance = self.createInstance()
hosting_subscription = instance.getSpecialiseValue() hosting_subscription = instance.getSpecialiseValue()
...@@ -1791,6 +1809,34 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -1791,6 +1809,34 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
sub_instance.Instance_tryToGarbageCollectNonAllocatedRootTree() sub_instance.Instance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('start_requested', hosting_subscription.getSlapState()) self.assertEqual('start_requested', hosting_subscription.getSlapState())
def test_tryToGarbageCollect_complex_tree_allocation_disallowed(self):
instance = self.createInstance()
hosting_subscription = instance.getSpecialiseValue()
request_kw = dict(
software_release=\
self.generateNewSoftwareReleaseUrl(),
software_type=self.generateNewSoftwareType(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateSafeXml(),
shared=False,
software_title="another %s" % hosting_subscription.getTitle(),
state='started'
)
instance.requestInstance(**request_kw)
sub_instance = instance.getPredecessorValue()
self.tic()
sub_instance.workflow_history['edit_workflow'].append({
'comment':'Allocation failed: Allocation disallowed',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': '',
'time': addToDate(DateTime(), to_add={'day': -4}),
'action': 'edit'
})
sub_instance.Instance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('start_requested', hosting_subscription.getSlapState())
def test_tryToGarbageCollect_old_allocation_try_found(self): def test_tryToGarbageCollect_old_allocation_try_found(self):
instance = self.createInstance() instance = self.createInstance()
hosting_subscription = instance.getSpecialiseValue() hosting_subscription = instance.getSpecialiseValue()
...@@ -1808,6 +1854,24 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -1808,6 +1854,24 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
self.assertEqual('destroy_requested', hosting_subscription.getSlapState()) self.assertEqual('destroy_requested', hosting_subscription.getSlapState())
self.assertEqual('archived', hosting_subscription.getValidationState()) self.assertEqual('archived', hosting_subscription.getValidationState())
def test_tryToGarbageCollect_old_allocation_try_found_allocation_disallowed(self):
instance = self.createInstance()
hosting_subscription = instance.getSpecialiseValue()
self.tic()
instance.workflow_history['edit_workflow'].append({
'comment':'Allocation failed: Allocation disallowed',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': '',
'time': addToDate(DateTime(), to_add={'day': -8}),
'action': 'edit'
})
instance.Instance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('destroy_requested', hosting_subscription.getSlapState())
self.assertEqual('archived', hosting_subscription.getValidationState())
def _simulateInstance_tryToGarbageCollectNonAllocatedRootTree(self): def _simulateInstance_tryToGarbageCollectNonAllocatedRootTree(self):
script_name = 'Instance_tryToGarbageCollectNonAllocatedRootTree' script_name = 'Instance_tryToGarbageCollectNonAllocatedRootTree'
if script_name in self.portal.portal_skins.custom.objectIds(): if script_name in self.portal.portal_skins.custom.objectIds():
......
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