This patch changes what is being returned from Idl.run() to a tuple
(changed, changes) so one can determine what changes have occurred to
the database without having to read the entire table.

Signed-off-by: Aaron Rosen <aro...@nicira.com>
---
 python/ovs/db/idl.py |   16 ++++++++++------
 tests/test-ovsdb.py  |    4 ++--
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 55fbcba..095cf4f 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -134,11 +134,13 @@ class Idl:

     def run(self):
         """Processes a batch of messages from the database server.  Returns
-        True if the database as seen through the IDL changed, False if it
did
-        not change.  The initial fetch of the entire contents of the remote
-        database is considered to be one kind of change.  If the IDL has
been
-        configured to acquire a database lock (with Idl.set_lock()), then
-        successfully acquiring the lock is also considered to be a change.
+        a tuple (changed, changes) where changed is True if the database as
+        seen through the IDL changed, False if it did not change. The
changes
+        variable contain all of the jsonrpc messages that have been
processed.
+        The initial fetch of the entire contents of the remote database is
+        considered to be one kind of change.  If the IDL has been
configured
+        to acquire a database lock (with Idl.set_lock()), then successfully
+        acquiring the lock is also considered to be a change.

         This function can return occasional false positives, that is,
report
         that the database changed even though it didn't.  This happens if
the
@@ -153,6 +155,7 @@ class Idl:
         assert not self.txn
         initial_change_seqno = self.change_seqno
         self._session.run()
+        changes = []
         i = 0
         while i < 50:
             i += 1
@@ -171,6 +174,7 @@ class Idl:
             msg = self._session.recv()
             if msg is None:
                 break
+            changes.append(msg)
             if (msg.type == ovs.jsonrpc.Message.T_NOTIFY
                 and msg.method == "update"
                 and len(msg.params) == 2
@@ -218,7 +222,7 @@ class Idl:
                          % (self._session.get_name(),
                              ovs.jsonrpc.Message.type_to_string(msg.type)))

-        return initial_change_seqno != self.change_seqno
+        return (initial_change_seqno != self.change_seqno, changes)

     def wait(self, poller):
         """Arranges for poller.block() to wake up when self.run() has
something
diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py
index 392ed4b..afc8287 100644
--- a/tests/test-ovsdb.py
+++ b/tests/test-ovsdb.py
@@ -366,7 +366,7 @@ def do_idl(schema_file, remote, *commands):
             command = command[1:]
         else:
             # Wait for update.
-            while idl.change_seqno == seqno and not idl.run():
+            while idl.change_seqno == seqno and not idl.run()[0]:
                 rpc.run()

                 poller = ovs.poller.Poller()
@@ -415,7 +415,7 @@ def do_idl(schema_file, remote, *commands):

     if rpc:
         rpc.close()
-    while idl.change_seqno == seqno and not idl.run():
+    while idl.change_seqno == seqno and not idl.run()[0]:
         poller = ovs.poller.Poller()
         idl.wait(poller)
         poller.block()
-- 
1.7.9.5
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to