Changing property of external_segments for L3P
To a format: external_segments: - external_segement_id: <es_id> - allocated_address: <ip> This allows using a Heat resource ID for "es_id" (earlier one had to specify the actual GBP ES id, so it was not possible to reference a ES created earlier in the same Heat template). Change-Id: I782fdb6cf1109f9662acd623ccbbc1687924bb60 Closes-bug: 1490773
This commit is contained in:
parent
9c5f645947
commit
c56d940da4
|
@ -368,8 +368,8 @@ class L3Policy(gbpresource.GBPResource):
|
||||||
update_allowed=True
|
update_allowed=True
|
||||||
),
|
),
|
||||||
EXTERNAL_SEGMENTS: properties.Schema(
|
EXTERNAL_SEGMENTS: properties.Schema(
|
||||||
properties.Schema.MAP,
|
properties.Schema.LIST,
|
||||||
_('External segments of L3 policy.'),
|
_('External segments for L3 policy.'),
|
||||||
update_allowed=True
|
update_allowed=True
|
||||||
),
|
),
|
||||||
SHARED: properties.Schema(
|
SHARED: properties.Schema(
|
||||||
|
@ -392,6 +392,21 @@ class L3Policy(gbpresource.GBPResource):
|
||||||
if self.properties.get(key) is not None:
|
if self.properties.get(key) is not None:
|
||||||
props[key] = self.properties.get(key)
|
props[key] = self.properties.get(key)
|
||||||
|
|
||||||
|
external_segments_dict = {}
|
||||||
|
props_external_segments = props.get(
|
||||||
|
'external_segments', [])
|
||||||
|
|
||||||
|
for prop_external_segment in props_external_segments:
|
||||||
|
external_segment_id = (
|
||||||
|
prop_external_segment['external_segment_id'])
|
||||||
|
allocated_address = (
|
||||||
|
prop_external_segment['allocated_address'])
|
||||||
|
external_segments_dict.update({external_segment_id:
|
||||||
|
allocated_address})
|
||||||
|
|
||||||
|
if external_segments_dict:
|
||||||
|
props['external_segments'] = external_segments_dict
|
||||||
|
|
||||||
l3_policy = client.create_l3_policy(
|
l3_policy = client.create_l3_policy(
|
||||||
{'l3_policy': props})['l3_policy']
|
{'l3_policy': props})['l3_policy']
|
||||||
|
|
||||||
|
@ -411,6 +426,20 @@ class L3Policy(gbpresource.GBPResource):
|
||||||
|
|
||||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||||
if prop_diff:
|
if prop_diff:
|
||||||
|
external_segments_dict = {}
|
||||||
|
props_external_segments = prop_diff.get(
|
||||||
|
'external_segments', [])
|
||||||
|
|
||||||
|
for prop_external_segment in props_external_segments:
|
||||||
|
external_segment_id = (
|
||||||
|
prop_external_segment['external_segment_id'])
|
||||||
|
allocated_address = (
|
||||||
|
prop_external_segment['allocated_address'])
|
||||||
|
external_segments_dict.update({external_segment_id:
|
||||||
|
allocated_address})
|
||||||
|
|
||||||
|
if external_segments_dict:
|
||||||
|
prop_diff['external_segments'] = external_segments_dict
|
||||||
self.grouppolicy().update_l3_policy(
|
self.grouppolicy().update_l3_policy(
|
||||||
self.resource_id, {'l3_policy': prop_diff})
|
self.resource_id, {'l3_policy': prop_diff})
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,10 @@ l3_policy_template = '''
|
||||||
"description": "test L3 policy resource",
|
"description": "test L3 policy resource",
|
||||||
"ip_version": "4",
|
"ip_version": "4",
|
||||||
"ip_pool": "10.20.20.0",
|
"ip_pool": "10.20.20.0",
|
||||||
|
"external_segments": [
|
||||||
|
{"external_segment_id": "es1",
|
||||||
|
"allocated_address": "1.1.1.1"},
|
||||||
|
],
|
||||||
"subnet_prefix_length": 24,
|
"subnet_prefix_length": 24,
|
||||||
"shared": True
|
"shared": True
|
||||||
}
|
}
|
||||||
|
@ -720,6 +724,7 @@ class L3PolicyTest(HeatTestCase):
|
||||||
"ip_version": "4",
|
"ip_version": "4",
|
||||||
"ip_pool": "10.20.20.0",
|
"ip_pool": "10.20.20.0",
|
||||||
"subnet_prefix_length": 24,
|
"subnet_prefix_length": 24,
|
||||||
|
"external_segments": {"es1": "1.1.1.1"},
|
||||||
"shared": True
|
"shared": True
|
||||||
}
|
}
|
||||||
}).AndReturn({'l3_policy': {'id': '5678'}})
|
}).AndReturn({'l3_policy': {'id': '5678'}})
|
||||||
|
@ -745,6 +750,7 @@ class L3PolicyTest(HeatTestCase):
|
||||||
"ip_version": "4",
|
"ip_version": "4",
|
||||||
"ip_pool": "10.20.20.0",
|
"ip_pool": "10.20.20.0",
|
||||||
"subnet_prefix_length": 24,
|
"subnet_prefix_length": 24,
|
||||||
|
"external_segments": {"es1": "1.1.1.1"},
|
||||||
"shared": True
|
"shared": True
|
||||||
}
|
}
|
||||||
}).AndRaise(grouppolicy.NeutronClientException())
|
}).AndRaise(grouppolicy.NeutronClientException())
|
||||||
|
@ -807,12 +813,17 @@ class L3PolicyTest(HeatTestCase):
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
rsrc = self.create_l3_policy()
|
rsrc = self.create_l3_policy()
|
||||||
gbpclient.Client.update_l3_policy(
|
gbpclient.Client.update_l3_policy(
|
||||||
'5678', {'l3_policy': {'subnet_prefix_length': 28}})
|
'5678', {'l3_policy': {'subnet_prefix_length': 28,
|
||||||
|
'external_segments':
|
||||||
|
{'es2': '2.1.1.1'}}})
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
scheduler.TaskRunner(rsrc.create)()
|
scheduler.TaskRunner(rsrc.create)()
|
||||||
|
|
||||||
update_template = copy.deepcopy(rsrc.t)
|
update_template = copy.deepcopy(rsrc.t)
|
||||||
update_template['Properties']['subnet_prefix_length'] = 28
|
update_template['Properties']['subnet_prefix_length'] = 28
|
||||||
|
update_template['Properties']['external_segments'] = [
|
||||||
|
{'external_segment_id': 'es2',
|
||||||
|
'allocated_address': '2.1.1.1'}]
|
||||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||||
|
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
Loading…
Reference in New Issue