Raise only DbMigrationError from migrate 'upgrade' method
All the exceptions which are raised from sqlalchemy-migrate upgrade method are not more user friendly to the operator. This patch proposes to convert all the exceptions which will be raised by 'upgrade' method to an oslo_db specific 'DbMigrationError' exception. Related-Bug: #1546441 Change-Id: I28533bedba358281ce302b9b021744387a76c04a
This commit is contained in:
parent
c23e571ff5
commit
a6172924d5
@ -75,7 +75,10 @@ def db_sync(engine, abs_path, version=None, init_version=0, sanity_check=True):
|
||||
if sanity_check:
|
||||
_db_schema_sanity_check(engine)
|
||||
if version is None or version > current_version:
|
||||
migration = versioning_api.upgrade(engine, repository, version)
|
||||
try:
|
||||
migration = versioning_api.upgrade(engine, repository, version)
|
||||
except Exception as ex:
|
||||
raise exception.DbMigrationError(ex)
|
||||
else:
|
||||
migration = versioning_api.downgrade(engine, repository,
|
||||
version)
|
||||
|
@ -192,6 +192,22 @@ class TestMigrationCommon(test_base.DbTestCase):
|
||||
self.assertRaises(db_exception.DBMigrationError,
|
||||
migration.db_sync, self.engine, self.path, 'foo')
|
||||
|
||||
@mock.patch.object(versioning_api, 'upgrade')
|
||||
def test_db_sync_script_not_present(self, upgrade):
|
||||
# For non existent migration script file sqlalchemy-migrate will raise
|
||||
# VersionNotFoundError which will be wrapped in DbMigrationError.
|
||||
upgrade.side_effect = migrate_exception.VersionNotFoundError
|
||||
self.assertRaises(db_exception.DbMigrationError,
|
||||
migration.db_sync, self.engine, self.path,
|
||||
self.test_version + 1)
|
||||
|
||||
@mock.patch.object(versioning_api, 'upgrade')
|
||||
def test_db_sync_known_error_raised(self, upgrade):
|
||||
upgrade.side_effect = migrate_exception.KnownError
|
||||
self.assertRaises(db_exception.DbMigrationError,
|
||||
migration.db_sync, self.engine, self.path,
|
||||
self.test_version + 1)
|
||||
|
||||
def test_db_sync_upgrade(self):
|
||||
init_ver = 55
|
||||
with test_utils.nested(
|
||||
|
Loading…
Reference in New Issue
Block a user