Enable region policy to handle NODE_CREATE
This patch enables the region placement policy to handle NODE_CREATE actions originated from a node_create RPC request. If the request is using a profile that has a specific 'region_name' specified, we ignore the region placement policy's decision. Change-Id: Id1517f7e4f2fde6fd46b66fdbaad22f9aa39a4ad
This commit is contained in:
parent
55b6b76c29
commit
415800bc28
@ -44,6 +44,7 @@ class RegionPlacementPolicy(base.Policy):
|
||||
('BEFORE', consts.CLUSTER_SCALE_OUT),
|
||||
('BEFORE', consts.CLUSTER_SCALE_IN),
|
||||
('BEFORE', consts.CLUSTER_RESIZE),
|
||||
('BEFORE', consts.NODE_CREATE),
|
||||
]
|
||||
|
||||
PROFILE_TYPE = [
|
||||
@ -181,6 +182,14 @@ class RegionPlacementPolicy(base.Policy):
|
||||
to create; 2) negative - number of nodes to delete; 3) 0 -
|
||||
something wrong happened, and the policy check failed.
|
||||
"""
|
||||
if action.action == consts.NODE_CREATE:
|
||||
# skip node if the context already contains a region_name
|
||||
profile = action.node.rt['profile']
|
||||
if 'region_name' in profile.properties[profile.CONTEXT]:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
if action.action == consts.CLUSTER_RESIZE:
|
||||
if action.data.get('deletion', None):
|
||||
return -action.data['deletion']['count']
|
||||
|
@ -112,6 +112,27 @@ class TestRegionPlacementPolicy(base.SenlinTestCase):
|
||||
answer = {'R2': 1, 'R3': 1, 'R4': 1}
|
||||
self.assertEqual(answer, plan)
|
||||
|
||||
def test__get_count_node_create_no_region(self):
|
||||
x_profile = mock.Mock(CONTEXT='context', properties={'context': {}})
|
||||
x_node = mock.Mock(rt={'profile': x_profile})
|
||||
action = mock.Mock(action=consts.NODE_CREATE, node=x_node)
|
||||
|
||||
policy = rp.RegionPlacementPolicy('p1', self.spec)
|
||||
|
||||
res = policy._get_count('FOO', action)
|
||||
self.assertEqual(1, res)
|
||||
|
||||
def test__get_count_node_create_region_specified(self):
|
||||
x_profile = mock.Mock(CONTEXT='context',
|
||||
properties={'context': {'region_name': 'foo'}})
|
||||
x_node = mock.Mock(rt={'profile': x_profile})
|
||||
action = mock.Mock(action=consts.NODE_CREATE, node=x_node)
|
||||
|
||||
policy = rp.RegionPlacementPolicy('p1', self.spec)
|
||||
|
||||
res = policy._get_count('FOO', action)
|
||||
self.assertEqual(0, res)
|
||||
|
||||
def test__get_count_resize_deletion(self):
|
||||
action = mock.Mock(action=consts.CLUSTER_RESIZE,
|
||||
data={'deletion': {'count': 3}})
|
||||
|
Loading…
Reference in New Issue
Block a user