Enable LB policy to handle NODE_DELETE

This patch enables the LB policy to handle standalone NODE_DELETE
actions, i.e. NODE_DELETE actions originated from node_delete RPC
requests.

Change-Id: I1bb51fe3b77bdec1a9bbecef437c54936247cb5d
This commit is contained in:
tengqm 2016-07-21 22:43:54 -04:00
parent e42bb458e1
commit 99d3e998c4
2 changed files with 16 additions and 1 deletions

View File

@ -56,6 +56,7 @@ class LoadBalancingPolicy(base.Policy):
('BEFORE', consts.CLUSTER_DEL_NODES),
('BEFORE', consts.CLUSTER_SCALE_IN),
('BEFORE', consts.CLUSTER_RESIZE),
('BEFORE', consts.NODE_DELETE),
]
PROFILE_TYPE = [
@ -366,7 +367,10 @@ class LoadBalancingPolicy(base.Policy):
# policy or deletion policy is attached.
candidates = None
if deletion is None:
if action.action == consts.CLUSTER_DEL_NODES:
if action.action == consts.NODE_DELETE:
candidates = [action.node.id]
count = 1
elif action.action == consts.CLUSTER_DEL_NODES:
# Get candidates from action.input
candidates = action.inputs.get('candidates', [])
count = len(candidates)

View File

@ -224,6 +224,17 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
self.assertEqual((False, 'Failed in adding node into lb pool'), res)
self.lb_driver.lb_delete.assert_called_once_with(**lb_data)
def test_get_delete_candidates_for_node_delete(self):
action = mock.Mock()
action.data = {}
action.action = consts.NODE_DELETE
action.node = mock.Mock(id='NODE_ID')
action.inputs = {}
policy = lb_policy.LoadBalancingPolicy('test-policy', self.spec)
res = policy._get_delete_candidates('CLUSTERID', action)
self.assertEqual(['NODE_ID'], res)
def test_get_delete_candidates_no_deletion_data_del_nodes(self):
action = mock.Mock()
action.data = {}