Rebase LB policy on real capacity of cluster
This makes the LB policy to make policy decisions based on a cluster's real/actual capacity rather than its desired capacity. Change-Id: Ibb5541af6a4865ebbea452ecdcb51869c46584db
This commit is contained in:
parent
40c2a0a64c
commit
5d79494e2e
|
@ -404,7 +404,8 @@ class LoadBalancingPolicy(base.Policy):
|
|||
elif action.action == consts.CLUSTER_RESIZE:
|
||||
# Calculate deletion count based on action input
|
||||
db_cluster = co.Cluster.get(action.context, cluster_id)
|
||||
scaleutils.parse_resize_params(action, db_cluster)
|
||||
current = no.Node.count_by_cluster(action.context, cluster_id)
|
||||
scaleutils.parse_resize_params(action, db_cluster, current)
|
||||
if 'deletion' not in action.data:
|
||||
return []
|
||||
else:
|
||||
|
|
|
@ -302,19 +302,20 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
self.assertEqual(['node1', 'node3'], res)
|
||||
|
||||
@mock.patch.object(no.Node, 'get_all_by_cluster')
|
||||
@mock.patch.object(no.Node, 'count_by_cluster')
|
||||
@mock.patch.object(co.Cluster, 'get')
|
||||
@mock.patch.object(scaleutils, 'parse_resize_params')
|
||||
@mock.patch.object(scaleutils, 'nodes_by_random')
|
||||
def test_get_delete_candidates_no_deletion_data_resize(self,
|
||||
m_nodes_random,
|
||||
m_parse_param,
|
||||
m_cluster_get,
|
||||
m_node_get):
|
||||
def _parse_param(action, cluster):
|
||||
def test_get_delete_candidates_no_deletion_data_resize(
|
||||
self, m_nodes_random, m_parse_param, m_cluster_get, m_node_count,
|
||||
m_node_get):
|
||||
|
||||
def _parse_param(action, cluster, current):
|
||||
action.data = {'deletion': {'count': 2}}
|
||||
|
||||
self.context = utils.dummy_context()
|
||||
action = mock.Mock(action=consts.CLUSTER_RESIZE, data={})
|
||||
m_node_count.return_value = 2
|
||||
m_parse_param.side_effect = _parse_param
|
||||
m_node_get.return_value = ['node1', 'node2', 'node3']
|
||||
m_cluster_get.return_value = 'cluster1'
|
||||
|
@ -325,7 +326,8 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
res = policy._get_delete_candidates('CLUSTERID', action)
|
||||
|
||||
m_cluster_get.assert_called_once_with(action.context, 'CLUSTERID')
|
||||
m_parse_param.assert_called_once_with(action, 'cluster1')
|
||||
m_node_count.assert_called_once_with(action.context, 'CLUSTERID')
|
||||
m_parse_param.assert_called_once_with(action, 'cluster1', 2)
|
||||
m_node_get.assert_called_once_with(action.context, 'CLUSTERID')
|
||||
m_nodes_random.assert_called_once_with(['node1', 'node2', 'node3'], 2)
|
||||
self.assertEqual(['node1', 'node3'], res)
|
||||
|
|
Loading…
Reference in New Issue