persistence: Handle switch to alembic
Change-Id: I02e3fdd7cb16ee420f47eb08ecce983f50d32697 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
98fc4b6c68
commit
f1af46dc6a
|
@ -15,13 +15,14 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import alembic.script.revision
|
||||||
|
import alembic.util.exc
|
||||||
from cinder.db import api as db_api
|
from cinder.db import api as db_api
|
||||||
from cinder.db import migration
|
from cinder.db import migration
|
||||||
from cinder.db.sqlalchemy import api as sqla_api
|
from cinder.db.sqlalchemy import api as sqla_api
|
||||||
from cinder.db.sqlalchemy import models
|
from cinder.db.sqlalchemy import models
|
||||||
from cinder import exception as cinder_exception
|
from cinder import exception as cinder_exception
|
||||||
from cinder import objects as cinder_objs
|
from cinder import objects as cinder_objs
|
||||||
import migrate
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_db import exception
|
from oslo_db import exception
|
||||||
from oslo_db.sqlalchemy import models as oslo_db_models
|
from oslo_db.sqlalchemy import models as oslo_db_models
|
||||||
|
@ -79,9 +80,9 @@ class DBPersistence(persistence_base.PersistenceDriverBase):
|
||||||
sqlite_synchronous,
|
sqlite_synchronous,
|
||||||
'database')
|
'database')
|
||||||
|
|
||||||
# Suppress logging for migration
|
# Suppress logging for alembic
|
||||||
migrate_logger = logging.getLogger('migrate')
|
alembic_logger = logging.getLogger('alembic.runtime.migration')
|
||||||
migrate_logger.setLevel(logging.WARNING)
|
alembic_logger.setLevel(logging.WARNING)
|
||||||
|
|
||||||
self._clear_facade()
|
self._clear_facade()
|
||||||
self.db_instance = db_api.oslo_db_api.DBAPI.from_config(
|
self.db_instance = db_api.oslo_db_api.DBAPI.from_config(
|
||||||
|
@ -99,13 +100,15 @@ class DBPersistence(persistence_base.PersistenceDriverBase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
migration.db_sync()
|
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
|
# 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
|
# DB while we upgrade, so we must ignore the fact that the DB is
|
||||||
# now on a newer version.
|
# now on a newer version.
|
||||||
if not isinstance(getattr(exc, 'inner_exception', None),
|
if not isinstance(
|
||||||
migrate.exceptions.VersionNotFoundError):
|
exc.__cause__, alembic.script.revision.ResolutionError,
|
||||||
|
):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
self._create_key_value_table()
|
self._create_key_value_table()
|
||||||
|
|
||||||
# NOTE : At this point, the persistence isn't ready so we need to use
|
# NOTE : At this point, the persistence isn't ready so we need to use
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
import tempfile
|
import tempfile
|
||||||
from unittest import mock
|
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 api as sqla_api
|
||||||
from cinder.db.sqlalchemy import models as sqla_models
|
from cinder.db.sqlalchemy import models as sqla_models
|
||||||
from cinder import objects as cinder_ovos
|
from cinder import objects as cinder_ovos
|
||||||
|
@ -152,10 +154,10 @@ class TestDBPersistenceNewerSchema(base.helper.TestHelper):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _raise_exc(self):
|
def _raise_exc(self):
|
||||||
inner_exc = dbms.migrate.exceptions.VersionNotFoundError()
|
inner_exc = alembic.script.revision.ResolutionError('foo', 'rev')
|
||||||
exc = dbms.exception.DBMigrationError(inner_exc)
|
outer_exc = alembic.util.exc.CommandError('bar')
|
||||||
self.original_db_sync()
|
self.original_db_sync()
|
||||||
raise(exc)
|
raise outer_exc from inner_exc
|
||||||
|
|
||||||
def test_newer_db_schema(self):
|
def test_newer_db_schema(self):
|
||||||
self.original_db_sync = dbms.migration.db_sync
|
self.original_db_sync = dbms.migration.db_sync
|
||||||
|
|
|
@ -5,7 +5,3 @@ os-brick>=6.3.0 # Apache-2.0
|
||||||
|
|
||||||
importlib_metadata>=1.7.0 # Apache-2.0
|
importlib_metadata>=1.7.0 # Apache-2.0
|
||||||
importlib_resources>=3.2.1;python_version<'3.10' # 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
|
|
||||||
|
|
Loading…
Reference in New Issue