diff options
author | Marco Fargetta <marco.fargetta@ct.infn.it> | 2015-03-04 11:22:05 +0100 |
---|---|---|
committer | Roman Podoliaka <rpodolyaka@mirantis.com> | 2015-04-10 15:25:56 +0300 |
commit | 9e004bdbc96bfc54ba9350f07925354095d51465 (patch) | |
tree | db7b320fbfb5baa025ceda1fcfe901877a287a73 /oslo_db | |
parent | 9c852c63cd153aaa820d9bf5ebda7b5b7e1265c3 (diff) | |
download | oslo-db-9e004bdbc96bfc54ba9350f07925354095d51465.tar.gz |
Sanity check after migration
Added a sanity_check call after the migration, so if a table in the
migration scripts is created not correctly the exception arise
before to go in production.
Closes-Bug: #1428065
Change-Id: Ib91f2471fa389a6072e8c2aa302504a6c068aa0a
Diffstat (limited to 'oslo_db')
-rw-r--r-- | oslo_db/sqlalchemy/migration.py | 10 | ||||
-rw-r--r-- | oslo_db/tests/old_import_api/sqlalchemy/test_migration_common.py | 3 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_migration_common.py | 3 |
3 files changed, 11 insertions, 5 deletions
diff --git a/oslo_db/sqlalchemy/migration.py b/oslo_db/sqlalchemy/migration.py index 308ce60..d07ffc8 100644 --- a/oslo_db/sqlalchemy/migration.py +++ b/oslo_db/sqlalchemy/migration.py @@ -76,10 +76,14 @@ 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: - return versioning_api.upgrade(engine, repository, version) + migration = versioning_api.upgrade(engine, repository, version) else: - return versioning_api.downgrade(engine, repository, - version) + migration = versioning_api.downgrade(engine, repository, + version) + if sanity_check: + _db_schema_sanity_check(engine) + + return migration def _db_schema_sanity_check(engine): diff --git a/oslo_db/tests/old_import_api/sqlalchemy/test_migration_common.py b/oslo_db/tests/old_import_api/sqlalchemy/test_migration_common.py index 98ae46e..c81c93a 100644 --- a/oslo_db/tests/old_import_api/sqlalchemy/test_migration_common.py +++ b/oslo_db/tests/old_import_api/sqlalchemy/test_migration_common.py @@ -158,7 +158,8 @@ class TestMigrationCommon(test_base.DbTestCase): mock_find_repo.return_value = self.return_value migration.db_sync(self.engine, self.path, self.test_version) - mock_sanity.assert_called_once_with(self.engine) + self.assertEqual([mock.call(self.engine), mock.call(self.engine)], + mock_sanity.call_args_list) def test_db_sync_sanity_skipped(self): with test_utils.nested( diff --git a/oslo_db/tests/sqlalchemy/test_migration_common.py b/oslo_db/tests/sqlalchemy/test_migration_common.py index 95efab1..ebdaaa9 100644 --- a/oslo_db/tests/sqlalchemy/test_migration_common.py +++ b/oslo_db/tests/sqlalchemy/test_migration_common.py @@ -174,7 +174,8 @@ class TestMigrationCommon(test_base.DbTestCase): mock_find_repo.return_value = self.return_value migration.db_sync(self.engine, self.path, self.test_version) - mock_sanity.assert_called_once_with(self.engine) + self.assertEqual([mock.call(self.engine), mock.call(self.engine)], + mock_sanity.call_args_list) def test_db_sync_sanity_skipped(self): with test_utils.nested( |