Merge "Don't "lock" the DB on expand dry run"

This commit is contained in:
Jenkins 2015-09-16 08:20:11 +00:00 committed by Gerrit Code Review
commit b5a9b6d1b1
2 changed files with 17 additions and 5 deletions

View File

@ -1026,11 +1026,12 @@ def db_expand(dryrun=False, database='main'):
for op in expand:
op.execute(ddlop)
repository = _find_migrate_repo(database)
if not _set_db_sync_lock(repository, locked=True):
# No rows exist yet. Might be 'db sync' was never run
db_version_control(INIT_VERSION)
_set_db_sync_lock(repository, locked=True)
if not dryrun:
repository = _find_migrate_repo(database)
if not _set_db_sync_lock(repository, locked=True):
# No rows exist yet. Might be 'db sync' was never run
db_version_control(INIT_VERSION)
_set_db_sync_lock(repository, locked=True)
def db_migrate(dryrun=False, database='main'):

View File

@ -871,6 +871,17 @@ class ProjectTestCase(test.NoDBTestCase):
self.assertFalse(includes_downgrade, helpful_msg)
class ExpandTest(test.NoDBTestCase):
@mock.patch('nova.db.sqlalchemy.migration._schedule_schema_changes')
@mock.patch('nova.db.sqlalchemy.migration._find_migrate_repo')
def test_dryrun(self, find_repo, schedule):
# we shouldn't lock the sqlalchemy migrate table on a dry run
schedule.return_value = [], [], []
sa_migration.db_expand(dryrun=True)
self.assertEqual([], find_repo.mock_calls)
class SchemaChangeSchedulerTest(test.NoDBTestCase):
def test_add_fk_after_add_column(self):
exist_meta = sqlalchemy.MetaData()