diff --git a/cinderlib/persistence/dbms.py b/cinderlib/persistence/dbms.py index ef76b15..3fceddc 100644 --- a/cinderlib/persistence/dbms.py +++ b/cinderlib/persistence/dbms.py @@ -15,13 +15,14 @@ import logging +import alembic.script.revision +import alembic.util.exc from cinder.db import api as db_api from cinder.db import migration from cinder.db.sqlalchemy import api as sqla_api from cinder.db.sqlalchemy import models from cinder import exception as cinder_exception from cinder import objects as cinder_objs -import migrate from oslo_config import cfg from oslo_db import exception from oslo_db.sqlalchemy import models as oslo_db_models @@ -79,9 +80,9 @@ class DBPersistence(persistence_base.PersistenceDriverBase): sqlite_synchronous, 'database') - # Suppress logging for migration - migrate_logger = logging.getLogger('migrate') - migrate_logger.setLevel(logging.WARNING) + # Suppress logging for alembic + alembic_logger = logging.getLogger('alembic.runtime.migration') + alembic_logger.setLevel(logging.WARNING) self._clear_facade() self.db_instance = db_api.oslo_db_api.DBAPI.from_config( @@ -99,13 +100,15 @@ class DBPersistence(persistence_base.PersistenceDriverBase): try: migration.db_sync() - except exception.DBMigrationError as exc: + except alembic.util.exc.CommandError as exc: # We can be running 2 Cinder versions at the same time on the same # DB while we upgrade, so we must ignore the fact that the DB is # now on a newer version. - if not isinstance(getattr(exc, 'inner_exception', None), - migrate.exceptions.VersionNotFoundError): + if not isinstance( + exc.__cause__, alembic.script.revision.ResolutionError, + ): raise + self._create_key_value_table() # NOTE : At this point, the persistence isn't ready so we need to use diff --git a/cinderlib/tests/unit/persistence/test_dbms.py b/cinderlib/tests/unit/persistence/test_dbms.py index 1c825e0..10f4ee5 100644 --- a/cinderlib/tests/unit/persistence/test_dbms.py +++ b/cinderlib/tests/unit/persistence/test_dbms.py @@ -16,6 +16,8 @@ import tempfile from unittest import mock +import alembic.script.revision +import alembic.util.exc from cinder.db.sqlalchemy import api as sqla_api from cinder.db.sqlalchemy import models as sqla_models from cinder import objects as cinder_ovos @@ -152,10 +154,10 @@ class TestDBPersistenceNewerSchema(base.helper.TestHelper): pass def _raise_exc(self): - inner_exc = dbms.migrate.exceptions.VersionNotFoundError() - exc = dbms.exception.DBMigrationError(inner_exc) + inner_exc = alembic.script.revision.ResolutionError('foo', 'rev') + outer_exc = alembic.util.exc.CommandError('bar') self.original_db_sync() - raise(exc) + raise outer_exc from inner_exc def test_newer_db_schema(self): self.original_db_sync = dbms.migration.db_sync diff --git a/requirements.txt b/requirements.txt index cf850bc..1d5cc3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,3 @@ os-brick>=6.3.0 # Apache-2.0 importlib_metadata>=1.7.0 # Apache-2.0 importlib_resources>=3.2.1;python_version<'3.10' # Apache-2.0 - -# TODO: cinder removed this as a dependency in 2023.2 (Bobcat) -# but we need to include it here until cinderlib catches up -sqlalchemy-migrate>=0.13.0 # Apache-2.0