Merge "Upgrade failure for DB2 at ml2_binding_vif_details"

This commit is contained in:
Jenkins 2014-05-14 16:07:02 +00:00 committed by Gerrit Code Review
commit c484d600f5

View File

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