From 667ea2ac7c1ef8ce6f52072639a13a833533f3ea Mon Sep 17 00:00:00 2001 From: lzklibj Date: Mon, 11 Apr 2016 15:15:05 +0800 Subject: [PATCH] Allow OVSDB Connection to register certain tables Current OVSDB Connection will register all tables with schema_helper. It doesn't matter for most cases, but for implementation for bp routed-networks in networking-ovn, we don't need all tables in OVN_ Southbound DB are registered. We only need a certain table named Chassis can be registered. This patch add a parameter for OVSDB Connection to allow it to register certain tables, instead of all tables. Change-Id: I79df60a08a7a6c555b07a9b566d7c09b97e2463c Closes-Bug: #1568718 --- neutron/agent/ovsdb/native/connection.py | 15 ++++- .../agent/ovsdb/native/test_connection.py | 55 +++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 neutron/tests/unit/agent/ovsdb/native/test_connection.py diff --git a/neutron/agent/ovsdb/native/connection.py b/neutron/agent/ovsdb/native/connection.py index 22724f68a45..248725c4441 100644 --- a/neutron/agent/ovsdb/native/connection.py +++ b/neutron/agent/ovsdb/native/connection.py @@ -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() diff --git a/neutron/tests/unit/agent/ovsdb/native/test_connection.py b/neutron/tests/unit/agent/ovsdb/native/test_connection.py new file mode 100644 index 00000000000..0dee11561d3 --- /dev/null +++ b/neutron/tests/unit/agent/ovsdb/native/test_connection.py @@ -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'])