]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fixing neutron-db-manage with some options other than upgrade/downgrade
authorronak <ronak.malav.shah@gmail.com>
Wed, 6 Aug 2014 00:40:24 +0000 (17:40 -0700)
committerronak <ronak.malav.shah@gmail.com>
Mon, 11 Aug 2014 16:19:26 +0000 (09:19 -0700)
"mysql-engine" argument was added to upgrade and downgrade option of
neutron-db-manage.
Reference commit: http://tinyurl.com/mzepbmq

migration environment's run_migration_offline/online() gets called
even for other neutron-db-manage options as well such as current,
history, stamp, branches etc. For those options since the argument
can not be set, it throws oslo.config.cfg.NoSuchOptError.
This fix tries to catch it and set the value accordingly.

Closes-bug: #1353180

Change-Id: I044daf04216ec61245ddb51689f8e50be5666e34

neutron/db/migration/alembic_migrations/env.py

index 7f2373fc7b0ea45031d9684c44cbf035db29dcb5..0c659866e3f97d7701db122539480b7eee60d4f6 100644 (file)
@@ -17,6 +17,7 @@
 from logging import config as logging_config
 
 from alembic import context
+from oslo.config import cfg
 import sqlalchemy as sa
 from sqlalchemy import create_engine, event, pool
 
@@ -48,7 +49,12 @@ for class_path in active_plugins:
 target_metadata = model_base.BASEV2.metadata
 
 
-def set_mysql_engine(mysql_engine):
+def set_mysql_engine():
+    try:
+        mysql_engine = neutron_config.command.mysql_engine
+    except cfg.NoSuchOptError:
+        mysql_engine = None
+
     global MYSQL_ENGINE
     MYSQL_ENGINE = (mysql_engine or
                     model_base.BASEV2.__table_args__['mysql_engine'])
@@ -64,7 +70,7 @@ def run_migrations_offline():
     script output.
 
     """
-    set_mysql_engine(neutron_config.command.mysql_engine)
+    set_mysql_engine()
 
     kwargs = dict()
     if neutron_config.database.connection:
@@ -91,7 +97,7 @@ def run_migrations_online():
     and associate a connection with the context.
 
     """
-    set_mysql_engine(neutron_config.command.mysql_engine)
+    set_mysql_engine()
 
     engine = create_engine(
         neutron_config.database.connection,