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