Skip to content

Commit

Permalink
ovn-detrace: Only decode br-int OVS interfaces.
Browse files Browse the repository at this point in the history
Do not assume 'ofport' is unique for all OVS interfaces in the system.  This
is true only for interfaces within the same OVS bridge.  Also, only decode
br-int related interfaces.

Also, fix printing of potential duplicate UUIDs decoded from cookies.

Reported-by: Michael Cambria <mcambria@redhat.com>
Reported-at: https://bugzilla.redhat.com/1890803
Fixes: 8051499 ("ovn-detrace: Add support for other types of SB cookies.")
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>

(cherry-picked from master commit fcdac56)
  • Loading branch information
dceara authored and numansiddique committed Oct 30, 2020
1 parent 628057e commit f378bf3
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions utilities/ovn-detrace.in
Expand Up @@ -117,18 +117,27 @@ class OVSDB(object):
def _find_rows(self, table_name, find_fn):
return filter(find_fn, self.get_table(table_name).rows.values())

def _find_rows_by_name(self, table_name, value):
def find_rows_by_name(self, table_name, value):
return self._find_rows(table_name, lambda row: row.name == value)

def find_rows_by_partial_uuid(self, table_name, value):
return self._find_rows(table_name,
lambda row: str(row.uuid).startswith(value))

def get_first_record(self, table_name):
table_rows = self.get_table(table_name).rows.values()
if len(table_rows) == 0:
return None
return next(iter(table_rows))

class CookieHandler(object):
def __init__(self, db, table):
self._db = db
self._table = table

def print(self, msg):
print_h(msg)

def get_records(self, cookie):
return []

Expand Down Expand Up @@ -320,18 +329,34 @@ class OvsInterfaceHandler(CookieHandler):
def __init__(self, ovs_db):
super(OvsInterfaceHandler, self).__init__(ovs_db, 'Interface')

# Store the interfaces connected to the integration bridge in a dict
# indexed by ofport.
br = self.get_br_int()
self._intfs = {
i.ofport[0] : i for p in br.ports
for i in p.interfaces if len(i.ofport) > 0
}

def get_br_int(self):
ovsrec = self._db.get_first_record('Open_vSwitch')
if ovsrec:
br_name = ovsrec.external_ids.get('ovn-bridge', 'br-int')
else:
br_name = 'br-int'
return next(iter(self._db.find_rows_by_name('Bridge', br_name)))

def get_records(self, ofport):
return self._db._find_rows(self._table,
lambda intf: len(intf.ofport) > 0 and
str(intf.ofport[0]) == ofport)
intf = self._intfs.get(int(ofport))
return [intf] if intf else []

def print_record(self, intf):
print_p('OVS Interface: %s (%s)' %
(intf.name, intf.external_ids.get('iface-id')))

def print_record_from_cookie(ovnnb_db, cookie_handlers, cookie):
for handler in cookie_handlers:
for i, record in enumerate(handler.get_records(cookie)):
records = list(handler.get_records(cookie))
for i, record in enumerate(records):
if i > 0:
handler.print('[Duplicate uuid cookie]')
handler.print_record(record)
Expand Down

0 comments on commit f378bf3

Please sign in to comment.