Skip to content

Commit 166b173

Browse files
author
Balazs Gibizer
committed
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
1 parent a027b45 commit 166b173

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

nova/tests/unit/db/api/test_migrations.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ def test_walk_versions(self):
241241
LOG.info('Testing revision %s', revision)
242242
self._migrate_up(revision)
243243

244+
def test_db_version_alembic(self):
245+
migration.db_sync(database='api')
246+
247+
# FIXME(gibi): this is bug/1943436
248+
ex = self.assertRaises(
249+
AttributeError, migration.db_version, database='api')
250+
self.assertIn(
251+
"'Engine' object has no attribute 'get_main_option'",
252+
str(ex)
253+
)
254+
255+
# It should return the head of the migrations instead
256+
# head = alembic_script.ScriptDirectory.from_config(
257+
# self.config).get_current_head()
258+
# self.assertEqual(head, migration.db_version(database='api'))
259+
244260

245261
class TestMigrationsWalkSQLite(
246262
NovaMigrationsWalk,

nova/tests/unit/db/main/test_migrations.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ class NovaMigrationsWalk(
238238
def setUp(self):
239239
super().setUp()
240240
self.engine = enginefacade.writer.get_engine()
241-
self.config = migration._find_alembic_conf('api')
242-
self.init_version = migration.ALEMBIC_INIT_VERSION['api']
241+
self.config = migration._find_alembic_conf('main')
242+
self.init_version = migration.ALEMBIC_INIT_VERSION['main']
243243

244244
def _migrate_up(self, revision):
245245
if revision == self.init_version: # no tests for the initial revision
@@ -284,6 +284,22 @@ def test_walk_versions(self):
284284
LOG.info('Testing revision %s', revision)
285285
self._migrate_up(revision)
286286

287+
def test_db_version_alembic(self):
288+
migration.db_sync(database='main')
289+
290+
# FIXME(gibi): this is bug/1943436
291+
ex = self.assertRaises(
292+
AttributeError, migration.db_version, database='main')
293+
self.assertIn(
294+
"'Engine' object has no attribute 'get_main_option'",
295+
str(ex)
296+
)
297+
298+
# It should return the head of the migrations instead
299+
# head = alembic_script.ScriptDirectory.from_config(
300+
# self.config).get_current_head()
301+
# self.assertEqual(head, migration.db_version(database='main'))
302+
287303

288304
class TestMigrationsWalkSQLite(
289305
NovaMigrationsWalk,

0 commit comments

Comments
 (0)