Browse Source

Merge "Fix for getting port groups while using OVS up to 2.9" into stable/train

tags/7.1.0^0
Zuul Gerrit Code Review 2 weeks ago
parent
commit
59e705be40
2 changed files with 41 additions and 13 deletions
  1. +26
    -13
      networking_ovn/ovsdb/impl_idl_ovn.py
  2. +15
    -0
      networking_ovn/tests/unit/ovsdb/test_impl_idl_ovn.py

+ 26
- 13
networking_ovn/ovsdb/impl_idl_ovn.py View File

@@ -674,22 +674,35 @@ class OvsdbNbOvnIdl(nb_impl_idl.OvnNbApiIdlImpl, Backend):
def get_port_group(self, pg_name):
if uuidutils.is_uuid_like(pg_name):
pg_name = utils.ovn_port_group_name(pg_name)

for pg in self._tables['Port_Group'].rows.values():
if pg.name == pg_name:
return pg
try:
for pg in self._tables['Port_Group'].rows.values():
if pg.name == pg_name:
return pg
except KeyError:
# TODO(dalvarez): This except block is added for backwards compat
# with old OVN schemas (<=2.9) where Port Groups are not present.
# This (and other conditional code around this feature) shall be
# removed at some point.
return

def get_port_groups(self):
port_groups = {}
for row in self._tables['Port_Group'].rows.values():
name = getattr(row, 'name')
if not (ovn_const.OVN_SG_EXT_ID_KEY in row.external_ids or
name == ovn_const.OVN_DROP_PORT_GROUP_NAME):
continue
data = {}
for row_key in getattr(row, "_data", {}):
data[row_key] = getattr(row, row_key)
port_groups[name] = data
try:
for row in self._tables['Port_Group'].rows.values():
name = getattr(row, 'name')
if not (ovn_const.OVN_SG_EXT_ID_KEY in row.external_ids or
name == ovn_const.OVN_DROP_PORT_GROUP_NAME):
continue
data = {}
for row_key in getattr(row, "_data", {}):
data[row_key] = getattr(row, row_key)
port_groups[name] = data
except KeyError:
# TODO(dalvarez): This except block is added for backwards compat
# with old OVN schemas (<=2.9) where Port Groups are not present.
# This (and other conditional code around this feature) shall be
# removed at some point.
pass
return port_groups

def check_liveness(self):


+ 15
- 0
networking_ovn/tests/unit/ovsdb/test_impl_idl_ovn.py View File

@@ -13,6 +13,7 @@
#
import collections
import copy
import uuid

import mock

@@ -707,6 +708,20 @@ class TestNBImplIdlOvn(TestDBImplIdlOvn):
address_sets = self.nb_ovn_idl.get_address_sets()
self.assertEqual(len(address_sets), 4)

def test_get_port_group_not_supported(self):
self._load_nb_db()
# Make sure that PG tables doesn't exist in fake db.
self._tables.pop('Port_Group', None)
port_group = self.nb_ovn_idl.get_port_group(str(uuid.uuid4()))
self.assertIsNone(port_group)

def test_get_port_groups_not_supported(self):
self._load_nb_db()
# Make sure that PG tables doesn't exist in fake db.
self._tables.pop('Port_Group', None)
port_groups = self.nb_ovn_idl.get_port_groups()
self.assertEqual({}, port_groups)


class TestSBImplIdlOvn(TestDBImplIdlOvn):



Loading…
Cancel
Save