Commit b495b8e7 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fixup slapos_garbage_collect_non_allocated_root_tree tests

parent 38e9d877
...@@ -665,134 +665,165 @@ class TestSlapOSGarbageCollectStoppedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -665,134 +665,165 @@ class TestSlapOSGarbageCollectStoppedRootTreeAlarm(SlapOSTestCaseMixin):
class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
#################################################################
def afterSetUp(self): # slapos_garbage_collect_non_allocated_root_tree
SlapOSTestCaseMixin.afterSetUp(self) #################################################################
self.project = self.addProject() def test_tryToGarbageCollectNonAllocatedRootTree_alarm(self):
instance_tree = self.addInstanceTree()
def createInstance(self, project): software_instance = instance_tree.getSuccessorValue()
instance_tree = self.portal.instance_tree_module\ self._test_alarm(
.template_instance_tree.Base_createCloneDocument(batch_mode=1) self.portal.portal_alarms.slapos_garbage_collect_non_allocated_root_tree,
instance_tree.edit( software_instance,
follow_up_value=project 'SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree'
)
instance_tree.validate()
instance_tree.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTHS-%s" % self.generateNewId(),
) )
request_kw = dict(
software_release=\ def test_tryToGarbageCollectNonAllocatedRootTree_alarm_invalidated(self):
self.generateNewSoftwareReleaseUrl(), instance_tree = self.addInstanceTree()
software_type=self.generateNewSoftwareType(), software_instance = instance_tree.getSuccessorValue()
instance_xml=self.generateSafeXml(), software_instance.invalidate()
sla_xml=self.generateSafeXml(), self._test_alarm_not_visited(
shared=False, self.portal.portal_alarms.slapos_garbage_collect_non_allocated_root_tree,
software_title=instance_tree.getTitle(), software_instance,
state='started', 'SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree'
project_reference=project
) )
instance_tree.requestStart(**request_kw)
instance_tree.requestInstance(**request_kw)
instance = instance_tree.getSuccessorValue() def test_tryToGarbageCollectNonAllocatedRootTree_alarm_allocated(self):
return instance _, partition = self.addComputeNodeAndPartition()
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.setAggregateValue(partition)
partition.markBusy()
def createComputePartition(self): self._test_alarm_not_visited(
compute_node = self.portal.compute_node_module\ self.portal.portal_alarms.slapos_garbage_collect_non_allocated_root_tree,
.template_compute_node.Base_createCloneDocument(batch_mode=1) software_instance,
compute_node.validate() 'SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree'
compute_node.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTCOMP-%s" % self.generateNewId(),
) )
partition = compute_node.newContent(portal_type="Compute Partition")
return partition
def test_tryToGarbageCollect_REQUEST_disallowed(self): #################################################################
# SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree
#################################################################
def test_tryToGarbageCollectNonAllocatedRootTree_REQUEST_disallowed(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree, self.portal.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree,
REQUEST={}) REQUEST={})
def test_tryToGarbageCollect_invalidated_instance(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_invalidatedInstance(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
instance.invalidate() software_instance = instance_tree.getSuccessorValue()
self.tic() software_instance.invalidate()
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() self.tic()
self.assertEqual('start_requested', instance.getSlapState()) software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
instance_tree = instance.getSpecialiseValue() self.assertEqual('start_requested', software_instance.getSlapState())
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_destroyed_instance(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_destroyedInstance(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested') software_instance = instance_tree.getSuccessorValue()
self.tic() self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() self.tic()
self.assertEqual('destroy_requested', instance.getSlapState()) software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
instance_tree = instance.getSpecialiseValue() self.assertEqual('destroy_requested', software_instance.getSlapState())
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_allocated_instance(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_allocatedInstance(self):
instance = self.createInstance(self.project) _, partition = self.addComputeNodeAndPartition()
partition = self.createComputePartition() instance_tree = self.addInstanceTree()
instance.edit(aggregate_value=partition) software_instance = instance_tree.getSuccessorValue()
self.tic() software_instance.setAggregateValue(partition)
partition.markBusy()
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() self.tic()
self.assertEqual('start_requested', instance.getSlapState()) software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
instance_tree = instance.getSpecialiseValue() self.assertEqual('start_requested', software_instance.getSlapState())
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_no_allocation_try_found(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_noAllocationTryFound(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
self.tic() software_instance = instance_tree.getSuccessorValue()
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() self.tic()
self.assertEqual('start_requested', instance.getSlapState()) software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
instance_tree = instance.getSpecialiseValue() self.assertEqual('start_requested', software_instance.getSlapState())
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_recent_allocation_try_found(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_recentAllocationTryFound(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
self.tic() software_instance = instance_tree.getSuccessorValue()
instance.workflow_history['edit_workflow'].append({ software_instance.workflow_history['edit_workflow'] = [{
'comment':'Allocation failed: no free Compute Partition', 'comment':'Allocation failed: no free Compute Partition',
'error_message': '', 'error_message': '',
'actor': 'ERP5TypeTestCase', 'actor': 'ERP5TypeTestCase',
'slap_state': '', 'state': 'current',
'time': addToDate(DateTime(), to_add={'day': -2}), 'time': addToDate(DateTime(), to_add={'day': -2}),
'action': 'edit' 'action': 'edit'
}) }]
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() self.tic()
self.assertEqual('start_requested', instance.getSlapState()) software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
instance_tree = instance.getSpecialiseValue() self.assertEqual('start_requested', software_instance.getSlapState())
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollectNonAllocatedRootTree_script_oldAllocationTryFound(self):
def test_tryToGarbageCollect_recent_allocation_try_found_allocation_disallowed(self): instance_tree = self.addInstanceTree()
instance = self.createInstance(self.project) software_instance = instance_tree.getSuccessorValue()
self.tic() self.tic()
instance.workflow_history['edit_workflow'].append({
software_instance.workflow_history['edit_workflow'] = [{
'comment':'Allocation failed: no free Compute Partition',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'state': 'current',
'time': addToDate(DateTime(), to_add={'day': -4}),
'action': 'edit'
}]
software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('destroy_requested', instance_tree.getSlapState())
self.assertEqual('archived', instance_tree.getValidationState())
self.assertEqual('start_requested', software_instance.getSlapState())
def test_tryToGarbageCollectNonAllocatedRootTree_script_recentAllocationTryFoundAllocationDisallowed(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.workflow_history['edit_workflow'] = [{
'comment':'Allocation failed: Allocation disallowed', 'comment':'Allocation failed: Allocation disallowed',
'error_message': '', 'error_message': '',
'actor': 'ERP5TypeTestCase', 'actor': 'ERP5TypeTestCase',
'slap_state': '', 'state': 'current',
'time': addToDate(DateTime(), to_add={'day': -2}), 'time': addToDate(DateTime(), to_add={'day': -2}),
'action': 'edit' 'action': 'edit'
}) }]
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() self.tic()
self.assertEqual('start_requested', instance.getSlapState()) software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
instance_tree = instance.getSpecialiseValue() self.assertEqual('start_requested', software_instance.getSlapState())
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_complex_tree(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_oldAllocationTryFoundAllocationDisallowed(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
instance_tree = instance.getSpecialiseValue() software_instance = instance_tree.getSuccessorValue()
self.tic()
software_instance.workflow_history['edit_workflow'] = [{
'comment':'Allocation failed: Allocation disallowed',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'state': 'current',
'time': addToDate(DateTime(), to_add={'day': -4}),
'action': 'edit'
}]
software_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('destroy_requested', instance_tree.getSlapState())
self.assertEqual('archived', instance_tree.getValidationState())
self.assertEqual('start_requested', software_instance.getSlapState())
def test_tryToGarbageCollectNonAllocatedRootTree_script_complexTree(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
request_kw = dict( request_kw = dict(
software_release=\ software_release=\
self.generateNewSoftwareReleaseUrl(), self.generateNewSoftwareReleaseUrl(),
...@@ -803,24 +834,24 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -803,24 +834,24 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
software_title="another %s" % instance_tree.getTitle(), software_title="another %s" % instance_tree.getTitle(),
state='started' state='started'
) )
instance.requestInstance(**request_kw) software_instance.requestInstance(**request_kw)
sub_instance = instance.getSuccessorValue() sub_instance = software_instance.getSuccessorValue()
self.tic() self.tic()
sub_instance.workflow_history['edit_workflow'].append({ sub_instance.workflow_history['edit_workflow'] = [{
'comment':'Allocation failed: no free Compute Partition', 'comment':'Allocation failed: no free Compute Partition',
'error_message': '', 'error_message': '',
'actor': 'ERP5TypeTestCase', 'actor': 'ERP5TypeTestCase',
'slap_state': '', 'state': 'current',
'time': addToDate(DateTime(), to_add={'day': -4}), 'time': addToDate(DateTime(), to_add={'day': -4}),
'action': 'edit' 'action': 'edit'
}) }]
sub_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() sub_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_complex_tree_allocation_disallowed(self): def test_tryToGarbageCollectNonAllocatedRootTree_script_complexTreeAllocationDisallowed(self):
instance = self.createInstance(self.project) instance_tree = self.addInstanceTree()
instance_tree = instance.getSpecialiseValue() software_instance = instance_tree.getSuccessorValue()
request_kw = dict( request_kw = dict(
software_release=\ software_release=\
self.generateNewSoftwareReleaseUrl(), self.generateNewSoftwareReleaseUrl(),
...@@ -831,83 +862,21 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -831,83 +862,21 @@ class TestSlapOSGarbageCollectNonAllocatedRootTreeAlarm(SlapOSTestCaseMixin):
software_title="another %s" % instance_tree.getTitle(), software_title="another %s" % instance_tree.getTitle(),
state='started' state='started'
) )
instance.requestInstance(**request_kw) software_instance.requestInstance(**request_kw)
sub_instance = instance.getSuccessorValue() sub_instance = software_instance.getSuccessorValue()
self.tic() self.tic()
sub_instance.workflow_history['edit_workflow'].append({ sub_instance.workflow_history['edit_workflow'] = [{
'comment':'Allocation failed: Allocation disallowed', 'comment':'Allocation failed: Allocation disallowed',
'error_message': '', 'error_message': '',
'actor': 'ERP5TypeTestCase', 'actor': 'ERP5TypeTestCase',
'slap_state': '', 'state': 'current',
'time': addToDate(DateTime(), to_add={'day': -4}), 'time': addToDate(DateTime(), to_add={'day': -2}),
'action': 'edit' 'action': 'edit'
}) }]
sub_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree() sub_instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('start_requested', instance_tree.getSlapState()) self.assertEqual('start_requested', instance_tree.getSlapState())
def test_tryToGarbageCollect_old_allocation_try_found(self):
instance = self.createInstance(self.project)
instance_tree = instance.getSpecialiseValue()
self.tic()
instance.workflow_history['edit_workflow'].append({
'comment':'Allocation failed: no free Compute Partition',
'error_message': '',
'actor': 'ERP5TypeTestCase',
'slap_state': '',
'time': addToDate(DateTime(), to_add={'day': -8}),
'action': 'edit'
})
instance.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('destroy_requested', instance_tree.getSlapState())
self.assertEqual('archived', instance_tree.getValidationState())
def test_tryToGarbageCollect_old_allocation_try_found_allocation_disallowed(self):
instance = self.createInstance(self.project)
instance_tree = 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.SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree()
self.assertEqual('destroy_requested', instance_tree.getSlapState())
self.assertEqual('archived', instance_tree.getValidationState())
def test_alarm(self):
instance = self.createInstance(self.project)
self._test_alarm(
self.portal.portal_alarms.slapos_garbage_collect_non_allocated_root_tree,
instance,
'SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree'
)
def test_alarm_invalidated(self):
instance = self.createInstance(self.project)
instance.invalidate()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_garbage_collect_non_allocated_root_tree,
instance,
'SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree'
)
def test_alarm_allocated(self):
instance = self.createInstance(self.project)
partition = self.createComputePartition()
instance.edit(aggregate_value=partition)
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_garbage_collect_non_allocated_root_tree,
instance,
'SoftwareInstance_tryToGarbageCollectNonAllocatedRootTree'
)
class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin): class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(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