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