From bbbcb55d12748566012bc217d3ae60515109d948 Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Fri, 3 Jan 2020 09:26:00 -0600 Subject: [PATCH] Remove sqlalchemy-migrate 0.7.3 patching This is similar to upstream submissions in 2013 such as https://review.opendev.org/#/c/56705/ We currently build, test and ship with a newer version of sqlalchemy-migrate 0.11.0 so we do not need to handle 0.7.3 workarounds and patches. This review also fixes: tests.db.sqlalchemy.test_migrations which would fail when tested in isolation, due to its environment not being initialized properly, but working if certain other tests were run first. Some skipped tests are now also enabled. Change-Id: I6ce73491f7a2471f25c7691dab8b53dc354619a2 Story: 2004515 Task: 37954 Signed-off-by: Al Bailey --- .../sysinv/sysinv/db/sqlalchemy/migration.py | 29 ------------------- .../tests/db/sqlalchemy/test_migrations.py | 6 ++-- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/migration.py b/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/migration.py index 53e4a72585..593b211a9c 100644 --- a/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/migration.py +++ b/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/migration.py @@ -16,11 +16,7 @@ # License for the specific language governing permissions and limitations # under the License. -import distutils.version as dist_version import os - -import migrate -from migrate.versioning import util as migrate_util import sqlalchemy from oslo_db.sqlalchemy import enginefacade @@ -28,31 +24,6 @@ from sysinv._i18n import _ from sysinv.common import exception from sysinv.db import migration - -@migrate_util.decorator -def patched_with_engine(f, *a, **kw): - url = a[0] - engine = migrate_util.construct_engine(url, **kw) - - try: - kw['engine'] = engine - return f(*a, **kw) - finally: - if isinstance(engine, migrate_util.Engine) and engine is not url: - migrate_util.log.debug('Disposing SQLAlchemy engine %s', engine) - engine.dispose() - - -# TODO(jkoelker) When migrate 0.7.3 is released and nova depends -# on that version or higher, this can be removed -MIN_PKG_VERSION = dist_version.StrictVersion('0.7.3') -if (not hasattr(migrate, '__version__') or - dist_version.StrictVersion(migrate.__version__) < MIN_PKG_VERSION): - - migrate_util.with_engine = patched_with_engine - - -# NOTE(jkoelker) Delay importing migrate until we are patched from migrate import exceptions as versioning_exceptions from migrate.versioning import api as versioning_api from migrate.versioning.repository import Repository diff --git a/sysinv/sysinv/sysinv/sysinv/tests/db/sqlalchemy/test_migrations.py b/sysinv/sysinv/sysinv/sysinv/tests/db/sqlalchemy/test_migrations.py index 9c6758a884..52100daed8 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/db/sqlalchemy/test_migrations.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/db/sqlalchemy/test_migrations.py @@ -51,11 +51,13 @@ import sqlalchemy.exc from migrate.versioning import repository from oslo_db.sqlalchemy import utils as db_utils +from oslo_config import cfg from oslo_log import log as logging from sqlalchemy import MetaData, Table from sysinv.openstack.common import lockutils import sysinv.db.sqlalchemy.migrate_repo +from sysinv.tests import conf_fixture from sysinv.tests import utils as test_utils LOG = logging.getLogger(__name__) @@ -519,6 +521,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin): def setUp(self): super(TestMigrations, self).setUp() + self.useFixture(conf_fixture.ConfFixture(cfg.CONF)) + if six.PY2: version = -1 else: @@ -665,13 +669,11 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin): def test_postgresql_opportunistically(self): # Test is skipped because postgresql isn't present/configured on target # server and will cause errors. Skipped to prevent Jenkins notification. - self.skipTest("Skipping to prevent postgres from throwing error in Jenkins") self._test_postgresql_opportunistically() def test_postgresql_connect_fail(self): # Test is skipped because postgresql isn't present/configured on target # server and will cause errors. Skipped to prevent Jenkins notification. - self.skipTest("Skipping to prevent postgres from throwing error in Jenkins") """Test that we can trigger a postgres connection failure Test that we can fail gracefully to ensure we don't break people