Browse Source

Fix GBP heat stack update handling

Change-Id: If8b3d03715b58372dcc478eee3af2cdde9664256
Closes-bug: #1421000
Susaant Kondapaneni 4 years ago
parent
commit
a02fb68229

+ 60
- 0
gbpautomation/heat/engine/resources/neutron/grouppolicy.py View File

@@ -221,6 +221,36 @@ class PolicyTargetGroup(gbpresource.GBPResource):
221 221
 
222 222
     def handle_update(self, json_snippet, tmpl_diff, prop_diff):
223 223
         if prop_diff:
224
+            provided_policy_rule_set_list = {}
225
+            consumed_policy_rule_set_list = {}
226
+            props_provided_policy_rule_sets = prop_diff.get(
227
+                'provided_policy_rule_sets', [])
228
+            props_consumed_policy_rule_sets = prop_diff.get(
229
+                'consumed_policy_rule_sets', [])
230
+
231
+            for prop_prov_policy_rule_set in props_provided_policy_rule_sets:
232
+                policy_rule_set_id = (
233
+                    prop_prov_policy_rule_set['policy_rule_set_id'])
234
+                policy_rule_set_scope = (
235
+                    prop_prov_policy_rule_set['policy_rule_set_scope'])
236
+                provided_policy_rule_set_list.update({policy_rule_set_id:
237
+                                                      policy_rule_set_scope})
238
+
239
+            for prop_cons_policy_rule_set in props_consumed_policy_rule_sets:
240
+                policy_rule_set_id = (
241
+                    prop_cons_policy_rule_set['policy_rule_set_id'])
242
+                policy_rule_set_scope = (
243
+                    prop_cons_policy_rule_set['policy_rule_set_scope'])
244
+                consumed_policy_rule_set_list.update({policy_rule_set_id:
245
+                                                      policy_rule_set_scope})
246
+
247
+            if provided_policy_rule_set_list:
248
+                prop_diff['provided_policy_rule_sets'] = (
249
+                    provided_policy_rule_set_list)
250
+            if consumed_policy_rule_set_list:
251
+                prop_diff['consumed_policy_rule_sets'] = (
252
+                    consumed_policy_rule_set_list)
253
+
224 254
             self.grouppolicy().update_policy_target_group(
225 255
                 self.resource_id, {'policy_target_group': prop_diff})
226 256
 
@@ -900,6 +930,36 @@ class ExternalPolicy(gbpresource.GBPResource):
900 930
 
901 931
     def handle_update(self, json_snippet, tmpl_diff, prop_diff):
902 932
         if prop_diff:
933
+            provided_policy_rule_set_list = {}
934
+            consumed_policy_rule_set_list = {}
935
+            props_provided_policy_rule_sets = prop_diff.get(
936
+                'provided_policy_rule_sets', [])
937
+            props_consumed_policy_rule_sets = prop_diff.get(
938
+                'consumed_policy_rule_sets', [])
939
+
940
+            for prop_prov_policy_rule_set in props_provided_policy_rule_sets:
941
+                policy_rule_set_id = (
942
+                    prop_prov_policy_rule_set['policy_rule_set_id'])
943
+                policy_rule_set_scope = (
944
+                    prop_prov_policy_rule_set['policy_rule_set_scope'])
945
+                provided_policy_rule_set_list.update({policy_rule_set_id:
946
+                                                      policy_rule_set_scope})
947
+
948
+            for prop_cons_policy_rule_set in props_consumed_policy_rule_sets:
949
+                policy_rule_set_id = (
950
+                    prop_cons_policy_rule_set['policy_rule_set_id'])
951
+                policy_rule_set_scope = (
952
+                    prop_cons_policy_rule_set['policy_rule_set_scope'])
953
+                consumed_policy_rule_set_list.update({policy_rule_set_id:
954
+                                                      policy_rule_set_scope})
955
+
956
+            if provided_policy_rule_set_list:
957
+                prop_diff['provided_policy_rule_sets'] = (
958
+                    provided_policy_rule_set_list)
959
+            if consumed_policy_rule_set_list:
960
+                prop_diff['consumed_policy_rule_sets'] = (
961
+                    consumed_policy_rule_set_list)
962
+
903 963
             self.grouppolicy().update_external_policy(
904 964
                 self.resource_id, {'external_policy': prop_diff})
905 965
 

+ 57
- 3
gbpautomation/heat/tests/test_grouppolicy.py View File

