Remove unused batch_num variable.

Change-Id: I38f47be07bc8b77d42f38a182902e370b606f6d2
This commit is contained in:
Jacob 2019-02-07 09:24:32 -08:00
parent 8bc176742c
commit 97cd02b0aa
2 changed files with 13 additions and 20 deletions

View File

@ -96,7 +96,7 @@ class BatchPolicy(base.Policy):
"""Get batch size for update operation.
:param total: Total number of nodes.
:returns: Size of each batch and number of batches.
:returns: Size of each batch.
"""
# if the number of nodes less than min_in_service,
@ -111,16 +111,13 @@ class BatchPolicy(base.Policy):
else:
batch_size = self.max_batch_size
batch_num = int(math.ceil(float(total) / float(batch_size)))
return batch_size
return batch_size, batch_num
def _pick_nodes(self, nodes, batch_size, batch_num):
def _pick_nodes(self, nodes, batch_size):
"""Select nodes based on size and number of batches.
:param nodes: list of node objects.
:param batch_size: the number of nodes of each batch.
:param batch_num: the number of batches.
:returns: a list of sets containing the nodes' IDs we
selected based on the input params.
"""
@ -146,8 +143,8 @@ class BatchPolicy(base.Policy):
plan['plan'] = []
return True, plan
batch_size, batch_num = self._get_batch_size(len(nodes))
plan['plan'] = self._pick_nodes(nodes, batch_size, batch_num)
batch_size = self._get_batch_size(len(nodes))
plan['plan'] = self._pick_nodes(nodes, batch_size)
return True, plan

View File

@ -45,39 +45,35 @@ class TestBatchPolicy(base.SenlinTestCase):
def test_get_batch_size(self):
policy = bp.BatchPolicy('test-batch', self.spec)
size, number = policy._get_batch_size(5)
size = policy._get_batch_size(5)
self.assertEqual(2, size)
self.assertEqual(3, number)
def test_get_batch_size_less_than_max(self):
spec = copy.deepcopy(self.spec)
spec['properties']['max_batch_size'] = 3
policy = bp.BatchPolicy('test-batch', spec)
size, number = policy._get_batch_size(3)
size = policy._get_batch_size(3)
self.assertEqual(2, size)
self.assertEqual(2, number)
def test_get_batch_size_less_than_min(self):
spec = copy.deepcopy(self.spec)
spec['properties']['min_in_service'] = 2
policy = bp.BatchPolicy('test-batch', spec)
size, number = policy._get_batch_size(1)
size = policy._get_batch_size(1)
self.assertEqual(1, size)
self.assertEqual(1, number)
def test_get_batch_size_with_default_max(self):
spec = copy.deepcopy(self.spec)
spec['properties']['max_batch_size'] = -1
policy = bp.BatchPolicy('test-batch', spec)
size, number = policy._get_batch_size(5)
size = policy._get_batch_size(5)
self.assertEqual(4, size)
self.assertEqual(2, number)
def test_pick_nodes_all_active(self):
node1 = mock.Mock(id='1', status='ACTIVE')
@ -86,7 +82,7 @@ class TestBatchPolicy(base.SenlinTestCase):
nodes = [node1, node2, node3]
policy = bp.BatchPolicy('test-batch', self.spec)
nodes = policy._pick_nodes(nodes, 2, 2)
nodes = policy._pick_nodes(nodes, 2)
self.assertEqual(2, len(nodes))
self.assertIn(node1.id, nodes[0])
@ -101,7 +97,7 @@ class TestBatchPolicy(base.SenlinTestCase):
policy = bp.BatchPolicy('test-batch', self.spec)
nodes = policy._pick_nodes(nodes, 2, 2)
nodes = policy._pick_nodes(nodes, 2)
self.assertEqual(2, len(nodes))
self.assertIn(node3.id, nodes[0])
@ -117,7 +113,7 @@ class TestBatchPolicy(base.SenlinTestCase):
cluster.nodes = [node1, node2, node3]
action.entity = cluster
mock_cal.return_value = (2, 2)
mock_cal.return_value = 2
mock_pick.return_value = [{'1', '2'}, {'3'}]
policy = bp.BatchPolicy('test-batch', self.spec)
@ -130,7 +126,7 @@ class TestBatchPolicy(base.SenlinTestCase):
}
self.assertEqual(excepted_plan, plan)
mock_cal.assert_called_once_with(3)
mock_pick.assert_called_once_with([node1, node2, node3], 2, 2)
mock_pick.assert_called_once_with([node1, node2, node3], 2)
def test_create_plan_for_update_no_node(self):
action = mock.Mock(context=self.context, action='CLUSTER_UPDATE')