Commit 34c0ca72 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fixup slapos_free_compute_partition tests

parent 748aa612
...@@ -352,6 +352,33 @@ class SlapOSTestCaseMixin(testSlapOSMixin): ...@@ -352,6 +352,33 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
def _makeSlaveTree(self, project, requested_template_id='template_slave_instance'): def _makeSlaveTree(self, project, requested_template_id='template_slave_instance'):
return self._makeTree(project, requested_template_id=requested_template_id) return self._makeTree(project, requested_template_id=requested_template_id)
def addComputeNodeAndPartition(self, project):
# XXX replace _makeComputeNode
reference = 'TESTCOMP-%s' % self.generateNewId()
compute_node = self.portal.compute_node_module.newContent(
portal_type="Compute Node",
#allocation_scope=allocation_scope,
reference=reference,
title=reference,
follow_up_value=project
)
# The edit above will update capacity scope due the interaction workflow
# The line above force capacity scope to be open, keeping the previous
# behaviour.
compute_node.edit(capacity_scope='open')
compute_node.validate()
reference = 'TESTPART-%s' % self.generateNewId()
partition = compute_node.newContent(
portal_type='Compute Partition',
reference=reference,
title=reference
)
partition.markFree()
partition.validate()
return compute_node, partition
def _makeComputeNode(self, project, allocation_scope='open'): def _makeComputeNode(self, project, allocation_scope='open'):
self.compute_node = self.portal.compute_node_module.template_compute_node\ self.compute_node = self.portal.compute_node_module.template_compute_node\
.Base_createCloneDocument(batch_mode=1) .Base_createCloneDocument(batch_mode=1)
......
...@@ -9,7 +9,7 @@ from erp5.component.module.DateUtils import addToDate ...@@ -9,7 +9,7 @@ from erp5.component.module.DateUtils import addToDate
class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(SlapOSTestCaseMixin): class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(SlapOSTestCaseMixin):
################################################################# #################################################################
# InstanceTree_assertSuccessor # slapos_assert_instance_tree_successor
################################################################# #################################################################
def test_InstanceTree_assertSuccessor_alarm_orphaned(self): def test_InstanceTree_assertSuccessor_alarm_orphaned(self):
instance_tree = self.portal.instance_tree_module.newContent( instance_tree = self.portal.instance_tree_module.newContent(
...@@ -120,115 +120,147 @@ class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(SlapOSTestCaseMixin): ...@@ -120,115 +120,147 @@ class TestSlapOSCoreSlapOSAssertInstanceTreeSuccessorAlarm(SlapOSTestCaseMixin):
instance_tree.getSuccessorTitleList()) instance_tree.getSuccessorTitleList())
#################################################################
# slapos_free_compute_partition
#################################################################
class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin): class TestSlapOSFreeComputePartitionAlarm(SlapOSTestCaseMixin):
def afterSetUp(self): #################################################################
SlapOSTestCaseMixin.afterSetUp(self) # slapos_free_compute_partition
self.project = self.addProject() #################################################################
self._makeTree(self.project) def test_SoftwareInstance_tryToUnallocatePartition_alarm_allocated(self):
instance_tree = self.addInstanceTree()
def test_SoftwareInstance_tryToUnallocatePartition(self): software_instance = instance_tree.getSuccessorValue()
self._makeComputeNode(self.project) _, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
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_concurrency(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.partition.activate(tag="allocate_%s" % self.partition.getRelativeUrl()\
).getId()
transaction.commit()
self.software_instance.SoftwareInstance_tryToUnallocatePartition()
self.tic()
self.assertEqual(self.partition.getRelativeUrl(),
self.software_instance.getAggregate())
self.assertEqual('busy', self.partition.getSlapState())
def test_SoftwareInstance_tryToUnallocatePartition_twoInstances(self):
software_instance = self.portal.software_instance_module\
.template_software_instance.Base_createCloneDocument(batch_mode=1)
self._makeComputeNode(self.project) software_instance.setAggregateValue(partition)
self.software_instance.setAggregate(self.partition.getRelativeUrl()) partition.markBusy()
software_instance.setAggregate(self.partition.getRelativeUrl()) self.portal.portal_workflow._jumpToStateFor(software_instance,
self.partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(self.software_instance,
'destroy_requested') 'destroy_requested')
self.tic() # invalidate transition triggers the alarm
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.software_instance.SoftwareInstance_tryToUnallocatePartition()
self.tic() self.tic()
self.assertEqual(None, self.software_instance.getAggregate())
self.assertEqual('busy', self.partition.getSlapState())
self.assertEqual(self.partition.getRelativeUrl(), software_instance.getAggregate())
def test_alarm_allocated(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.software_instance.invalidate()
self._test_alarm( self._test_alarm(
self.portal.portal_alarms.slapos_free_compute_partition, self.portal.portal_alarms.slapos_free_compute_partition,
self.software_instance, software_instance,
'SoftwareInstance_tryToUnallocatePartition' 'SoftwareInstance_tryToUnallocatePartition'
) )
def test_alarm_unallocated(self): def test_SoftwareInstance_tryToUnallocatePartition_alarm_unallocated(self):
self._makeComputeNode(self.project) instance_tree = self.addInstanceTree()
self.partition.markBusy() software_instance = instance_tree.getSuccessorValue()
self.portal.portal_workflow._jumpToStateFor(self.software_instance, _, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested') 'destroy_requested')
self.software_instance.invalidate() # invalidate transition triggers the alarm
self.portal.portal_workflow._jumpToStateFor(software_instance,
'invalidated')
self.tic()
self._test_alarm_not_visited( self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_free_compute_partition, self.portal.portal_alarms.slapos_free_compute_partition,
self.software_instance, software_instance,
'SoftwareInstance_tryToUnallocatePartition' 'SoftwareInstance_tryToUnallocatePartition'
) )
def test_alarm_validated(self): def test_SoftwareInstance_tryToUnallocatePartition_alarm_allocatedAndValidated(self):
self._makeComputeNode(self.project) instance_tree = self.addInstanceTree()
self.software_instance.setAggregate(self.partition.getRelativeUrl()) software_instance = instance_tree.getSuccessorValue()
self.partition.markBusy() _, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
self.portal.portal_workflow._jumpToStateFor(self.software_instance,
software_instance.setAggregateValue(partition)
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested') 'destroy_requested')
self.tic()
self._test_alarm_not_visited( self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_free_compute_partition, self.portal.portal_alarms.slapos_free_compute_partition,
self.software_instance, software_instance,
'SoftwareInstance_tryToUnallocatePartition' 'SoftwareInstance_tryToUnallocatePartition'
) )
def test_alarm_start_requested(self): def test_SoftwareInstance_tryToUnallocatePartition_alarm_allocatedAndStarted(self):
self._makeComputeNode(self.project) instance_tree = self.addInstanceTree()
self.software_instance.setAggregate(self.partition.getRelativeUrl()) software_instance = instance_tree.getSuccessorValue()
self.partition.markBusy() _, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
software_instance.setAggregateValue(partition)
partition.markBusy()
self.tic()
self._test_alarm_not_visited( self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_free_compute_partition, self.portal.portal_alarms.slapos_free_compute_partition,
self.software_instance, software_instance,
'SoftwareInstance_tryToUnallocatePartition' 'SoftwareInstance_tryToUnallocatePartition'
) )
#################################################################
# SoftwareInstance_tryToUnallocatePartition
#################################################################
def test_SoftwareInstance_tryToUnallocatePartition_script_allocated(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,
'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()
_, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
software_instance.setAggregateValue(partition)
partition.markBusy()
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
self.tic()
partition.activate(tag="allocate_%s" % partition.getRelativeUrl()\
).getId()
transaction.commit()
software_instance.SoftwareInstance_tryToUnallocatePartition()
self.assertEqual(partition.getRelativeUrl(),
software_instance.getAggregate())
self.assertEqual('busy', partition.getSlapState())
def test_SoftwareInstance_tryToUnallocatePartition_script_twoInstances(self):
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
_, partition = self.addComputeNodeAndPartition(project=instance_tree.getFollowUpValue())
instance_tree2 = self.addInstanceTree(project=instance_tree.getFollowUpValue())
software_instance2 = instance_tree2.getSuccessorValue()
self.tic()
# Prevent calling interaction workflows
software_instance.setCategoryList(
software_instance.getCategoryList() + ['aggregate/%s' % partition.getRelativeUrl()]
)
software_instance2.setCategoryList(
software_instance2.getCategoryList() + ['aggregate/%s' % partition.getRelativeUrl()]
)
self.portal.portal_workflow._jumpToStateFor(partition,
'busy')
self.portal.portal_workflow._jumpToStateFor(software_instance,
'destroy_requested')
self.tic()
software_instance.SoftwareInstance_tryToUnallocatePartition()
self.assertEqual(None, software_instance.getAggregate())
self.assertEqual('busy', partition.getSlapState())
self.assertEqual(partition.getRelativeUrl(), software_instance2.getAggregate())
class TestSlapOSFreeComputePartitionAlarmWithSlave(SlapOSTestCaseMixin): class TestSlapOSFreeComputePartitionAlarmWithSlave(SlapOSTestCaseMixin):
def afterSetUp(self): def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self) SlapOSTestCaseMixin.afterSetUp(self)
......
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