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
This commit is contained in:
Frank Wang 2019-03-19 15:48:43 +08:00
parent 745d94e0b1
commit 3c6c766847
2 changed files with 12 additions and 2 deletions

View File

@ -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):

View File

@ -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)