瀏覽代碼

Fix for getting port groups while using OVS up to 2.9

Functions get_port_group() and get_port_groups() were failing
with KeyError while getting to access non-existent Port_Group
table with OVS 2.9.

This patch adds additional check if Port Group is supported in the
env where the code runs.

Change-Id: If3ce6ab1d1318a6d5142989b3bf45ecce97762e3
Closes-Bug: #1844491
(cherry-picked from commit a78dbc252d)
tags/5.1.0
Maciej Józefczyk 8 月之前
父節點
當前提交
3ac53d2ed4
共有 2 個文件被更改,包括 41 次插入13 次删除
  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 查看文件

@@ -682,22 +682,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 查看文件

@@ -13,6 +13,7 @@
#

import copy
import uuid

import mock

@@ -696,6 +697,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…
取消
儲存