From 0320e78c2c1d04118cd10182c2e0c476950ba776 Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Sun, 31 May 2020 21:19:06 -0500 Subject: [PATCH] Only create indices if connection is not running Also adds some better debug logs when creating indexes Related-Bug: #1881424 Change-Id: I094dd475bb6956a3c029075ad85dbc15cf59a16c --- ovsdbapp/backend/ovs_idl/__init__.py | 17 +++++++++++------ ovsdbapp/backend/ovs_idl/connection.py | 12 ++++++------ .../schema/open_vswitch/test_impl_idl.py | 6 +++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ovsdbapp/backend/ovs_idl/__init__.py b/ovsdbapp/backend/ovs_idl/__init__.py index ef7fbab6..62ce345e 100644 --- a/ovsdbapp/backend/ovs_idl/__init__.py +++ b/ovsdbapp/backend/ovs_idl/__init__.py @@ -30,7 +30,10 @@ class Backend(object): super(Backend, self).__init__(**kwargs) self.ovsdb_connection = connection if auto_index: - self.autocreate_indices() + if connection.is_running: + LOG.debug("Connection already started, not creating indices") + else: + self.autocreate_indices() if start: self.start_connection(connection) @@ -75,11 +78,12 @@ class Backend(object): try: idx = self.idl.tables[table].rows.index_create(index_name) except ValueError: - # index already exists - pass + LOG.debug("lookup_table index %s.%s already exists", table, + index_name) else: idx.add_column(col) - LOG.debug("Created index %s", index_name) + LOG.debug("Created lookup_table index %s.%s", table, + index_name) tables.remove(table) # Simple ovsdb-schema indices @@ -93,10 +97,11 @@ class Backend(object): try: idx = table.rows.index_create(index_name) except ValueError: - pass # index already exists + LOG.debug("schema index %s.%s already exists", table, + index_name) else: idx.add_column(col) - LOG.debug("Created index %s", index_name) + LOG.debug("Created schema index %s.%s", table.name, index_name) tables.remove(table.name) def start_connection(self, connection): diff --git a/ovsdbapp/backend/ovs_idl/connection.py b/ovsdbapp/backend/ovs_idl/connection.py index 3cc676fb..faf9f70a 100644 --- a/ovsdbapp/backend/ovs_idl/connection.py +++ b/ovsdbapp/backend/ovs_idl/connection.py @@ -68,7 +68,7 @@ class Connection(object): self.lock = threading.Lock() self.idl = idl self.thread = None - self._is_running = None + self.is_running = None def start(self): """Start the connection.""" @@ -83,14 +83,14 @@ class Connection(object): # An ovs.db.Idl class has no post_connect pass self.poller = poller.Poller() - self._is_running = True + self.is_running = True self.thread = threading.Thread(target=self.run) self.thread.setDaemon(True) self.thread.start() def run(self): errors = 0 - while self._is_running: + while self.is_running: # If we fail in an Idl call, we could have missed an update # from the server, leaving us out of sync with ovsdb-server. # It is not safe to continue without restarting the connection, @@ -113,7 +113,7 @@ class Connection(object): self.idl.force_reconnect() idlutils.wait_for_change(self.idl, self.timeout) continue - self._is_running = False + self.is_running = False break errors = 0 txn = self.txns.get_nowait() @@ -127,9 +127,9 @@ class Connection(object): self.txns.task_done() def stop(self, timeout=None): - if not self._is_running: + if not self.is_running: return True - self._is_running = False + self.is_running = False self.txns.put(None) self.thread.join(timeout) if self.thread.is_alive(): diff --git a/ovsdbapp/tests/functional/schema/open_vswitch/test_impl_idl.py b/ovsdbapp/tests/functional/schema/open_vswitch/test_impl_idl.py index 900ba51e..6d8b8859 100644 --- a/ovsdbapp/tests/functional/schema/open_vswitch/test_impl_idl.py +++ b/ovsdbapp/tests/functional/schema/open_vswitch/test_impl_idl.py @@ -127,10 +127,10 @@ class TestOvsdbIdl(base.FunctionalTestCase): self.assertEqual(result, [False]) def test_connection_disconnect_timeout(self): - _is_running_mock = mock.PropertyMock(return_value=True) + is_running_mock = mock.PropertyMock(return_value=True) connection = self.api.ovsdb_connection - type(connection)._is_running = _is_running_mock - self.addCleanup(delattr, type(connection), '_is_running') + type(connection).is_running = is_running_mock + self.addCleanup(delattr, type(connection), 'is_running') self.assertFalse(connection.stop(1)) def test_br_external_id(self):