From 407dd98fc2381013aa6153e3a793e80303770912 Mon Sep 17 00:00:00 2001 From: Brian Elliott Date: Mon, 13 May 2013 08:38:56 +0000 Subject: Cell weighing class to handle mute child cells Give negative weight to child cells that have not recently sent capability or capacity updates to their parent cell. Change-Id: I7cada3e1b6f04c48b71c82d8e0a8527e44674abd --- nova/tests/cells/test_cells_weights.py | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/cells/test_cells_weights.py b/nova/tests/cells/test_cells_weights.py index ca01e9939..38618bc64 100644 --- a/nova/tests/cells/test_cells_weights.py +++ b/nova/tests/cells/test_cells_weights.py @@ -18,8 +18,11 @@ Unit Tests for testing the cells weight algorithms. Cells with higher weights should be given priority for new builds. """ +import datetime + from nova.cells import state from nova.cells import weights +from nova.openstack.common import timeutils from nova import test @@ -163,3 +166,52 @@ class WeightOffsetWeigherTestClass(_WeigherTestClass): expected_cells = [cells[2], cells[3], cells[0], cells[1]] resulting_cells = [weighed_cell.obj for weighed_cell in weighed_cells] self.assertEqual(expected_cells, resulting_cells) + + +class MuteWeigherTestClass(_WeigherTestClass): + weigher_cls_name = 'nova.cells.weights.mute_child.MuteChildWeigher' + + def setUp(self): + super(MuteWeigherTestClass, self).setUp() + self.flags(mute_weight_multiplier=-10.0, mute_child_interval=100, + mute_weight_value=1000.0, group='cells') + + self.now = timeutils.utcnow() + timeutils.set_time_override(self.now) + + self.cells = _get_fake_cells() + for cell in self.cells: + cell.last_seen = self.now + + def tearDown(self): + super(MuteWeigherTestClass, self).tearDown() + timeutils.clear_time_override() + + def test_non_mute(self): + weight_properties = {} + weighed_cells = self._get_weighed_cells(self.cells, weight_properties) + self.assertEqual(len(weighed_cells), 4) + + for weighed_cell in weighed_cells: + self.assertEqual(0, weighed_cell.weight) + + def test_mutes(self): + # make 2 of them mute: + self.cells[0].last_seen = (self.cells[0].last_seen - + datetime.timedelta(seconds=200)) + self.cells[1].last_seen = (self.cells[1].last_seen - + datetime.timedelta(seconds=200)) + + weight_properties = {} + weighed_cells = self._get_weighed_cells(self.cells, weight_properties) + self.assertEqual(len(weighed_cells), 4) + + for i in range(2): + weighed_cell = weighed_cells.pop(0) + self.assertEqual(0, weighed_cell.weight) + self.assertIn(weighed_cell.obj.name, ['cell3', 'cell4']) + + for i in range(2): + weighed_cell = weighed_cells.pop(0) + self.assertEqual(1000 * -10.0, weighed_cell.weight) + self.assertIn(weighed_cell.obj.name, ['cell1', 'cell2']) -- cgit