Don't throw NotConnectedError in queue_txn

Before Ifc74a834ca1a7d914c7ca66d71b47694f9eef1e5, queueing a
transaction before we had connected to an ovsdb-server would
happily work. When the connection started, the run() method would
pull the queued transaction off the queue and process it. Adding
the exception added a race condition in existing code, so this
patch removes it.

Change-Id: I0b620b0040ef5f7cb99d2f27140f605e97f95512
Related-Bug: #1731063
This commit is contained in:
Terry Wilson 2017-11-28 23:26:58 -06:00
parent 158ae06bce
commit 8ffd90dbf3
3 changed files with 7 additions and 11 deletions

View File

@ -21,7 +21,6 @@ from ovs import poller
from six.moves import queue as Queue
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp import exceptions
if os.name == 'nt':
from ovsdbapp.backend.ovs_idl.windows import connection_utils
@ -116,8 +115,8 @@ class Connection(object):
return True
def queue_txn(self, txn):
if not self._is_running:
raise exceptions.NotConnectedError(txn=txn)
# Even if we aren't started, we can queue a transaction and it will
# run when we are started
self.txns.put(txn)

View File

@ -59,7 +59,3 @@ class OvsdbConnectionUnavailable(OvsdbAppException):
"'%(error)s'. Verify that the OVS and OVN services are "
"available and that the 'ovn_nb_connection' and "
"'ovn_sb_connection' configuration options are correct.")
class NotConnectedError(OvsdbAppException):
message = "Cannot commit transaction %(txn)s. Not connected"

View File

@ -104,11 +104,12 @@ class TestOvsdbIdl(base.FunctionalTestCase):
def test_connection_reconnect(self):
self.api.ovsdb_connection.stop()
existsCmd = self.api.br_exists(self.brname)
self.assertRaises(exc.NotConnectedError,
existsCmd.execute, check_error=True)
txn = self.api.create_transaction(check_error=True)
txn.add(existsCmd)
self.api.ovsdb_connection.queue_txn(txn)
self.api.ovsdb_connection.start()
exists = self.api.br_exists(self.brname).execute(check_error=True)
self.assertFalse(exists)
result = txn.results.get(timeout=self.api.ovsdb_connection.timeout)
self.assertEqual(result, [False])
def test_connection_disconnect_timeout(self):
_is_running_mock = mock.PropertyMock(return_value=True)