From b4523032029604df34e045d6f6777a695328cff4 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Wed, 25 Jan 2012 15:20:38 -0800 Subject: Ignore connection_type when no instances exist In migration 74, we had required that the connection_type flag be set. That's annoying for new deployments, so bypass this check if there are no instances in the databse. Fixes bug 921294 Change-Id: I9b829e80ad7fa7ded3c7a471cb68c9b342d973bb --- .../migrate_repo/versions/074_change_flavor_local_gb.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/074_change_flavor_local_gb.py b/nova/db/sqlalchemy/migrate_repo/versions/074_change_flavor_local_gb.py index ef7e3293a..61fa86494 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/074_change_flavor_local_gb.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/074_change_flavor_local_gb.py @@ -70,13 +70,22 @@ def upgrade_other(instances, instance_types): ephemeral_gb=0).execute() -def upgrade(migrate_engine): - if not FLAGS.connection_type: - raise exception.Error("Need connection_type specified to run " - "migration") +def check_instance_presence(migrate_engine, instances_table): + result = migrate_engine.execute(instances_table.select().limit(1)) + return result.fetchone() is not None + +def upgrade(migrate_engine): meta.bind = migrate_engine instances = _get_table('instances') + + data_present = check_instance_presence(migrate_engine, instances) + + if data_present and not FLAGS.connection_type: + msg = ("Found instance records in database. You must specify " + "connection_type to run migration migration") + raise exception.Error(msg) + instance_types = _get_table('instance_types') for table in (instances, instance_types): -- cgit