Merge "Remove all the deprecated methods and parameters from Connection"
This commit is contained in:
commit
342f70083a
@ -16,8 +16,6 @@ import os
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from debtcollector import removals
|
||||
from ovs.db import idl
|
||||
from ovs import poller
|
||||
import six
|
||||
from six.moves import queue as Queue
|
||||
@ -53,62 +51,21 @@ class TransactionQueue(Queue.Queue, object):
|
||||
|
||||
|
||||
class Connection(object):
|
||||
__rm_args = {'version': 'Ocata', 'removal_version': 'Pike',
|
||||
'message': 'Use an idl_factory function instead'}
|
||||
|
||||
@removals.removed_kwarg('connection', **__rm_args)
|
||||
@removals.removed_kwarg('schema_name', **__rm_args)
|
||||
@removals.removed_kwarg('idl_class', **__rm_args)
|
||||
def __init__(self, connection=None, timeout=None, schema_name=None,
|
||||
idl_class=None, idl_factory=None):
|
||||
def __init__(self, idl_factory, timeout):
|
||||
"""Create a connection to an OVSDB server using the OVS IDL
|
||||
|
||||
:param connection: (deprecated) An OVSDB connection string
|
||||
:param timeout: The timeout value for OVSDB operations (required)
|
||||
:param schema_name: (deprecated) The name ovs the OVSDB schema to use
|
||||
:param idl_class: (deprecated) An Idl subclass. Defaults to idl.Idl
|
||||
:param timeout: The timeout value for OVSDB operations
|
||||
:param idl_factory: A factory function that produces an Idl instance
|
||||
|
||||
The signature of this class is changing. It is recommended to pass in
|
||||
a timeout and idl_factory
|
||||
"""
|
||||
assert timeout is not None
|
||||
self.idl = None
|
||||
self.timeout = timeout
|
||||
self.txns = TransactionQueue(1)
|
||||
self.lock = threading.Lock()
|
||||
if idl_factory:
|
||||
if connection or schema_name:
|
||||
raise TypeError('Connection: Takes either idl_factory, or '
|
||||
'connection and schema_name. Both given')
|
||||
self.idl_factory = idl_factory
|
||||
else:
|
||||
if not connection or not schema_name:
|
||||
raise TypeError('Connection: Takes either idl_factory, or '
|
||||
'connection and schema_name. Neither given')
|
||||
self.idl_factory = self._idl_factory
|
||||
self.connection = connection
|
||||
self.schema_name = schema_name
|
||||
self.idl_class = idl_class or idl.Idl
|
||||
self._schema_filter = None
|
||||
self.idl_factory = idl_factory
|
||||
|
||||
@removals.remove(**__rm_args)
|
||||
def _idl_factory(self):
|
||||
helper = self.get_schema_helper()
|
||||
self.update_schema_helper(helper)
|
||||
return self.idl_class(self.connection, helper)
|
||||
|
||||
@removals.removed_kwarg('table_name_list', **__rm_args)
|
||||
def start(self, table_name_list=None):
|
||||
"""Start the connection.
|
||||
|
||||
:param table_name_list: A list of table names for schema_helper to
|
||||
register. When this parameter is given, schema_helper will only
|
||||
register tables which name are in list. Otherwise,
|
||||
schema_helper will register all tables for given schema_name as
|
||||
default.
|
||||
"""
|
||||
self._schema_filter = table_name_list
|
||||
def start(self):
|
||||
"""Start the connection."""
|
||||
with self.lock:
|
||||
if self.idl is not None:
|
||||
return
|
||||
@ -120,23 +77,6 @@ class Connection(object):
|
||||
self.thread.setDaemon(True)
|
||||
self.thread.start()
|
||||
|
||||
@removals.remove(
|
||||
version='Ocata', removal_version='Pike',
|
||||
message="Use idlutils.get_schema_helper(conn, schema, retry=True)")
|
||||
def get_schema_helper(self):
|
||||
"""Retrieve the schema helper object from OVSDB"""
|
||||
return idlutils.get_schema_helper(self.connection, self.schema_name)
|
||||
|
||||
@removals.remove(
|
||||
version='Ocata', removal_version='Pike',
|
||||
message="Use an idl_factory and ovs.db.SchemaHelper for filtering")
|
||||
def update_schema_helper(self, helper):
|
||||
if self._schema_filter:
|
||||
for table_name in self._schema_filter:
|
||||
helper.register_table(table_name)
|
||||
else:
|
||||
helper.register_all()
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
self.idl.wait(self.poller)
|
||||
|
@ -13,9 +13,8 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import time
|
||||
import threading
|
||||
|
||||
from ovs.db import idl
|
||||
from ovs import poller
|
||||
|
||||
from ovsdbapp.backend.ovs_idl import connection
|
||||
@ -26,57 +25,36 @@ from ovsdbapp.tests import base
|
||||
class TestOVSNativeConnection(base.TestCase):
|
||||
|
||||
@mock.patch.object(connection, 'TransactionQueue')
|
||||
@mock.patch.object(idlutils, 'get_schema_helper')
|
||||
@mock.patch.object(idl, 'Idl')
|
||||
def setUp(self, mock_trans_queue):
|
||||
super(TestOVSNativeConnection, self).setUp()
|
||||
self.idl_factory = mock.Mock()
|
||||
self.mock_trans_queue = mock_trans_queue
|
||||
self.conn = connection.Connection(self.idl_factory,
|
||||
timeout=1)
|
||||
self.mock_trans_queue.assert_called_once_with(1)
|
||||
|
||||
@mock.patch.object(threading, 'Thread')
|
||||
@mock.patch.object(poller, 'Poller')
|
||||
@mock.patch.object(idlutils, 'wait_for_change')
|
||||
def _test_start(self, wfc, idl, gsh, tq, table_name_list=None):
|
||||
gsh.return_value = helper = mock.Mock()
|
||||
self.connection = connection.Connection(
|
||||
mock.Mock(), mock.Mock(), mock.Mock())
|
||||
with mock.patch.object(poller, 'Poller') as poller_mock,\
|
||||
mock.patch('threading.Thread'):
|
||||
poller_mock.return_value.block.side_effect = time.sleep
|
||||
self.connection.start(table_name_list=table_name_list)
|
||||
reg_all_called = table_name_list is None
|
||||
reg_table_called = table_name_list is not None
|
||||
self.assertEqual(reg_all_called, helper.register_all.called)
|
||||
self.assertEqual(reg_table_called, helper.register_table.called)
|
||||
def test_start(self, mock_wait_for_change, mock_poller, mock_thread):
|
||||
self.conn.start()
|
||||
|
||||
def test_start_without_table_name_list(self):
|
||||
self._test_start()
|
||||
self.idl_factory.assert_called_once_with()
|
||||
mock_wait_for_change.assert_called_once_with(self.conn.idl,
|
||||
self.conn.timeout)
|
||||
mock_poller.assert_called_once_with()
|
||||
mock_thread.assert_called_once_with(target=self.conn.run)
|
||||
mock_thread.return_value.setDaemon.assert_called_once_with(True)
|
||||
mock_thread.return_value.start.assert_called_once_with()
|
||||
|
||||
def test_start_with_table_name_list(self):
|
||||
self._test_start(table_name_list=['fake-table1', 'fake-table2'])
|
||||
def test_queue_txn(self):
|
||||
self.conn.queue_txn('blah')
|
||||
self.conn.txns.put.assert_called_once_with('blah')
|
||||
|
||||
@mock.patch.object(connection, 'TransactionQueue')
|
||||
@mock.patch.object(idl, 'Idl')
|
||||
@mock.patch.object(idlutils, 'wait_for_change')
|
||||
def test_start_call_graph(self, wait_for_change, idl, transaction_queue):
|
||||
self.connection = connection.Connection(
|
||||
mock.sentinel, mock.sentinel, mock.sentinel)
|
||||
self.connection.get_schema_helper = mock.Mock()
|
||||
helper = self.connection.get_schema_helper.return_value
|
||||
self.connection.update_schema_helper = mock.Mock()
|
||||
with mock.patch.object(poller, 'Poller') as poller_mock,\
|
||||
mock.patch('threading.Thread'):
|
||||
poller_mock.return_value.block.side_effect = time.sleep
|
||||
self.connection.start()
|
||||
self.connection.get_schema_helper.assert_called_once_with()
|
||||
self.connection.update_schema_helper.assert_called_once_with(helper)
|
||||
|
||||
def test_transaction_queue_init(self):
|
||||
class TestTransactionQueue(base.TestCase):
|
||||
|
||||
def test_init(self):
|
||||
# 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
Block a user