Reproduce bug/1943436

The added db tests reproduces the bug that
$ nova-manage db version fails with
AttributeError: 'Engine' object has no attribute 'get_main_option'
If the db is managed by alembic.

Change-Id: I0647bb8545c1464b521a1d866cf5ee674aea2eae
Related-Bug: #1943436
This commit is contained in:
Balazs Gibizer 2021-09-13 12:40:14 +02:00
parent a027b45e46
commit 166b1730b8
2 changed files with 34 additions and 2 deletions

View File

@ -241,6 +241,22 @@ class NovaMigrationsWalk(
LOG.info('Testing revision %s', revision)
self._migrate_up(revision)
def test_db_version_alembic(self):
migration.db_sync(database='api')
# FIXME(gibi): this is bug/1943436
ex = self.assertRaises(
AttributeError, migration.db_version, database='api')
self.assertIn(
"'Engine' object has no attribute 'get_main_option'",
str(ex)
)
# It should return the head of the migrations instead
# head = alembic_script.ScriptDirectory.from_config(
# self.config).get_current_head()
# self.assertEqual(head, migration.db_version(database='api'))
class TestMigrationsWalkSQLite(
NovaMigrationsWalk,

View File

@ -238,8 +238,8 @@ class NovaMigrationsWalk(
def setUp(self):
super().setUp()
self.engine = enginefacade.writer.get_engine()
self.config = migration._find_alembic_conf('api')
self.init_version = migration.ALEMBIC_INIT_VERSION['api']
self.config = migration._find_alembic_conf('main')
self.init_version = migration.ALEMBIC_INIT_VERSION['main']
def _migrate_up(self, revision):
if revision == self.init_version: # no tests for the initial revision
@ -284,6 +284,22 @@ class NovaMigrationsWalk(
LOG.info('Testing revision %s', revision)
self._migrate_up(revision)
def test_db_version_alembic(self):
migration.db_sync(database='main')
# FIXME(gibi): this is bug/1943436
ex = self.assertRaises(
AttributeError, migration.db_version, database='main')
self.assertIn(
"'Engine' object has no attribute 'get_main_option'",
str(ex)
)
# It should return the head of the migrations instead
# head = alembic_script.ScriptDirectory.from_config(
# self.config).get_current_head()
# self.assertEqual(head, migration.db_version(database='main'))
class TestMigrationsWalkSQLite(
NovaMigrationsWalk,