Browse Source

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
Sumit Naiksatam 3 years ago
parent
commit
c56d940da4

+ 31
- 2
gbpautomation/heat/engine/resources/grouppolicy.py View File

@@ -368,8 +368,8 @@ class L3Policy(gbpresource.GBPResource):
368 368
             update_allowed=True
369 369
         ),
370 370
         EXTERNAL_SEGMENTS: properties.Schema(
371
-            properties.Schema.MAP,
372
-            _('External segments of L3 policy.'),
371
+            properties.Schema.LIST,
372
+            _('External segments for L3 policy.'),
373 373
             update_allowed=True
374 374
         ),
375 375
         SHARED: properties.Schema(
@@ -392,6 +392,21 @@ class L3Policy(gbpresource.GBPResource):
392 392
             if self.properties.get(key) is not None:
393 393
                 props[key] = self.properties.get(key)
394 394
 
395
+        external_segments_dict = {}
396
+        props_external_segments = props.get(
397
+            'external_segments', [])
398
+
399
+        for prop_external_segment in props_external_segments:
400
+            external_segment_id = (
401
+                prop_external_segment['external_segment_id'])
402
+            allocated_address = (
403
+                prop_external_segment['allocated_address'])
404
+            external_segments_dict.update({external_segment_id:
405
+                                           allocated_address})
406
+
407
+        if external_segments_dict:
408
+            props['external_segments'] = external_segments_dict
409
+
395 410
         l3_policy = client.create_l3_policy(
396 411
             {'l3_policy': props})['l3_policy']
397 412
 
@@ -411,6 +426,20 @@ class L3Policy(gbpresource.GBPResource):
411 426
 
412 427
     def handle_update(self, json_snippet, tmpl_diff, prop_diff):
413 428
         if prop_diff:
429
+            external_segments_dict = {}
430
+            props_external_segments = prop_diff.get(
431
+                'external_segments', [])
432
+
433
+            for prop_external_segment in props_external_segments:
434
+                external_segment_id = (
435
+                    prop_external_segment['external_segment_id'])
436
+                allocated_address = (
437
+                    prop_external_segment['allocated_address'])
438
+                external_segments_dict.update({external_segment_id:
439
+                                               allocated_address})
440
+
441
+            if external_segments_dict:
442
+                prop_diff['external_segments'] = external_segments_dict
414 443
             self.grouppolicy().update_l3_policy(
415 444
                 self.resource_id, {'l3_policy': prop_diff})
416 445
 

+ 12
- 1
gbpautomation/heat/tests/test_grouppolicy.py View File

@@ -104,6 +104,10 @@ l3_policy_template = '''
104 104
         "description": "test L3 policy resource",
105 105
         "ip_version": "4",
106 106
         "ip_pool": "10.20.20.0",
107
+        "external_segments": [
108
+            {"external_segment_id": "es1",
109
+             "allocated_address": "1.1.1.1"},
110
+        ],
107 111
         "subnet_prefix_length": 24,
108 112
         "shared": True
109 113
       }
@@ -720,6 +724,7 @@ class L3PolicyTest(HeatTestCase):
720 724
                 "ip_version": "4",
721 725
                 "ip_pool": "10.20.20.0",
722 726
                 "subnet_prefix_length": 24,
727
+                "external_segments": {"es1": "1.1.1.1"},
723 728
                 "shared": True
724 729
             }
725 730
         }).AndReturn({'l3_policy': {'id': '5678'}})
@@ -745,6 +750,7 @@ class L3PolicyTest(HeatTestCase):
745 750
                 "ip_version": "4",
746 751
                 "ip_pool": "10.20.20.0",
747 752
                 "subnet_prefix_length": 24,
753
+                "external_segments": {"es1": "1.1.1.1"},
748 754
                 "shared": True
749 755
             }
750 756
         }).AndRaise(grouppolicy.NeutronClientException())
@@ -807,12 +813,17 @@ class L3PolicyTest(HeatTestCase):
807 813
     def test_update(self):
808 814
         rsrc = self.create_l3_policy()
809 815
         gbpclient.Client.update_l3_policy(
810
-            '5678', {'l3_policy': {'subnet_prefix_length': 28}})
816
+            '5678', {'l3_policy': {'subnet_prefix_length': 28,
817
+                                   'external_segments':
818
+                                   {'es2': '2.1.1.1'}}})
811 819
         self.m.ReplayAll()
812 820
         scheduler.TaskRunner(rsrc.create)()
813 821
 
814 822
         update_template = copy.deepcopy(rsrc.t)
815 823
         update_template['Properties']['subnet_prefix_length'] = 28
824
+        update_template['Properties']['external_segments'] = [
825
+            {'external_segment_id': 'es2',
826
+             'allocated_address': '2.1.1.1'}]
816 827
         scheduler.TaskRunner(rsrc.update, update_template)()
817 828
 
818 829
         self.m.VerifyAll()

Loading…
Cancel
Save