Skip to content

Commit d93c35f

Browse files
ralonsohmnasiadka
authored andcommitted
Maintenance method to update the LRP from GC to HCG
The new maintenance method ``migrate_lrp_gateway_chassis_to_ha_chassis_group``, replaces the ``Logical_Router_Port`` ``Gateway_Chassis`` with the equivalent ``HA_Chassis_Group``, that is the preferred method for HA scheduling in OVN, as reported in the LP bug. Partial-Bug: #2092271 Signed-off-by: Rodolfo Alonso Hernandez <[email protected]> Change-Id: I8994415f97bca575b7104824ef889da0235c9a8b
1 parent 772ad87 commit d93c35f

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,41 @@ def update_qos_fip_rule_priority(self):
11601160

11611161
raise periodics.NeverAgain()
11621162

1163+
# TODO(ralonsoh): Remove this method in F+3 cycle (2nd next SLURP release)
1164+
@has_lock_periodic(
1165+
periodic_run_limit=ovn_const.MAINTENANCE_TASK_RETRY_LIMIT,
1166+
spacing=ovn_const.MAINTENANCE_ONE_RUN_TASK_SPACING,
1167+
run_immediately=True)
1168+
def migrate_lrp_gateway_chassis_to_ha_chassis_group(self):
1169+
"""Migrate the LRP Gateway_Chassis to HA_Chassis_Group"""
1170+
with self._nb_idl.transaction(check_error=True) as txn:
1171+
for lrp in self._nb_idl.db_list_rows(
1172+
'Logical_Router_Port').execute(check_error=True):
1173+
if not lrp.gateway_chassis:
1174+
continue
1175+
1176+
chassis_prio = {}
1177+
for gc in lrp.gateway_chassis:
1178+
chassis_prio[gc.chassis_name] = gc.priority
1179+
r_name = lrp.external_ids.get(
1180+
ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY)
1181+
if not r_name:
1182+
LOG.warning(f'Logical_Router_Port {lrp.name} does not '
1183+
'have the router name in external_ids.')
1184+
continue
1185+
1186+
# Add the new HA_Chassis_Group and assign to the LRP.
1187+
hcg_cmd = txn.add(self._nb_idl.ha_chassis_group_with_hc_add(
1188+
r_name, chassis_prio, may_exist=True))
1189+
txn.add(self._nb_idl.db_set(
1190+
'Logical_Router_Port', lrp.uuid,
1191+
('ha_chassis_group', hcg_cmd)))
1192+
# Unset the Gateway_Chassis in the LRP.
1193+
txn.add(self._nb_idl.db_clear(
1194+
'Logical_Router_Port', lrp.uuid, 'gateway_chassis'))
1195+
1196+
raise periodics.NeverAgain()
1197+
11631198

11641199
class HashRingHealthCheckPeriodics:
11651200

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from neutron_lib import constants as n_const
2828
from neutron_lib import context as n_context
2929
from neutron_lib.exceptions import l3 as lib_l3_exc
30+
from neutron_lib.utils import net as net_utils
3031
from oslo_utils import uuidutils
3132
from sqlalchemy.dialects.mysql import dialect as mysql_dialect
3233

@@ -1480,6 +1481,44 @@ def test_update_qos_fip_rule_priority(self):
14801481
else:
14811482
self.assertEqual(def_prio, qos_rule.priority)
14821483

1484+
def test_migrate_lrp_gateway_chassis_to_ha_chassis_group(self):
1485+
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
1486+
networks = ['192.0.2.0/24']
1487+
lr_name = uuidutils.generate_uuid()
1488+
lrp_name = uuidutils.generate_uuid()
1489+
gateway_chassis = ['gw_ch1', 'gw_ch2', 'gw_ch3']
1490+
1491+
self.nb_api.lr_add(lr_name).execute(check_error=True)
1492+
ext_ids = {ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: lr_name}
1493+
self.nb_api.add_lrouter_port(
1494+
lrp_name, lr_name, mac=mac,
1495+
networks=networks, gateway_chassis=gateway_chassis,
1496+
external_ids=ext_ids).execute(check_error=True)
1497+
1498+
hcg = self.nb_api.lookup('HA_Chassis_Group', lr_name, default=None)
1499+
self.assertIsNone(hcg)
1500+
lr = self.nb_api.lookup('Logical_Router_Port', lrp_name)
1501+
chassis_prio = {}
1502+
for gc in lr.gateway_chassis:
1503+
chassis_prio[gc.chassis_name] = gc.priority
1504+
1505+
self.assertRaises(
1506+
periodics.NeverAgain,
1507+
self.maint.migrate_lrp_gateway_chassis_to_ha_chassis_group)
1508+
1509+
hcg = self.nb_api.lookup('HA_Chassis_Group', lr_name, default=None)
1510+
self.assertEqual(len(chassis_prio), len(hcg.ha_chassis))
1511+
for ha_chassis in hcg.ha_chassis:
1512+
try:
1513+
# The priority and the chassis_name of the former
1514+
# Gateway_Chassis registers must match the new HA_Chassis ones.
1515+
self.assertEqual(ha_chassis.priority,
1516+
chassis_prio.pop(ha_chassis.chassis_name))
1517+
except KeyError:
1518+
self.fail(f'HA_Chassis with chassis name '
1519+
f'{ha_chassis.chassis_name} not present in the '
1520+
f'chassis list')
1521+
14831522

14841523
class TestLogMaintenance(_TestMaintenanceHelper,
14851524
test_log_driver.LogApiTestCaseBase):

0 commit comments

Comments
 (0)