Commit 64e0c507 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: more slapos_free_compute_partition tests

parent 3d185d29
......@@ -145,6 +145,26 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
'SoftwareInstance_tryToUnallocatePartition'
)
def test_SoftwareInstance_tryToUnallocatePartition_alarm_sharedAndAllocated(self):
instance_tree = self.addInstanceTree(shared=True)
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,
'destroy_requested')
# invalidate transition triggers the alarm
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.tic()
self._test_alarm(
self.portal.portal_alarms.slapos_free_compute_partition,
software_instance,
'SoftwareInstance_tryToUnallocatePartition'
)
def test_SoftwareInstance_tryToUnallocatePartition_alarm_unallocated(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
......@@ -214,6 +234,21 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
self.assertEqual(None, software_instance.getAggregate())
self.assertEqual('free', partition.getSlapState())
def test_SoftwareInstance_tryToUnallocatePartition_script_sharedAndAllocated(self):
instance_tree = self.addInstanceTree(shared=True)
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,
'destroy_requested')
self.tic()
software_instance.SoftwareInstance_tryToUnallocatePartition()
self.assertEqual(None, software_instance.getAggregate())
self.assertEqual('free', partition.getSlapState())
def test_SoftwareInstance_tryToUnallocatePartition_script_concurrency(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
......@@ -260,38 +295,18 @@ class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
self.assertEqual('busy', partition.getSlapState())
self.assertEqual(partition.getRelativeUrl(), software_instance2.getAggregate())
def test_SoftwareInstance_tryToUnallocatePartition_script_notDestroyed(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
_, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
class TestSlapOSFreeComputePartitionAlarmWithSlave(SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
self._makeTree(self.project,
requested_template_id='template_slave_instance')
def test_SoftwareInstance_tryToUnallocatePartition(self):
self._makeComputeNode(self.project)
self.software_instance.setAggregate(self.partition.getRelativeUrl())
self.partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(self.software_instance,
'destroy_requested')
self.tic()
self.software_instance.SoftwareInstance_tryToUnallocatePartition()
self.tic()
self.assertEqual(None, self.software_instance.getAggregate())
self.assertEqual('free', self.partition.getSlapState())
def test_SoftwareInstance_tryToUnallocatePartition_nonDestroyed(self):
self._makeComputeNode(self.project)
self.software_instance.setAggregate(self.partition.getRelativeUrl())
self.partition.markBusy()
software_instance.setAggregateValue(partition)
partition.markBusy()
self.tic()
self.software_instance.SoftwareInstance_tryToUnallocatePartition()
self.tic()
self.assertEqual(self.partition.getRelativeUrl(),
self.software_instance.getAggregate())
self.assertEqual('busy', self.partition.getSlapState())
software_instance.SoftwareInstance_tryToUnallocatePartition()
self.assertEqual(partition.getRelativeUrl(), software_instance.getAggregate())
self.assertEqual('busy', partition.getSlapState())
class TestSlapOSGarbageCollectDestroyedRootTreeAlarm(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