Browse Source

Merge "Change name of HA redundancy router automatically"

tags/5.1.0
Jenkins 1 year ago
parent
commit
977f5217ba

+ 12
- 2
networking_cisco/plugins/cisco/db/l3/ha_db.py View File

@@ -406,9 +406,14 @@ class HA_db_mixin(object):
406 406
                                         router_requested)
407 407
         # pick up updates to other attributes where it makes sense
408 408
         # and push - right now it is only admin_state_up.
409
+        other_updates_spec = {'router': {}}
409 410
         if 'admin_state_up' in update_specification['router']:
410
-            other_updates_spec = {'router': {'admin_state_up':
411
-                update_specification['router']['admin_state_up']}}
411
+            other_updates_spec['router']['admin_state_up'] = (
412
+                update_specification['router']['admin_state_up'])
413
+        if 'name' in update_specification['router']:
414
+            other_updates_spec['router']['name'] = (
415
+                update_specification['router']['name'])
416
+        if other_updates_spec['router']:
412 417
             self._process_other_router_updates(e_context, updated_router_db,
413 418
                                                other_updates_spec)
414 419
         # Ensure we get latest state from DB
@@ -444,7 +449,12 @@ class HA_db_mixin(object):
444 449
 
445 450
     def _process_other_router_updates(self, context, router_db, update_spec):
446 451
         rr_ids = []
452
+        new_name_stub = update_spec['router'].get('name')
447 453
         for r_b_db in router_db.redundancy_bindings:
454
+            if new_name_stub is not None:
455
+                idx = r_b_db.redundancy_router.name.split('_')[-1]
456
+                update_spec['router']['name'] = (
457
+                    new_name_stub + REDUNDANCY_ROUTER_SUFFIX + idx)
448 458
             update_spec['router'][ha.ENABLED] = False
449 459
             self._update_router_no_notify(
450 460
                 context, r_b_db.redundancy_router_id, update_spec)

+ 18
- 0
networking_cisco/tests/unit/cisco/l3/test_ha_l3_router_appliance_plugin.py View File

@@ -1464,6 +1464,24 @@ class HAL3RouterApplianceVMTestCase(
1464 1464
             self._rr_routes_update_cleanup(p2['id'], None, r['id'], rr1_id, [])
1465 1465
             self._routes_update_cleanup(p1['id'], None, r['id'], [])
1466 1466
 
1467
+    def test_router_update_change_name_changes_redundancy_routers(self):
1468
+        with self.router() as router:
1469
+            r = router['router']
1470
+            newName = 'routerOne'
1471
+            params = "&".join(["id=%s" % rr['id'] for rr in
1472
+                               r[ha.DETAILS][ha.REDUNDANCY_ROUTERS]])
1473
+            r_routers = self._list('routers', query_params=params)['routers']
1474
+            rr_name_start = 'router1' + ha_db.REDUNDANCY_ROUTER_SUFFIX
1475
+            for rr in r_routers:
1476
+                self.assertTrue(rr['name'].startswith(rr_name_start))
1477
+            r_updated = self._update('routers', r['id'],
1478
+                                     {'router': {'name': newName}})['router']
1479
+            self.assertEqual(newName, r_updated['name'])
1480
+            rr_name_start = newName + ha_db.REDUNDANCY_ROUTER_SUFFIX
1481
+            r_routers = self._list('routers', query_params=params)['routers']
1482
+            for rr in r_routers:
1483
+                self.assertTrue(rr['name'].startswith(rr_name_start))
1484
+
1467 1485
     def test__notify_subnetpool_address_scope_update(self):
1468 1486
         l3_plugin = bc.get_plugin(bc.constants.L3)
1469 1487
 

Loading…
Cancel
Save