Allow to override Idl class in OVSDB Connection
Add an option to neutron.agent.ovsdb.native.connection.Connection to
override the Idl class that is created to communicate with OVSDB.
This is a feature that would help in Dragonflow[1], where the notify
method should be overriden before start() is called, in order to receive
all events in real-time, and not retroactively.
[1] d17ae9705a/dragonflow/ovsdb/impl_idl.py (L135)
Change-Id: I49da05f02a00352b1b1db863d244e97f9c148804
Closes-Bug: 1627615
This commit is contained in:
parent
cae38fb392
commit
070ee35b9c
|
@ -53,13 +53,14 @@ class TransactionQueue(Queue.Queue, object):
|
|||
|
||||
|
||||
class Connection(object):
|
||||
def __init__(self, connection, timeout, schema_name):
|
||||
def __init__(self, connection, timeout, schema_name, idl_class=None):
|
||||
self.idl = None
|
||||
self.connection = connection
|
||||
self.timeout = timeout
|
||||
self.txns = TransactionQueue(1)
|
||||
self.lock = threading.Lock()
|
||||
self.schema_name = schema_name
|
||||
self.idl_class = idl_class or idl.Idl
|
||||
|
||||
def start(self, table_name_list=None):
|
||||
"""
|
||||
|
@ -93,7 +94,7 @@ class Connection(object):
|
|||
else:
|
||||
for table_name in table_name_list:
|
||||
helper.register_table(table_name)
|
||||
self.idl = idl.Idl(self.connection, helper)
|
||||
self.idl = self.idl_class(self.connection, helper)
|
||||
idlutils.wait_for_change(self.idl, self.timeout)
|
||||
self.poller = poller.Poller()
|
||||
self.thread = threading.Thread(target=self.run)
|
||||
|
|
|
@ -57,3 +57,15 @@ class TestOVSNativeConnection(base.BaseTestCase):
|
|||
# a test to cover py34 failure during initialization (LP Bug #1580270)
|
||||
# make sure no ValueError: can't have unbuffered text I/O is raised
|
||||
connection.TransactionQueue()
|
||||
|
||||
@mock.patch.object(connection, 'TransactionQueue')
|
||||
@mock.patch.object(idlutils, 'get_schema_helper')
|
||||
@mock.patch.object(idlutils, 'wait_for_change')
|
||||
def test_start_with_idl_class(self, wait_for_change, get_schema_helper,
|
||||
transaction_queue):
|
||||
idl_class = mock.Mock()
|
||||
self.connection = connection.Connection(
|
||||
mock.sentinel, mock.sentinel, mock.sentinel, idl_class=idl_class)
|
||||
idl_instance = idl_class.return_value
|
||||
self.connection.start()
|
||||
self.assertEqual(idl_instance, self.connection.idl)
|
||||
|
|
Loading…
Reference in New Issue