Skip to content

Commit 772ad87

Browse files
ralonsohmnasiadka
authored andcommitted
[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
1 parent a2235ac commit 772ad87

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,9 @@ def run_idl(self, txn):
509509
if col == 'gateway_chassis':
510510
col, val = _add_gateway_chassis(self.api, txn, self.name,
511511
val)
512-
setattr(lrouter_port, col, val)
512+
self.set_column(lrouter_port, col, val)
513513
_addvalue_to_list(lrouter, 'ports', lrouter_port)
514+
self.result = lrouter_port.uuid
514515

515516

516517
class UpdateLRouterPortCommand(command.BaseCommand):
@@ -535,7 +536,7 @@ def run_idl(self, txn):
535536
if col == 'gateway_chassis':
536537
col, val = _add_gateway_chassis(self.api, txn, self.name,
537538
val)
538-
setattr(lrouter_port, col, val)
539+
self.set_column(lrouter_port, col, val)
539540

540541

541542
class DelLRouterPortCommand(command.BaseCommand):

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,82 @@ def test__get_logical_router_port_ha_chassis_group_no_hcg(self):
819819
cprio_res = self.nbapi._get_logical_router_port_ha_chassis_group(lrp)
820820
self.assertEqual([], cprio_res)
821821

822+
def test_create_lrp_with_ha_chassis_group_same_txn(self):
823+
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
824+
networks = ['192.0.2.0/24']
825+
lr_name = uuidutils.generate_uuid()
826+
lrp_name = uuidutils.generate_uuid()
827+
self.nbapi.lr_add(lr_name).execute(check_error=True)
828+
829+
# Create the HCG and the LRP in the same transaction.
830+
with self.nbapi.transaction(check_error=True) as txn:
831+
hcg_cmd = txn.add(self.nbapi.ha_chassis_group_with_hc_add(
832+
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}))
833+
txn.add(self.nbapi.add_lrouter_port(
834+
lrp_name, lr_name, mac=mac, networks=networks,
835+
ha_chassis_group=hcg_cmd))
836+
837+
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
838+
self.assertEqual(hcg_cmd.result.uuid, lrp.ha_chassis_group[0].uuid)
839+
840+
def test_create_lrp_with_ha_chassis_group_different_txn(self):
841+
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
842+
networks = ['192.0.2.0/24']
843+
lr_name = uuidutils.generate_uuid()
844+
lrp_name = uuidutils.generate_uuid()
845+
self.nbapi.lr_add(lr_name).execute(check_error=True)
846+
847+
# Create the HCG and the LRP in two consecutive transactions.
848+
hcg = self.nbapi.ha_chassis_group_with_hc_add(
849+
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}).execute(
850+
check_error=True)
851+
self.nbapi.add_lrouter_port(
852+
lrp_name, lr_name, mac=mac, networks=networks,
853+
ha_chassis_group=hcg.uuid).execute(check_error=True)
854+
855+
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
856+
self.assertEqual(hcg.uuid, lrp.ha_chassis_group[0].uuid)
857+
858+
def test_update_lrp_with_ha_chassis_group_same_txn(self):
859+
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
860+
networks = ['192.0.2.0/24']
861+
lr_name = uuidutils.generate_uuid()
862+
lrp_name = uuidutils.generate_uuid()
863+
self.nbapi.lr_add(lr_name).execute(check_error=True)
864+
self.nbapi.add_lrouter_port(
865+
lrp_name, lr_name, mac=mac,
866+
networks=networks).execute(check_error=True)
867+
868+
# Create the HCG and update the LRP in the same transaction.
869+
with self.nbapi.transaction(check_error=True) as txn:
870+
hcg_cmd = txn.add(self.nbapi.ha_chassis_group_with_hc_add(
871+
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}))
872+
txn.add(self.nbapi.update_lrouter_port(
873+
lrp_name, ha_chassis_group=hcg_cmd))
874+
875+
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
876+
self.assertEqual(hcg_cmd.result.uuid, lrp.ha_chassis_group[0].uuid)
877+
878+
def test_update_lrp_with_ha_chassis_group_different_txn(self):
879+
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
880+
networks = ['192.0.2.0/24']
881+
lr_name = uuidutils.generate_uuid()
882+
lrp_name = uuidutils.generate_uuid()
883+
self.nbapi.lr_add(lr_name).execute(check_error=True)
884+
self.nbapi.add_lrouter_port(
885+
lrp_name, lr_name, mac=mac,
886+
networks=networks).execute(check_error=True)
887+
888+
# Create the HCG and update the LRP in two consecutive transactions.
889+
hcg = self.nbapi.ha_chassis_group_with_hc_add(
890+
uuidutils.generate_uuid(), {'ch1': 1, 'ch2': 2}).execute(
891+
check_error=True)
892+
self.nbapi.update_lrouter_port(
893+
lrp_name, ha_chassis_group=hcg.uuid).execute(check_error=True)
894+
895+
lrp = self.nbapi.lrp_get(lrp_name).execute(check_error=True)
896+
self.assertEqual(hcg.uuid, lrp.ha_chassis_group[0].uuid)
897+
822898

823899
class TestIgnoreConnectionTimeout(BaseOvnIdlTest):
824900
@classmethod

0 commit comments

Comments
 (0)