From 3c6c7668470a36e9537207d37d62ca933817e644 Mon Sep 17 00:00:00 2001 From: Frank Wang Date: Tue, 19 Mar 2019 15:48:43 +0800 Subject: [PATCH] add an option to let the user choose the right time to start connection Sometimes we don't want to start connection when the IDL is created, because in some cases our resources may not be ready. so give users a choice when to connect is better. Change-Id: Iccf4c604127568719e4ebde60959f3b4ec04de58 --- ovsdbapp/backend/ovs_idl/__init__.py | 5 +++-- ovsdbapp/tests/unit/schema/open_vswitch/test_impl_idl.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ovsdbapp/backend/ovs_idl/__init__.py b/ovsdbapp/backend/ovs_idl/__init__.py index 3747340f..276f1ede 100644 --- a/ovsdbapp/backend/ovs_idl/__init__.py +++ b/ovsdbapp/backend/ovs_idl/__init__.py @@ -26,9 +26,10 @@ class Backend(object): lookup_table = {} ovsdb_connection = None - def __init__(self, connection, **kwargs): + def __init__(self, connection, start=True, **kwargs): super(Backend, self).__init__(**kwargs) - self.start_connection(connection) + if start: + self.start_connection(connection) @classmethod def start_connection(cls, connection): diff --git a/ovsdbapp/tests/unit/schema/open_vswitch/test_impl_idl.py b/ovsdbapp/tests/unit/schema/open_vswitch/test_impl_idl.py index 14a41c79..68a0b730 100644 --- a/ovsdbapp/tests/unit/schema/open_vswitch/test_impl_idl.py +++ b/ovsdbapp/tests/unit/schema/open_vswitch/test_impl_idl.py @@ -36,7 +36,16 @@ class TransactionTestCase(base.TestCase): class TestOvsdbIdl(base.TestCase): + def setUp(self): + super(TestOvsdbIdl, self).setUp() + impl_idl.OvsdbIdl.ovsdb_connection = None + def test_nested_txns(self): conn = mock.MagicMock() api = impl_idl.OvsdbIdl(conn, nested_transactions=False) self.assertFalse(api._nested_txns) + + def test_init_session(self): + conn = mock.MagicMock() + backend = impl_idl.OvsdbIdl(conn, start=False) + self.assertIsNone(backend.ovsdb_connection)