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): ...@@ -352,8 +352,12 @@ 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): def addComputeNodeAndPartition(self, project=None):
# XXX replace _makeComputeNode # XXX replace _makeComputeNode
if project is None:
project = self.addProject()
self.tic()
reference = 'TESTCOMP-%s' % self.generateNewId() reference = 'TESTCOMP-%s' % self.generateNewId()
compute_node = self.portal.compute_node_module.newContent( compute_node = self.portal.compute_node_module.newContent(
portal_type="Compute Node", portal_type="Compute Node",
......
...@@ -423,148 +423,180 @@ class TestSlapOSGarbageCollectDestroyedRootTreeAlarm(SlapOSTestCaseMixin): ...@@ -423,148 +423,180 @@ class TestSlapOSGarbageCollectDestroyedRootTreeAlarm(SlapOSTestCaseMixin):
class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin): class TestSlapOSUpdateComputeNodeCapacityScopeAlarm(SlapOSTestCaseMixin):
#################################################################
def afterSetUp(self): # slapos_update_compute_node_capacity_scope
SlapOSTestCaseMixin.afterSetUp(self) #################################################################
self.project = self.addProject() def test_ComputeNode_checkAndUpdateCapacityScope_alarm_open(self):
self.compute_node = self.portal.compute_node_module.template_compute_node\ compute_node, _ = self.addComputeNodeAndPartition()
.Base_createCloneDocument(batch_mode=1) compute_node.edit(
self.compute_node.edit(
allocation_scope='open', allocation_scope='open',
reference='TESTC-%s' % self.generateNewId(),
follow_up_value=self.project
) )
self.compute_node.edit(capacity_scope='open') self._test_alarm(
self.compute_node.validate() self.portal.portal_alarms.slapos_update_compute_node_capacity_scope,
self.compute_node.setAccessStatus("#access ok") compute_node,
transaction.commit() '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): def test_ComputeNode_checkAndUpdateCapacityScope_alarm_invalidated(self):
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node, _ = self.addComputeNodeAndPartition()
self.assertEqual('open', self.compute_node.getCapacityScope()) 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.\ # ComputeNode_checkAndUpdateCapacityScope
template_computer_model.Base_createCloneDocument(batch_mode=1) #################################################################
computer_model.edit(capacity_quantity=quantity, 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(), 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): def test_ComputeNode_checkAndUpdateCapacityScope_script_model(self):
computer_model = self._newComputerModel(9999) 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, computer_model = self.addComputerModel(9999)
capacity_quantity=None) compute_node.edit(specialise_value=computer_model, capacity_quantity=None)
transaction.commit()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('open', self.compute_node.getCapacityScope()) self.assertEqual('open', compute_node.getCapacityScope())
self.assertEqual(computer_model.getCapacityQuantity(), self.assertEqual(computer_model.getCapacityQuantity(),
self.compute_node.getCapacityQuantity()) compute_node.getCapacityQuantity())
def test_ComputeNode_checkAndUpdateCapacityScope_model_no_capacity(self): def test_ComputeNode_checkAndUpdateCapacityScope_script_modelNoCapacity(self):
self._makeTree(self.project) 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) computer_model = self.addComputerModel(1)
self.compute_node.edit(specialise_value=computer_model, compute_node.edit(specialise_value=computer_model, capacity_quantity=None)
capacity_quantity=None)
self._addPartitionToComputeNode() instance_tree = self.addInstanceTree()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() software_instance = instance_tree.getSuccessorValue()
self.assertEqual('close', self.compute_node.getCapacityScope()) software_instance.setAggregateValue(partition)
self.assertEqual('Compute Node capacity limit exceeded', partition.markBusy()
self.compute_node.workflow_history['edit_workflow'][-1]['comment'])
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.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. # 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.tic()
self.compute_node.edit(specialise_value=computer_model,
capacity_quantity=2)
self._addPartitionToComputeNode() compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() self.assertEqual('open', compute_node.getCapacityScope())
self.assertEqual('open', self.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: try:
self.pinDateTime(addToDate(DateTime(),to_add={'minute': -11})) self.pinDateTime(addToDate(DateTime(),to_add={'minute': -11}))
self.compute_node.setAccessStatus("#access ok") compute_node.setAccessStatus("#access ok")
finally: finally:
self.unpinDateTime() self.unpinDateTime()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.assertEqual('close', self.compute_node.getCapacityScope()) self.assertEqual('close', compute_node.getCapacityScope())
self.assertEqual("Compute Node didn't contact for more than 10 minutes", self.assertEqual("Compute Node didn't contact for more than 10 minutes",
self.compute_node.workflow_history['edit_workflow'][-1]['comment']) compute_node.workflow_history['edit_workflow'][-1]['comment'])
def test_ComputeNode_checkAndUpdateCapacityScope_no_capacity_quantity(self): def test_ComputeNode_checkAndUpdateCapacityScope_script_noCapacityQuantity(self):
self._makeTree(self.project) compute_node, partition = self.addComputeNodeAndPartition()
self.compute_node.edit(capacity_quantity=1) compute_node.edit(allocation_scope='open')
self._addPartitionToComputeNode() compute_node.edit(capacity_scope='open')
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node.setAccessStatus("#access ok")
self.assertEqual('close', self.compute_node.getCapacityScope()) 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.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): def test_ComputeNode_checkAndUpdateCapacityScope_script_noAccess(self):
self.compute_node.edit(reference='TESTC-%s' % self.generateNewId()) compute_node, _ = self.addComputeNodeAndPartition()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node.edit(allocation_scope='open')
self.assertEqual('close', self.compute_node.getCapacityScope()) 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.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): def test_ComputeNode_checkAndUpdateCapacityScope_script_capacityClose(self):
self.compute_node.edit(capacity_scope='close') compute_node, _ = self.addComputeNodeAndPartition()
self.compute_node.ComputeNode_checkAndUpdateCapacityScope() compute_node.edit(allocation_scope='open')
self.assertEqual('open', self.compute_node.getCapacityScope()) compute_node.setAccessStatus("#access ok")
compute_node.edit(capacity_scope='close')
def test_ComputeNode_checkAndUpdateCapacityScope_with_error(self): compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.compute_node.setAccessStatus('#error not ok') self.assertEqual('open', compute_node.getCapacityScope())
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'])
def test_alarm(self): def test_ComputeNode_checkAndUpdateCapacityScope_script_withError(self):
self._test_alarm( compute_node, _ = self.addComputeNodeAndPartition()
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope, compute_node.edit(allocation_scope='open')
self.compute_node, compute_node.edit(capacity_scope='open')
'ComputeNode_checkAndUpdateCapacityScope' compute_node.setAccessStatus('#error not ok')
)
def test_alarm_non_public(self): compute_node.ComputeNode_checkAndUpdateCapacityScope()
self.compute_node.edit(allocation_scope='close') self.assertEqual('close', compute_node.getCapacityScope())
self._test_alarm_not_visited( self.assertEqual("Compute Node reported an error",
self.portal.portal_alarms.slapos_update_compute_node_capacity_scope, compute_node.workflow_history['edit_workflow'][-1]['comment'])
self.compute_node,
'ComputeNode_checkAndUpdateCapacityScope'
)
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): 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