@@ -547,12 +547,40 @@ class PolicyTargetGroupTest(HeatTestCase):
547 547
     def test_update(self):
548 548
         rsrc = self.create_policy_target_group()
549 549
         gbpclient.Client.update_policy_target_group(
550
-            '5678', {'policy_target_group': {'l2_policy_id': 'l2_id_update'}})
550
+            '5678', {'policy_target_group': {
551
+                'l2_policy_id': 'l2_id_update',
552
+                'provided_policy_rule_sets': {
553
+                    'policy_rule_set1': 'scope1',
554
+                    'policy_rule_set2': 'scope2',
555
+                    'policy_rule_set5': 'scope5'
556
+                },
557
+                'consumed_policy_rule_sets': {
558
+                    'policy_rule_set3': 'scope3',
559
+                    'policy_rule_set4': 'scope4',
560
+                    'policy_rule_set6': 'scope6'
561
+                },
562
+            }})
551 563
         self.m.ReplayAll()
552 564
         scheduler.TaskRunner(rsrc.create)()
553 565
 
554 566
         update_template = copy.deepcopy(rsrc.t)
555 567
         update_template['Properties']['l2_policy_id'] = 'l2_id_update'
568
+        update_template['Properties']['provided_policy_rule_sets'] = [
569
+            {'policy_rule_set_id': 'policy_rule_set1',
570
+             'policy_rule_set_scope': 'scope1'},
571
+            {'policy_rule_set_id': 'policy_rule_set2',
572
+             'policy_rule_set_scope': 'scope2'},
573
+            {'policy_rule_set_id': 'policy_rule_set5',
574
+             'policy_rule_set_scope': 'scope5'}
575
+        ]
576
+        update_template['Properties']['consumed_policy_rule_sets'] = [
577
+            {'policy_rule_set_id': 'policy_rule_set3',
578
+             'policy_rule_set_scope': 'scope3'},
579
+            {'policy_rule_set_id': 'policy_rule_set4',
580
+             'policy_rule_set_scope': 'scope4'},
581
+            {'policy_rule_set_id': 'policy_rule_set6',
582
+             'policy_rule_set_scope': 'scope6'}
583
+        ]
556 584
         scheduler.TaskRunner(rsrc.update, update_template)()
557 585
 
558 586
         self.m.VerifyAll()
@@ -1483,14 +1511,40 @@ class ExternalPolicyTest(HeatTestCase):
1483 1511
     def test_update(self):
1484 1512
         rsrc = self.create_external_policy()
1485 1513
         gbpclient.Client.update_external_policy(
1486
-            '5678', {'external_policy':
1487
-                     {'external_segments': ['9876']}})
1514
+            '5678', {'external_policy': {
1515
+                'external_segments': ['9876'],
1516
+                'provided_policy_rule_sets': {
1517
+                    '2345': 'scope1',
1518
+                    '8901': 'scope2',
1519
+                    '1122': 'scope5'},
1520
+                'consumed_policy_rule_sets': {
1521
+                    '9012': 'scope3',
1522
+                    '9210': 'scope4',
1523
+                    '9900': 'scope6'
1524
+                }
1525
+            }})
1488 1526
         self.m.ReplayAll()
1489 1527
         scheduler.TaskRunner(rsrc.create)()
1490 1528
 
1491 1529
         update_template = copy.deepcopy(rsrc.t)
1492 1530
         update_template['Properties']['external_segments'] = [
1493 1531
             '9876']
1532
+        update_template['Properties']['provided_policy_rule_sets'] = [
1533
+            {'policy_rule_set_id': '2345',
1534
+             'policy_rule_set_scope': 'scope1'},
1535
+            {'policy_rule_set_id': '8901',
1536
+             'policy_rule_set_scope': 'scope2'},
1537
+            {'policy_rule_set_id': '1122',
1538
+             'policy_rule_set_scope': 'scope5'}
1539
+        ]
1540
+        update_template['Properties']['consumed_policy_rule_sets'] = [
1541
+            {'policy_rule_set_id': '9012',
1542
+             'policy_rule_set_scope': 'scope3'},
1543
+            {'policy_rule_set_id': '9210',
1544
+             'policy_rule_set_scope': 'scope4'},
1545
+            {'policy_rule_set_id': '9900',
1546
+             'policy_rule_set_scope': 'scope6'}
1547
+        ]
1494 1548
         scheduler.TaskRunner(rsrc.update, update_template)()
1495 1549
 
1496 1550
         self.m.VerifyAll()

Loading…
Cancel
Save