Browse Source

Functional: Workaround database failures

This patch inherited and modified the mehtod that creates the database
for the functional tests to:

1. Make it atomic by using a lock

2. Removed the singleton nature of it. Prior to this patch, the tests
kept a single shared in-memory database. Now, each test will have its
own in-memory database.

3. Handle the DBNonExistentTable for failures in the cleanUp() method
while deleting the db tables.

Partial-Bug: #1808146
Change-Id: I90a50fe1284078f5a5719da54599d4cddc5bd06f
Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
Lucas Alvares Gomes 3 months ago
parent
commit
29d07bec16
1 changed files with 36 additions and 0 deletions
  1. 36
    0
      networking_ovn/tests/functional/base.py

+ 36
- 0
networking_ovn/tests/functional/base.py View File

@@ -20,9 +20,13 @@ import mock
20 20
 from neutron.conf.plugins.ml2 import config
21 21
 from neutron.plugins.ml2.drivers import type_geneve  # noqa
22 22
 from neutron.tests.unit.plugins.ml2 import test_plugin
23
+from neutron.tests.unit import testlib_api
23 24
 from neutron_lib.plugins import constants
24 25
 from neutron_lib.plugins import directory
26
+from oslo_concurrency import lockutils
25 27
 from oslo_config import cfg
28
+from oslo_db import exception as os_db_exc
29
+from oslo_db.sqlalchemy import provision
26 30
 from oslo_log import log
27 31
 from oslo_utils import uuidutils
28 32
 from ovsdbapp.backend.ovs_idl import command
@@ -41,6 +45,7 @@ LOG = log.getLogger(__name__)
41 45
 # This is the directory from which infra fetches log files for functional tests
42 46
 DEFAULT_LOG_DIR = os.path.join(os.environ.get('OS_LOG_PATH', '/tmp'),
43 47
                                'dsvm-functional-logs')
48
+SQL_FIXTURE_LOCK = 'sql_fixture_lock'
44 49
 
45 50
 
46 51
 class AddFakeChassisCommand(command.BaseCommand):
@@ -79,6 +84,27 @@ class ConnectionFixture(fixtures.Fixture):
79 84
         self.connection.stop()
80 85
 
81 86
 
87
+class OVNSqlFixture(testlib_api.StaticSqlFixture):
88
+
89
+    @classmethod
90
+    @lockutils.synchronized(SQL_FIXTURE_LOCK)
91
+    def _init_resources(cls):
92
+        cls.schema_resource = provision.SchemaResource(
93
+            provision.DatabaseResource("sqlite"),
94
+            cls._generate_schema, teardown=False)
95
+        dependency_resources = {}
96
+        for name, resource in cls.schema_resource.resources:
97
+            dependency_resources[name] = resource.getResource()
98
+        cls.schema_resource.make(dependency_resources)
99
+        cls.engine = dependency_resources['database'].engine
100
+
101
+    def _delete_from_schema(self, engine):
102
+        try:
103
+            super(OVNSqlFixture, self)._delete_from_schema(engine)
104
+        except os_db_exc.DBNonExistentTable:
105
+            pass
106
+
107
+
82 108
 class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
83 109
 
84 110
     # Please see networking_ovn/tests/contrib/gate_hook.sh.
@@ -117,6 +143,16 @@ class TestOVNFunctionalBase(test_plugin.Ml2PluginV2TestCase):
117 143
         self._start_ovsdb_server_and_idls()
118 144
         self._start_ovn_northd()
119 145
 
146
+    # FIXME(lucasagomes): Workaround for
147
+    # https://bugs.launchpad.net/networking-ovn/+bug/1808146. We should
148
+    # investigate and properly fix the problem. This method is just a
149
+    # workaround to alleviate the gate for now and should not be considered
150
+    # a proper fix.
151
+    def _setup_database_fixtures(self):
152
+        fixture = OVNSqlFixture()
153
+        self.useFixture(fixture)
154
+        self.engine = fixture.engine
155
+
120 156
     def get_additional_service_plugins(self):
121 157
         p = super(TestOVNFunctionalBase, self).get_additional_service_plugins()
122 158
         p.update({'revision_plugin_name': 'revisions'})

Loading…
Cancel
Save