]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enhance OVSDB Transaction timeout configuration
authorGal Sagie <gal.sagie@huawei.com>
Wed, 15 Apr 2015 06:26:54 +0000 (09:26 +0300)
committerGal Sagie <gal.sagie@huawei.com>
Wed, 15 Apr 2015 06:26:54 +0000 (09:26 +0300)
OVSDB Transaction currently takes the timeout parameter
from a context object that assume to have a vsctl_timeout attribute
This doesnt fit well for other users of this class (like OVN)

This fix configure the transaction timeout in a more common way

Change-Id: I51bb8d8fdc6d061d44af828818aaf62e187795fd
Closes-Bug: #1444277

neutron/agent/ovsdb/impl_idl.py

index 011db3a91d60fd98e01aaeff2caa0a94da9c96a0..4a73707811543cd1046bac44c6346ad3c943d38b 100644 (file)
@@ -40,15 +40,15 @@ LOG = logging.getLogger(__name__)
 
 
 class Transaction(api.Transaction):
-    def __init__(self, context, api, ovsdb_connection,
+    def __init__(self, api, ovsdb_connection, timeout,
                  check_error=False, log_errors=False):
-        self.context = context
         self.api = api
         self.check_error = check_error
         self.log_errors = log_errors
         self.commands = []
         self.results = Queue.Queue(1)
         self.ovsdb_connection = ovsdb_connection
+        self.timeout = timeout
 
     def add(self, command):
         """Add a command to the transaction
@@ -74,7 +74,7 @@ class Transaction(api.Transaction):
         attempts = 0
         while True:
             elapsed_time = time.time() - start_time
-            if attempts > 0 and elapsed_time > self.context.vsctl_timeout:
+            if attempts > 0 and elapsed_time > self.timeout:
                 raise RuntimeError("OVS transaction timed out")
             attempts += 1
             # TODO(twilson) Make sure we don't loop longer than vsctl_timeout
@@ -97,7 +97,7 @@ class Transaction(api.Transaction):
                     LOG.debug("Lost connection to OVSDB, reconnecting!")
                     self.api.idl.force_reconnect()
                 idlutils.wait_for_change(
-                    self.api.idl, self.context.vsctl_timeout - elapsed_time,
+                    self.api.idl, self.timeout - elapsed_time,
                     seqno)
                 continue
             elif status == txn.ERROR:
@@ -137,7 +137,8 @@ class OvsdbIdl(api.API):
         return self._tables['Open_vSwitch'].rows.values()[0]
 
     def transaction(self, check_error=False, log_errors=True, **kwargs):
-        return Transaction(self.context, self, OvsdbIdl.ovsdb_connection,
+        return Transaction(self, OvsdbIdl.ovsdb_connection,
+                           self.context.vsctl_timeout,
                            check_error, log_errors)
 
     def add_br(self, name, may_exist=True):