Break out match_fn from matches

The condition matching functionality is kind of limited. Since
matching table and event is very common, break out a match_fn
method to allow users to create custom matching w/o replicating
table and event matching.

Change-Id: I5b48863499375c40295504bae41c5fffdbcd747c
This commit is contained in:
Terry Wilson 2019-02-12 11:14:49 -06:00
parent bc06517ba3
commit 4ee25ad6af

View File

@ -19,11 +19,7 @@ LOG = logging.getLogger(__name__)
class RowEvent(ovsdb_event.RowEvent): # pylint: disable=abstract-method
def matches(self, event, row, old=None):
if event not in self.events:
return False
if row._table.name != self.table:
return False
def match_fn(self, event, row, old):
if self.conditions and not idlutils.row_match(row, self.conditions):
return False
if self.old_conditions:
@ -35,7 +31,15 @@ class RowEvent(ovsdb_event.RowEvent): # pylint: disable=abstract-method
except (KeyError, AttributeError):
# Its possible that old row may not have all columns in it
return False
return True
def matches(self, event, row, old=None):
if event not in self.events:
return False
if row._table.name != self.table:
return False
if not self.match_fn(event, row, old):
return False
LOG.debug("%s : Matched %s, %s, %s %s", self.event_name, self.table,
self.events, self.conditions, self.old_conditions)
return True