Merge "Allow OVSDB Connection to register certain tables"
This commit is contained in:
commit
ba8c051401
neutron
@ -59,7 +59,14 @@ class Connection(object):
|
||||
self.lock = threading.Lock()
|
||||
self.schema_name = schema_name
|
||||
|
||||
def start(self):
|
||||
def start(self, table_name_list=None):
|
||||
"""
|
||||
: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.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.idl is not None:
|
||||
return
|
||||
@ -79,7 +86,11 @@ class Connection(object):
|
||||
self.schema_name)
|
||||
helper = do_get_schema_helper()
|
||||
|
||||
helper.register_all()
|
||||
if table_name_list is None:
|
||||
helper.register_all()
|
||||
else:
|
||||
for table_name in table_name_list:
|
||||
helper.register_table(table_name)
|
||||
self.idl = idl.Idl(self.connection, helper)
|
||||
idlutils.wait_for_change(self.idl, self.timeout)
|
||||
self.poller = poller.Poller()
|
||||
|
55
neutron/tests/unit/agent/ovsdb/native/test_connection.py
Normal file
55
neutron/tests/unit/agent/ovsdb/native/test_connection.py
Normal file
@ -0,0 +1,55 @@
|
||||
# Copyright 2015, Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import unittest2
|
||||
|
||||
try:
|
||||
from ovs.db import idl
|
||||
except ImportError:
|
||||
raise unittest2.SkipTest(
|
||||
"Skip test since ovs requirement for PY3 doesn't support yet.")
|
||||
|
||||
from neutron.agent.ovsdb.native import connection
|
||||
from neutron.agent.ovsdb.native import idlutils
|
||||
from neutron.tests import base
|
||||
from neutron.tests.common import helpers
|
||||
|
||||
|
||||
class TestOVSNativeConnection(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestOVSNativeConnection, self).setUp()
|
||||
|
||||
@mock.patch.object(connection, 'TransactionQueue')
|
||||
@mock.patch.object(idlutils, 'get_schema_helper')
|
||||
@mock.patch.object(idl, 'Idl')
|
||||
@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())
|
||||
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)
|
||||
|
||||
@helpers.requires_py2
|
||||
def test_start_without_table_name_list(self):
|
||||
self._test_start()
|
||||
|
||||
@helpers.requires_py2
|
||||
def test_start_with_table_name_list(self):
|
||||
self._test_start(table_name_list=['fake-table1', 'fake-table2'])
|
Loading…
Reference in New Issue
Block a user