[OVN] Handle HA_Chassis_Group field in LRP creation and update

Now is possible to set a ``HA_Chassis_Group`` in a
``Logical_Router_Port``, using the NB API methods ``add_lrouter_port``
and ``update_lrouter_port``. Both methods support creating the
``HA_Chassis_Group`` in the same transation the LRP is created or
updated.

Partial-Bug: #2092271
Change-Id: Iab7581d2f4eff8ab84a2a379499490353fbe1971
This commit is contained in:
Rodolfo Alonso Hernandez 2025-04-22 23:51:49 +00:00
parent 6a6426770d
commit a548177567
2 changed files with 79 additions and 2 deletions

View File

@ -554,8 +554,9 @@ class AddLRouterPortCommand(command.BaseCommand):
if col == 'gateway_chassis':
col, val = _add_gateway_chassis(self.api, txn, self.name,
val)
setattr(lrouter_port, col, val)
self.set_column(lrouter_port, col, val)
_addvalue_to_list(lrouter, 'ports', lrouter_port)
self.result = lrouter_port.uuid
class UpdateLRouterPortCommand(command.BaseCommand):
@ -580,7 +581,7 @@ class UpdateLRouterPortCommand(command.BaseCommand):
if col == 'gateway_chassis':
col, val = _add_gateway_chassis(self.api, txn, self.name,
val)
setattr(lrouter_port, col, val)
self.set_column(lrouter_port, col, val)
class DelLRouterPortCommand(command.BaseCommand):

View File

@ -819,6 +819,82 @@ class TestNbApi(BaseOvnIdlTest):
cprio_res = self.nbapi._get_logical_router_port_ha_chassis_group(lrp)
self.assertEqual([], cprio_res)
def test_create_lrp_with_ha_chassis_group_same_txn(self):
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
networks = ['192.0.2.0/24']
lr_name = uuidutils.generate_uuid()
lrp_name = uuidutils.generate_uuid()
self.nbapi.lr_add(lr_name).execute(check_error=True)
# Create the HCG and the LRP in the same transaction.
with self.nbapi.transaction(check_error=True) as txn:
hcg_cmd = txn.add(self.nbapi.ha_chassis_group_with_hc_add(
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}))
txn.add(self.nbapi.add_lrouter_port(
lrp_name, lr_name, mac=mac, networks=networks,
ha_chassis_group=hcg_cmd))
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
self.assertEqual(hcg_cmd.result.uuid, lrp.ha_chassis_group[0].uuid)
def test_create_lrp_with_ha_chassis_group_different_txn(self):
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
networks = ['192.0.2.0/24']
lr_name = uuidutils.generate_uuid()
lrp_name = uuidutils.generate_uuid()
self.nbapi.lr_add(lr_name).execute(check_error=True)
# Create the HCG and the LRP in two consecutive transactions.
hcg = self.nbapi.ha_chassis_group_with_hc_add(
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}).execute(
check_error=True)
self.nbapi.add_lrouter_port(
lrp_name, lr_name, mac=mac, networks=networks,
ha_chassis_group=hcg.uuid).execute(check_error=True)
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
self.assertEqual(hcg.uuid, lrp.ha_chassis_group[0].uuid)
def test_update_lrp_with_ha_chassis_group_same_txn(self):
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
networks = ['192.0.2.0/24']
lr_name = uuidutils.generate_uuid()
lrp_name = uuidutils.generate_uuid()
self.nbapi.lr_add(lr_name).execute(check_error=True)
self.nbapi.add_lrouter_port(
lrp_name, lr_name, mac=mac,
networks=networks).execute(check_error=True)
# Create the HCG and update the LRP in the same transaction.
with self.nbapi.transaction(check_error=True) as txn:
hcg_cmd = txn.add(self.nbapi.ha_chassis_group_with_hc_add(
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}))
txn.add(self.nbapi.update_lrouter_port(
lrp_name, ha_chassis_group=hcg_cmd))
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
self.assertEqual(hcg_cmd.result.uuid, lrp.ha_chassis_group[0].uuid)
def test_update_lrp_with_ha_chassis_group_different_txn(self):
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
networks = ['192.0.2.0/24']
lr_name = uuidutils.generate_uuid()
lrp_name = uuidutils.generate_uuid()
self.nbapi.lr_add(lr_name).execute(check_error=True)
self.nbapi.add_lrouter_port(
lrp_name, lr_name, mac=mac,
networks=networks).execute(check_error=True)
# Create the HCG and update the LRP in two consecutive transactions.
hcg = self.nbapi.ha_chassis_group_with_hc_add(
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}).execute(
check_error=True)
self.nbapi.update_lrouter_port(
lrp_name, ha_chassis_group=hcg.uuid).execute(check_error=True)
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
self.assertEqual(hcg.uuid, lrp.ha_chassis_group[0].uuid)
class TestIgnoreConnectionTimeout(BaseOvnIdlTest):
@classmethod