Skip to content

Commit a2235ac

Browse files
ralonsohmnasiadka
authored andcommitted
[OVN] Method to retrieve the LRP chassis list
Added a new method in ``OvsdbNbOvnIdl`` to retrieve the gateway ``Logical_Router_Port`` chassis list with priorities, stored in the ``HA_Chassis_Group`` register associated to the router. Partial-Bug: #2092271 Change-Id: I6b2bc7a3e80a906f146da3645c530d175f31a8dd
1 parent f493715 commit a2235ac

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,30 @@ def _get_logical_router_port_gateway_chassis(self, lrp, priorities=None):
520520
# make sure that chassis are sorted by priority
521521
return sorted(chassis, reverse=True, key=lambda x: x[1])
522522

523+
@staticmethod
524+
def _get_logical_router_port_ha_chassis_group(lrp, priorities=None):
525+
"""Get the list of chassis hosting this gateway port.
526+
527+
@param lrp: logical router port
528+
@type lrp: Logical_Router_Port row
529+
@param priorities: a list of gateway chassis priorities to search for
530+
@type priorities: list of int
531+
@return: List of tuples (chassis_name, priority) sorted by priority. If
532+
``priorities`` is set then only chassis matching of these
533+
priorities are returned.
534+
"""
535+
chassis = []
536+
hcg = getattr(lrp, 'ha_chassis_group', None)
537+
if not hcg:
538+
return chassis
539+
540+
for hc in hcg[0].ha_chassis:
541+
if priorities is not None and hc.priority not in priorities:
542+
continue
543+
chassis.append((hc.chassis_name, hc.priority))
544+
# Make sure that chassis are sorted by priority (highest prio first)
545+
return sorted(chassis, reverse=True, key=lambda x: x[1])
546+
523547
def get_all_chassis_gateway_bindings(self,
524548
chassis_candidate_list=None,
525549
priorities=None):

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import netaddr
2121
from neutron_lib import constants
22+
from neutron_lib.utils import net as net_utils
2223
from oslo_utils import netutils
2324
from oslo_utils import uuidutils
2425
from ovsdbapp.backend.ovs_idl import connection
@@ -779,6 +780,45 @@ def test_ha_chassis_group_with_hc_add_two_hcg(self):
779780
self._check_hcg(hcg1, hcg_name1, chassis_priority1)
780781
self._check_hcg(hcg2, hcg_name2, chassis_priority2)
781782

783+
def _add_lrp_with_gw(self, chassis_priority=None, is_gw=True):
784+
if is_gw:
785+
hcg_name = uuidutils.generate_uuid()
786+
hcg = self.nbapi.ha_chassis_group_with_hc_add(
787+
hcg_name, chassis_priority).execute(check_error=True)
788+
kwargs = {'ha_chassis_group': hcg.uuid}
789+
else:
790+
hcg = None
791+
kwargs = {}
792+
793+
mac = next(net_utils.random_mac_generator(['ca', 'fe', 'ca', 'fe']))
794+
networks = ['192.0.2.0/24']
795+
lr = self.nbapi.lr_add(uuidutils.generate_uuid()).execute(
796+
check_error=True)
797+
798+
lrp = self.nbapi.lrp_add(
799+
lr.uuid, uuidutils.generate_uuid(), mac, networks,
800+
**kwargs).execute(check_error=True)
801+
return lr, lrp, hcg
802+
803+
def test__get_logical_router_port_ha_chassis_group(self):
804+
chassis_priority = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4}
805+
lr, lrp, hcg = self._add_lrp_with_gw(chassis_priority)
806+
cprio_res = self.nbapi._get_logical_router_port_ha_chassis_group(lrp)
807+
self.assertEqual([('ch4', 4), ('ch3', 3), ('ch2', 2), ('ch1', 1)],
808+
cprio_res)
809+
810+
def test__get_logical_router_port_ha_chassis_group_with_priorities(self):
811+
chassis_priority = {'ch1': 1, 'ch2': 2, 'ch3': 3, 'ch4': 4}
812+
lr, lrp, hcg = self._add_lrp_with_gw(chassis_priority)
813+
cprio_res = self.nbapi._get_logical_router_port_ha_chassis_group(
814+
lrp, priorities=(1, 3, 4))
815+
self.assertEqual([('ch4', 4), ('ch3', 3), ('ch1', 1)], cprio_res)
816+
817+
def test__get_logical_router_port_ha_chassis_group_no_hcg(self):
818+
lr, lrp, hcg = self._add_lrp_with_gw(is_gw=False)
819+
cprio_res = self.nbapi._get_logical_router_port_ha_chassis_group(lrp)
820+
self.assertEqual([], cprio_res)
821+
782822

783823
class TestIgnoreConnectionTimeout(BaseOvnIdlTest):
784824
@classmethod

0 commit comments

Comments
 (0)