Commit fcb26053 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fixup slapos_cloud_invalidate_destroyed_instance tests

parent e2903c82
......@@ -1063,114 +1063,110 @@ class TestSlapOSGarbageCollectUnlinkedInstanceAlarm(SlapOSTestCaseMixin):
class TestSlapOSInvalidateDestroyedInstance(SlapOSTestCaseMixin):
#################################################################
# slapos_cloud_invalidate_destroyed_instance
#################################################################
def test_tryToInvalidateIfDestroyed_alarm_softwareInstanceInvalidated(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'invalidated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
self.tic()
def createSoftwareInstance(self):
new_id = self.generateNewId()
return self.portal.software_instance_module.newContent(
portal_type='Software Instance',
title="Test instance %s" % new_id,
reference="TESTINST-%s" % new_id,
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_cloud_invalidate_destroyed_instance,
software_instance,
'SoftwareInstance_tryToInvalidateIfDestroyed'
)
def createComputePartition(self):
new_id = self.generateNewId()
compute_node = self.portal.compute_node_module.newContent(
portal_type='Compute Node',
title="Test compute_node %s" % new_id,
reference="TESTCOMP-%s" % new_id,
def test_tryToInvalidateIfDestroyed_alarm_softwareInstanceMatching(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
self.tic()
self._test_alarm(
self.portal.portal_alarms.slapos_cloud_invalidate_destroyed_instance,
software_instance,
'SoftwareInstance_tryToInvalidateIfDestroyed'
)
compute_partition = compute_node.newContent(
portal_type='Compute Partition',
def test_tryToInvalidateIfDestroyed_alarm_softwareInstanceAllocated(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, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_cloud_invalidate_destroyed_instance,
software_instance,
'SoftwareInstance_tryToInvalidateIfDestroyed'
)
return compute_partition
#################################################################
# SoftwareInstance_tryToInvalidateIfDestroyed
#################################################################
def test_tryToInvalidateIfDestroyed_REQUEST_disallowed(self):
instance = self.createSoftwareInstance()
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.assertRaises(
Unauthorized,
instance.SoftwareInstance_tryToInvalidateIfDestroyed,
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed,
REQUEST={})
def test_tryToInvalidateIfDestroyed_unexpected_context(self):
def test_tryToInvalidateIfDestroyed_script_unexpectedContext(self):
self.assertRaises(
TypeError,
self.portal.SoftwareInstance_tryToInvalidateIfDestroyed,
)
def test_tryToInvalidateIfDestroyed_expected_instance(self):
instance = self.createSoftwareInstance()
self.portal.portal_workflow._jumpToStateFor(instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested')
instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(instance.getValidationState(), "invalidated")
self.assertEqual(instance.getSlapState(), "destroy_requested")
def test_tryToInvalidateIfDestroyed_invalidated_instance(self):
instance = self.createSoftwareInstance()
self.portal.portal_workflow._jumpToStateFor(instance, 'invalidated')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested')
instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(instance.getValidationState(), "invalidated")
self.assertEqual(instance.getSlapState(), "destroy_requested")
def test_tryToInvalidateIfDestroyed_not_destroyed_instance(self):
instance = self.createSoftwareInstance()
self.portal.portal_workflow._jumpToStateFor(instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(instance, 'stop_requested')
instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(instance.getValidationState(), "validated")
self.assertEqual(instance.getSlapState(), "stop_requested")
def test_tryToInvalidateIfDestroyed_allocated_instance(self):
instance = self.createSoftwareInstance()
partition = self.createComputePartition()
instance.edit(aggregate_value=partition)
self.portal.portal_workflow._jumpToStateFor(instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested')
instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(instance.getValidationState(), "validated")
self.assertEqual(instance.getSlapState(), "destroy_requested")
def test_alarm_software_instance_allocated(self):
instance = self.createSoftwareInstance()
partition = self.createComputePartition()
instance.edit(aggregate_value=partition)
self.portal.portal_workflow._jumpToStateFor(instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested')
self.tic()
def test_tryToInvalidateIfDestroyed_script_expectedInstance(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "invalidated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_cloud_invalidate_destroyed_instance,
instance,
'SoftwareInstance_tryToInvalidateIfDestroyed'
)
def test_tryToInvalidateIfDestroyed_script_invalidatedInstance(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'invalidated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "invalidated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
def test_alarm_software_instance_invalidated(self):
instance = self.createSoftwareInstance()
self.createComputePartition()
self.portal.portal_workflow._jumpToStateFor(instance, 'invalidated')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested')
self.tic()
def test_tryToInvalidateIfDestroyed_script_notDestroyedInstance(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'stop_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "validated")
self.assertEqual(software_instance.getSlapState(), "stop_requested")
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_cloud_invalidate_destroyed_instance,
instance,
'SoftwareInstance_tryToInvalidateIfDestroyed'
)
def test_tryToInvalidateIfDestroyed_script_allocatedInstance(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
def test_alarm_software_instance_matching(self):
instance = self.createSoftwareInstance()
self.createComputePartition()
self.portal.portal_workflow._jumpToStateFor(instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(instance, 'destroy_requested')
self.tic()
_, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
software_instance.setAggregateValue(partition)
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance, 'validated')
self.portal.portal_workflow._jumpToStateFor(software_instance, 'destroy_requested')
software_instance.SoftwareInstance_tryToInvalidateIfDestroyed()
self.assertEqual(software_instance.getValidationState(), "validated")
self.assertEqual(software_instance.getSlapState(), "destroy_requested")
self._test_alarm(
self.portal.portal_alarms.slapos_cloud_invalidate_destroyed_instance,
instance,
'SoftwareInstance_tryToInvalidateIfDestroyed'
)
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