From d240b281129111d568d420d64450bbd0aac7a561 Mon Sep 17 00:00:00 2001 From: Roman Podoliaka Date: Mon, 23 Feb 2015 19:12:34 +0200 Subject: [PATCH] Fix the order of base classes in migrations test cases Next release of oslo.db is going to break Nova migrations tests: when a test case cleanup is run it fails to fetch 'schema' attribute of oslo.db base test case sets in its setup. The problem is that Nova base test case intentionally removes all attributes from a test case class instance in its cleanup callback (to ensure there are no memory leaks). Inheritance from Nova base test case was actually added when fixing LP #1410235, so that TIMEOUT_SCALING_FACTOR attribute would be handled properly (at that time it was done directly in Nova base test case setUp(), and now it's a separate fixture). So in order for Nova unit tests to work correctly with new release of oslo.db we need either to remove inheritance from Nova base test case or to change the order of base classes to achieve the 'proper' MRO for migration test cases. The latter can actually be problematic as we also need to ensure TIMEOUT_SCALING_FACTOR is still handled properly and not overridden by oslotest base test case. Related-Bug: #1410235 Change-Id: I5c7d2a391425766a5e8fd61a532b1a1e7d410770 --- nova/tests/unit/db/test_migrations.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/nova/tests/unit/db/test_migrations.py b/nova/tests/unit/db/test_migrations.py index 63985d399261..c3a79dd11715 100644 --- a/nova/tests/unit/db/test_migrations.py +++ b/nova/tests/unit/db/test_migrations.py @@ -57,6 +57,7 @@ from nova.db.sqlalchemy import models from nova.db.sqlalchemy import utils as db_utils from nova import exception from nova import test +from nova.tests import fixtures as nova_fixtures LOG = logging.getLogger(__name__) @@ -97,6 +98,14 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync, migrate_log.setLevel(logging.WARN) self.addCleanup(migrate_log.setLevel, old_level) + # NOTE(rpodolyaka): we need to repeat the functionality of the base + # test case a bit here as this gets overriden by oslotest base test + # case and nova base test case cleanup must be the last one (as it + # deletes attributes of test case instances) + self.useFixture(nova_fixtures.Timeout( + os.environ.get('OS_TEST_TIMEOUT', 0), + self.TIMEOUT_SCALING_FACTOR)) + def assertColumnExists(self, engine, table_name, column): self.assertTrue(oslodbutils.column_exists(engine, table_name, column)) @@ -809,14 +818,14 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync, class TestNovaMigrationsSQLite(NovaMigrationsCheckers, - test.TestCase, - test_base.DbTestCase): + test_base.DbTestCase, + test.NoDBTestCase): pass class TestNovaMigrationsMySQL(NovaMigrationsCheckers, - test.TestCase, - test_base.MySQLOpportunisticTestCase): + test_base.MySQLOpportunisticTestCase, + test.NoDBTestCase): def test_innodb_tables(self): with mock.patch.object(sa_migration, 'get_engine', return_value=self.migrate_engine): @@ -841,8 +850,8 @@ class TestNovaMigrationsMySQL(NovaMigrationsCheckers, class TestNovaMigrationsPostgreSQL(NovaMigrationsCheckers, - test.TestCase, - test_base.PostgreSQLOpportunisticTestCase): + test_base.PostgreSQLOpportunisticTestCase, + test.NoDBTestCase): pass