Commit 08824550 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: fixup slapos_update_compute_node_capacity_scope tests

parent 51e8990f
......@@ -352,8 +352,12 @@ class SlapOSTestCaseMixin(testSlapOSMixin):
def _makeSlaveTree(self, project, requested_template_id='template_slave_instance'):
return self._makeTree(project, requested_template_id=requested_template_id)
def addComputeNodeAndPartition(self, project):
def addComputeNodeAndPartition(self, project=None):
# XXX replace _makeComputeNode
if project is None:
project = self.addProject()
self.tic()
reference = 'TESTCOMP-%s' % self.generateNewId()
compute_node = self.portal.compute_node_module.newContent(
portal_type="Compute Node",
......
......@@ -423,148 +423,180 @@ class TestSlapOSGarbageCollectDestroyedRootTreeAlarm(SlapOSTestCaseMixin):
class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin):
def afterSetUp(self):
SlapOSTestCaseMixin.afterSetUp(self)
self.project = self.addProject()
self.compute_node = self.portal.compute_node_module.template_compute_node\
.Base_createCloneDocument(batch_mode=1)
self.compute_node.edit(
#################################################################
# slapos_update_compute_node_capacity_scope
#################################################################
def test_ComputeNode_checkAndUpdateCapacityScope_alarm_open(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(
allocation_scope='open',
reference='TESTC-%s' % self.generateNewId(),
follow_up_value=self.project
)
self.compute_node.edit(capacity_scope='open')
self.compute_node.validate()
self.compute_node.setAccessStatus("#access ok")
transaction.commit()
self._test_alarm(
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
def test_ComputeNode_checkAndUpdateCapacityScope_alarm_close(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(
allocation_scope='close',
)
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
def test_ComputeNode_checkAndUpdateCapacityScope(self):
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', self.compute_node.getCapacityScope())
def test_ComputeNode_checkAndUpdateCapacityScope_alarm_invalidated(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.invalidate()
compute_node.edit(
allocation_scope='open',
)
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
def _newComputerModel(self, quantity=None):
computer_model = self.portal.computer_model_module.\
template_computer_model.Base_createCloneDocument(batch_mode=1)
computer_model.edit(capacity_quantity=quantity,
#################################################################
# ComputeNode_checkAndUpdateCapacityScope
#################################################################
def test_ComputeNode_checkAndUpdateCapacityScope_script_open(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.setAccessStatus("#access ok")
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', compute_node.getCapacityScope())
def addComputerModel(self, capacity_quantity=None):
return self.portal.computer_model_module.newContent(
portal_type="Computer Model",
reference='TESTCM-%s' % self.generateNewId(),
capacity_quantity=capacity_quantity
)
return computer_model
def _addPartitionToComputeNode(self):
partition = self.compute_node.newContent(portal_type='Compute Partition',
reference='part1')
partition.markFree()
partition.markBusy()
partition.validate()
self.software_instance.setAggregate(partition.getRelativeUrl())
self.tic()
def test_ComputeNode_checkAndUpdateCapacityScope_model(self):
computer_model = self._newComputerModel(9999)
def test_ComputeNode_checkAndUpdateCapacityScope_script_model(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.setAccessStatus("#access ok")
self.compute_node.edit(specialise_value=computer_model,
capacity_quantity=None)
transaction.commit()
computer_model = self.addComputerModel(9999)
compute_node.edit(specialise_value=computer_model, capacity_quantity=None)
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', self.compute_node.getCapacityScope())
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', compute_node.getCapacityScope())
self.assertEqual(computer_model.getCapacityQuantity(),
self.compute_node.getCapacityQuantity())
compute_node.getCapacityQuantity())
def test_ComputeNode_checkAndUpdateCapacityScope_model_no_capacity(self):
self._makeTree(self.project)
def test_ComputeNode_checkAndUpdateCapacityScope_script_modelNoCapacity(self):
compute_node, partition = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.setAccessStatus("#access ok")
computer_model = self._newComputerModel(1)
self.compute_node.edit(specialise_value=computer_model,
capacity_quantity=None)
computer_model = self.addComputerModel(1)
compute_node.edit(specialise_value=computer_model, capacity_quantity=None)
self._addPartitionToComputeNode()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', self.compute_node.getCapacityScope())
self.assertEqual('Compute Node capacity limit exceeded',
self.compute_node.workflow_history['edit_workflow'][-1]['comment'])
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.setAggregateValue(partition)
partition.markBusy()
self.tic()
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual('Compute Node capacity limit exceeded',
compute_node.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual(computer_model.getCapacityQuantity(),
self.compute_node.getCapacityQuantity())
compute_node.getCapacityQuantity())
def test_ComputeNode_checkAndUpdateCapacityScope_model_has_capacity(self):
def test_ComputeNode_checkAndUpdateCapacityScope_script_modelHasCapacity(self):
# If capacity is set on compute_node, model value is ignored.
self._makeTree(self.project)
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.setAccessStatus("#access ok")
computer_model = self.addComputerModel(1)
compute_node.edit(specialise_value=computer_model, capacity_quantity=2)
computer_model = self._newComputerModel(1)
self.compute_node.edit(specialise_value=computer_model,
capacity_quantity=2)
self.tic()
self._addPartitionToComputeNode()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', self.compute_node.getCapacityScope())
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', compute_node.getCapacityScope())
self.assertEqual(2,
compute_node.getCapacityQuantity())
self.assertNotEqual(computer_model.getCapacityQuantity(),
self.compute_node.getCapacityQuantity())
def test_ComputeNode_checkAndUpdateCapacityScope_with_old_access(self):
def test_ComputeNode_checkAndUpdateCapacityScope_script_withOldAccess(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
try:
self.pinDateTime(addToDate(DateTime(),to_add={'minute': -11}))
self.compute_node.setAccessStatus("#access ok")
compute_node.setAccessStatus("#access ok")
finally:
self.unpinDateTime()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', self.compute_node.getCapacityScope())
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual("Compute Node didn't contact for more than 10 minutes",
self.compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_ComputeNode_checkAndUpdateCapacityScope_no_capacity_quantity(self):
self._makeTree(self.project)
self.compute_node.edit(capacity_quantity=1)
self._addPartitionToComputeNode()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', self.compute_node.getCapacityScope())
compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_ComputeNode_checkAndUpdateCapacityScope_script_noCapacityQuantity(self):
compute_node, partition = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.setAccessStatus("#access ok")
compute_node.edit(capacity_quantity=1)
instance_tree = self.addInstanceTree()
software_instance = instance_tree.getSuccessorValue()
software_instance.setAggregateValue(partition)
partition.markBusy()
self.tic()
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual('Compute Node capacity limit exceeded',
self.compute_node.workflow_history['edit_workflow'][-1]['comment'])
compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_ComputeNode_checkAndUpdateCapacityScope_no_access(self):
self.compute_node.edit(reference='TESTC-%s' % self.generateNewId())
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', self.compute_node.getCapacityScope())
def test_ComputeNode_checkAndUpdateCapacityScope_script_noAccess(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual("Compute Node didn't contact the server",
self.compute_node.workflow_history['edit_workflow'][-1]['comment'])
compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_ComputeNode_checkAndUpdateCapacityScope_close(self):
self.compute_node.edit(capacity_scope='close')
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', self.compute_node.getCapacityScope())
def test_ComputeNode_checkAndUpdateCapacityScope_script_capacityClose(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.setAccessStatus("#access ok")
compute_node.edit(capacity_scope='close')
def test_ComputeNode_checkAndUpdateCapacityScope_with_error(self):
self.compute_node.setAccessStatus('#error not ok')
self.compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', self.compute_node.getCapacityScope())
self.assertEqual("Compute Node reported an error",
self.compute_node.workflow_history['edit_workflow'][-1]['comment'])
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', compute_node.getCapacityScope())
def test_alarm(self):
self._test_alarm(
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
self.compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
def test_ComputeNode_checkAndUpdateCapacityScope_script_withError(self):
compute_node, _ = self.addComputeNodeAndPartition()
compute_node.edit(allocation_scope='open')
compute_node.edit(capacity_scope='open')
compute_node.setAccessStatus('#error not ok')
def test_alarm_non_public(self):
self.compute_node.edit(allocation_scope='close')
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
self.compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual("Compute Node reported an error",
compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_invalidated(self):
self.compute_node.invalidate()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
self.compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
class TestSlapOSGarbageCollectStoppedRootTreeAlarm(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