]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Upgrade failure for DB2 at ml2_binding_vif_details
authorXuhan Peng <xuhanp@cn.ibm.com>
Thu, 24 Apr 2014 02:58:32 +0000 (10:58 +0800)
committerXuhan Peng <xuhanp@cn.ibm.com>
Wed, 7 May 2014 02:38:14 +0000 (10:38 +0800)
50d5ba354c23_ml2_binding_vif_details fails during upgrade
when DB2 is used as the DB backend of neutron because
Boolean type is not supported by DB2.

This fix uses "1" instead of "true" in sql when db2 is engine.
This fix also changes context creation to op.execute.

Change-Id: I82d2141007894342c634f2c5e62344e20d876d8f
Closes-Bug: 1311589

neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py

index b7de5fc9f012ec0086bf3fcba11c5cfee320dc41..f89be7c11d05acf10a7e75071d152f4af1b6dcb8 100644 (file)
@@ -33,7 +33,6 @@ migration_for_plugins = [
     'neutron.plugins.ml2.plugin.Ml2Plugin'
 ]
 
-from alembic import context
 from alembic import op
 import sqlalchemy as sa
 
@@ -47,13 +46,24 @@ def upgrade(active_plugins=None, options=None):
     op.add_column('ml2_port_bindings',
                   sa.Column('vif_details', sa.String(length=4095),
                             nullable=False, server_default=''))
-    migr_context = context.get_context()
-    with context.begin_transaction():
-        for value in ('true', 'false'):
-            migr_context.execute(
-                "UPDATE ml2_port_bindings SET"
-                " vif_details = '{\"port_filter\": %(value)s}'"
-                " WHERE cap_port_filter = %(value)s" % {'value': value})
+    if op.get_bind().engine.name == 'ibm_db_sa':
+        op.execute(
+            "UPDATE ml2_port_bindings SET"
+            " vif_details = '{\"port_filter\": true}'"
+            " WHERE cap_port_filter = 1")
+        op.execute(
+            "UPDATE ml2_port_bindings SET"
+            " vif_details = '{\"port_filter\": false}'"
+            " WHERE cap_port_filter = 0")
+    else:
+        op.execute(
+            "UPDATE ml2_port_bindings SET"
+            " vif_details = '{\"port_filter\": true}'"
+            " WHERE cap_port_filter = true")
+        op.execute(
+            "UPDATE ml2_port_bindings SET"
+            " vif_details = '{\"port_filter\": false}'"
+            " WHERE cap_port_filter = false")
     op.drop_column('ml2_port_bindings', 'cap_port_filter')
 
 
@@ -61,12 +71,24 @@ def downgrade(active_plugins=None, options=None):
     if not migration.should_run(active_plugins, migration_for_plugins):
         return
 
-    op.add_column('ml2_port_bindings',
-                  sa.Column('cap_port_filter', sa.Boolean(),
-                            nullable=False, default=False))
-    migr_context = context.get_context()
-    with context.begin_transaction():
-        migr_context.execute(
+    if op.get_bind().engine.name == 'ibm_db_sa':
+        # Note(xuhanp): DB2 doesn't allow nullable=False Column with
+        # "DEFAULT" clause not specified. So server_default is used.
+        # Using sa.text will result "DEFAULT 0" for cap_port_filter.
+        op.add_column('ml2_port_bindings',
+                      sa.Column('cap_port_filter', sa.Boolean(),
+                                nullable=False,
+                                server_default=sa.text("0")))
+        op.execute(
+            "UPDATE ml2_port_bindings SET"
+            " cap_port_filter = 1"
+            " WHERE vif_details LIKE '%\"port_filter\": true%'")
+    else:
+        op.add_column('ml2_port_bindings',
+                      sa.Column('cap_port_filter', sa.Boolean(),
+                                nullable=False,
+                                server_default=sa.text("false")))
+        op.execute(
             "UPDATE ml2_port_bindings SET"
             " cap_port_filter = true"
             " WHERE vif_details LIKE '%\"port_filter\": true%'")