diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index bb805da31..2325c5ede 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -19,6 +19,7 @@ from oslo.config import cfg from oslo.db import exception as db_exc import sqlalchemy as sa from sqlalchemy.orm import exc +from sqlalchemy import sql from neutron.common import rpc as n_rpc from neutron.db import model_base @@ -54,7 +55,7 @@ class Agent(model_base.BASEV2, models_v2.HasId): # TOPIC.host is a target topic host = sa.Column(sa.String(255), nullable=False) admin_state_up = sa.Column(sa.Boolean, default=True, - nullable=False) + server_default=sql.true(), nullable=False) # the time when first report came from agents created_at = sa.Column(sa.DateTime, nullable=False) # the time when first report came after agents start diff --git a/neutron/db/l3_gwmode_db.py b/neutron/db/l3_gwmode_db.py index 4c184019f..108ecc824 100644 --- a/neutron/db/l3_gwmode_db.py +++ b/neutron/db/l3_gwmode_db.py @@ -14,6 +14,7 @@ # import sqlalchemy as sa +from sqlalchemy import sql from neutron.db import db_base_plugin_v2 from neutron.db import l3_db @@ -26,7 +27,8 @@ EXTERNAL_GW_INFO = l3.EXTERNAL_GW_INFO # Modify the Router Data Model adding the enable_snat attribute setattr(l3_db.Router, 'enable_snat', - sa.Column(sa.Boolean, default=True, nullable=False)) + sa.Column(sa.Boolean, default=True, server_default=sql.true(), + nullable=False)) class L3_NAT_db_mixin(l3_db.L3_NAT_db_mixin): diff --git a/neutron/db/metering/metering_db.py b/neutron/db/metering/metering_db.py index 8de0cc427..aad24dc4d 100644 --- a/neutron/db/metering/metering_db.py +++ b/neutron/db/metering/metering_db.py @@ -17,6 +17,7 @@ import netaddr import sqlalchemy as sa from sqlalchemy import orm +from sqlalchemy import sql from neutron.api.rpc.agentnotifiers import metering_rpc_agent_api from neutron.common import constants @@ -41,7 +42,7 @@ class MeteringLabelRule(model_base.BASEV2, models_v2.HasId): sa.ForeignKey("meteringlabels.id", ondelete="CASCADE"), nullable=False) - excluded = sa.Column(sa.Boolean, default=False) + excluded = sa.Column(sa.Boolean, default=False, server_default=sql.false()) class MeteringLabel(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): diff --git a/neutron/db/migration/alembic_migrations/versions/5446f2a45467_set_server_default.py b/neutron/db/migration/alembic_migrations/versions/5446f2a45467_set_server_default.py new file mode 100644 index 000000000..1e9f5b5db --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/5446f2a45467_set_server_default.py @@ -0,0 +1,148 @@ +# Copyright 2014 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""set_server_default +Revision ID: 5446f2a45467 +Revises: 2db5203cb7a9 +Create Date: 2014-07-07 18:31:30.384522 + +""" + +# revision identifiers, used by Alembic. +revision = '5446f2a45467' +down_revision = '2db5203cb7a9' + + +from alembic import op +import sqlalchemy as sa +import sqlalchemy.sql + + +from neutron.plugins.cisco.common import cisco_constants + +PLUGINS = { + 'brocade': 'neutron.plugins.brocade.NeutronPlugin.BrocadePluginV2', + 'cisco': 'neutron.plugins.cisco.network_plugin.PluginV2', + 'ml2': 'neutron.plugins.ml2.plugin.Ml2Plugin', + 'mlnx': 'neutron.plugins.mlnx.mlnx_plugin.MellanoxEswitchPlugin', + 'vmware': [ + 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', + 'neutron.plugins.nicira.NeutronServicePlugin.NvpAdvancedPlugin', + 'neutron.plugins.vmware.plugin.NsxPlugin', + 'neutron.plugins.vmware.plugin.NsxServicePlugin', + ], + 'agents': [ + 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', + 'neutron.plugins.nec.nec_plugin.NECPluginV2', + 'neutron.plugins.oneconvergence.plugin.OneConvergencePluginV2', + 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', + 'neutron.plugins.ibm.sdnve_neutron_plugin.SdnvePluginV2', + 'neutron.services.loadbalancer.plugin.LoadBalancerPlugin', + ], +} + + +def upgrade(active_plugins=None, options=None): + run(active_plugins, True) + + +def downgrade(active_plugins=None, options=None): + run(active_plugins, None) + + +def run(active_plugins, default): + if PLUGINS['ml2'] in active_plugins: + set_default_ml2(default) + if PLUGINS['mlnx'] in active_plugins: + set_default_agents(default) + set_default_mlnx(default) + if PLUGINS['brocade'] in active_plugins: + set_default_agents(default) + set_default_brocade(default) + if PLUGINS['cisco'] in active_plugins: + set_default_cisco(default) + if set(PLUGINS['vmware']) & set(active_plugins): + set_default_vmware(default) + set_default_agents(default) + if set(PLUGINS['agents']) & set(active_plugins): + set_default_agents(default) + + +def set_default_brocade(default): + if default: + default = '' + op.alter_column('brocadeports', 'port_id', + server_default=default, existing_type=sa.String(36)) + + +def set_default_mlnx(default): + if default: + default = sqlalchemy.sql.false() + op.alter_column('segmentation_id_allocation', 'allocated', + server_default=default, existing_nullable=False, + existing_type=sa.Boolean) + + +def set_default_cisco(default): + if default: + default = sqlalchemy.sql.false() + op.alter_column('cisco_n1kv_profile_bindings', 'tenant_id', + existing_type=sa.String(length=36), + server_default=cisco_constants.TENANT_ID_NOT_SET, + existing_nullable=False) + else: + op.alter_column('cisco_n1kv_profile_bindings', 'tenant_id', + existing_type=sa.String(length=36), + server_default=None, existing_nullable=False) + op.alter_column('cisco_network_profiles', 'multicast_ip_index', + server_default=default, existing_type=sa.Integer) + op.alter_column('cisco_n1kv_vlan_allocations', 'allocated', + existing_type=sa.Boolean, + server_default=default, existing_nullable=False) + op.alter_column('cisco_n1kv_vxlan_allocations', 'allocated', + existing_type=sa.Boolean, + server_default=default, existing_nullable=False) + + +def set_default_vmware(default=None): + if default: + default = sqlalchemy.sql.false() + op.alter_column('nsxrouterextattributess', 'service_router', + server_default=default, existing_nullable=False, + existing_type=sa.Boolean) + op.alter_column('nsxrouterextattributess', 'distributed', + server_default=default, existing_nullable=False, + existing_type=sa.Boolean) + op.alter_column('qosqueues', 'default', + server_default=default, existing_type=sa.Boolean) + + +def set_default_agents(default=None): + if default: + default = sqlalchemy.sql.true() + op.alter_column('agents', 'admin_state_up', + server_default=default, existing_nullable=False, + existing_type=sa.Boolean) + + +def set_default_ml2(default=None): + if default: + default = sqlalchemy.sql.false() + op.alter_column('ml2_gre_allocations', 'allocated', + server_default=default, existing_nullable=False, + existing_type=sa.Boolean) + op.alter_column('ml2_vxlan_allocations', 'allocated', + server_default=default, existing_nullable=False, + existing_type=sa.Boolean) diff --git a/neutron/db/migration/alembic_migrations/versions/HEAD b/neutron/db/migration/alembic_migrations/versions/HEAD index 2431c7d6b..858184884 100644 --- a/neutron/db/migration/alembic_migrations/versions/HEAD +++ b/neutron/db/migration/alembic_migrations/versions/HEAD @@ -1 +1 @@ -2db5203cb7a9 \ No newline at end of file +5446f2a45467 \ No newline at end of file diff --git a/neutron/plugins/brocade/db/models.py b/neutron/plugins/brocade/db/models.py index 313427c5b..4a0df671b 100644 --- a/neutron/plugins/brocade/db/models.py +++ b/neutron/plugins/brocade/db/models.py @@ -35,7 +35,8 @@ class BrocadeNetwork(model_base.BASEV2, models_v2.HasId): class BrocadePort(model_base.BASEV2): """Schema for brocade port.""" - port_id = sa.Column(sa.String(36), primary_key=True, default="") + port_id = sa.Column(sa.String(36), primary_key=True, default="", + server_default='') network_id = sa.Column(sa.String(36), sa.ForeignKey("brocadenetworks.id"), nullable=False) diff --git a/neutron/plugins/cisco/db/n1kv_models_v2.py b/neutron/plugins/cisco/db/n1kv_models_v2.py index b104666a9..63573d674 100644 --- a/neutron/plugins/cisco/db/n1kv_models_v2.py +++ b/neutron/plugins/cisco/db/n1kv_models_v2.py @@ -16,6 +16,7 @@ # @author: Rudrajit Tapadar, Cisco Systems Inc. import sqlalchemy as sa +from sqlalchemy import sql from neutron.db import model_base from neutron.db import models_v2 @@ -36,7 +37,8 @@ class N1kvVlanAllocation(model_base.BASEV2): primary_key=True) vlan_id = sa.Column(sa.Integer, nullable=False, primary_key=True, autoincrement=False) - allocated = sa.Column(sa.Boolean, nullable=False, default=False) + allocated = sa.Column(sa.Boolean, nullable=False, default=False, + server_default=sql.false()) network_profile_id = sa.Column(sa.String(36), sa.ForeignKey('cisco_network_profiles.id', ondelete="CASCADE"), @@ -50,7 +52,8 @@ class N1kvVxlanAllocation(model_base.BASEV2): vxlan_id = sa.Column(sa.Integer, nullable=False, primary_key=True, autoincrement=False) - allocated = sa.Column(sa.Boolean, nullable=False, default=False) + allocated = sa.Column(sa.Boolean, nullable=False, default=False, + server_default=sql.false()) network_profile_id = sa.Column(sa.String(36), sa.ForeignKey('cisco_network_profiles.id', ondelete="CASCADE"), @@ -121,7 +124,8 @@ class NetworkProfile(model_base.BASEV2, models_v2.HasId): nullable=False) sub_type = sa.Column(sa.String(255)) segment_range = sa.Column(sa.String(255)) - multicast_ip_index = sa.Column(sa.Integer, default=0) + multicast_ip_index = sa.Column(sa.Integer, default=0, + server_default=sql.false()) multicast_ip_range = sa.Column(sa.String(255)) physical_network = sa.Column(sa.String(255)) @@ -152,7 +156,8 @@ class ProfileBinding(model_base.BASEV2): name='profile_type')) tenant_id = sa.Column(sa.String(36), primary_key=True, - default=cisco_constants.TENANT_ID_NOT_SET) + default=cisco_constants.TENANT_ID_NOT_SET, + server_default=cisco_constants.TENANT_ID_NOT_SET) profile_id = sa.Column(sa.String(36), primary_key=True) diff --git a/neutron/plugins/ml2/drivers/cisco/apic/apic_model.py b/neutron/plugins/ml2/drivers/cisco/apic/apic_model.py index a3c05d630..54d36f94c 100644 --- a/neutron/plugins/ml2/drivers/cisco/apic/apic_model.py +++ b/neutron/plugins/ml2/drivers/cisco/apic/apic_model.py @@ -16,6 +16,7 @@ # @author: Arvind Somya (asomya@cisco.com), Cisco Systems Inc. import sqlalchemy as sa +from sqlalchemy import sql from neutron.db import api as db_api from neutron.db import model_base @@ -31,7 +32,8 @@ class NetworkEPG(model_base.BASEV2): network_id = sa.Column(sa.String(255), nullable=False, primary_key=True) epg_id = sa.Column(sa.String(64), nullable=False) segmentation_id = sa.Column(sa.String(64), nullable=False) - provider = sa.Column(sa.Boolean, default=False, nullable=False) + provider = sa.Column(sa.Boolean, default=False, server_default=sql.false(), + nullable=False) class PortProfile(model_base.BASEV2): diff --git a/neutron/plugins/ml2/drivers/type_gre.py b/neutron/plugins/ml2/drivers/type_gre.py index b9a00c0cb..69fb2ab6c 100644 --- a/neutron/plugins/ml2/drivers/type_gre.py +++ b/neutron/plugins/ml2/drivers/type_gre.py @@ -17,6 +17,7 @@ from oslo.config import cfg from six import moves import sqlalchemy as sa from sqlalchemy.orm import exc as sa_exc +from sqlalchemy import sql from neutron.common import exceptions as exc from neutron.db import api as db_api @@ -45,7 +46,8 @@ class GreAllocation(model_base.BASEV2): gre_id = sa.Column(sa.Integer, nullable=False, primary_key=True, autoincrement=False) - allocated = sa.Column(sa.Boolean, nullable=False, default=False) + allocated = sa.Column(sa.Boolean, nullable=False, default=False, + server_default=sql.false()) class GreEndpoints(model_base.BASEV2): diff --git a/neutron/plugins/ml2/drivers/type_vxlan.py b/neutron/plugins/ml2/drivers/type_vxlan.py index b5aeadbb6..7c24782b9 100644 --- a/neutron/plugins/ml2/drivers/type_vxlan.py +++ b/neutron/plugins/ml2/drivers/type_vxlan.py @@ -17,6 +17,7 @@ from oslo.config import cfg import sqlalchemy as sa from sqlalchemy.orm import exc as sa_exc +from sqlalchemy import sql from neutron.common import exceptions as exc from neutron.db import api as db_api @@ -51,7 +52,8 @@ class VxlanAllocation(model_base.BASEV2): vxlan_vni = sa.Column(sa.Integer, nullable=False, primary_key=True, autoincrement=False) - allocated = sa.Column(sa.Boolean, nullable=False, default=False) + allocated = sa.Column(sa.Boolean, nullable=False, default=False, + server_default=sql.false()) class VxlanEndpoints(model_base.BASEV2): diff --git a/neutron/plugins/mlnx/db/mlnx_models_v2.py b/neutron/plugins/mlnx/db/mlnx_models_v2.py index 8e55acea5..4b1bc94dc 100644 --- a/neutron/plugins/mlnx/db/mlnx_models_v2.py +++ b/neutron/plugins/mlnx/db/mlnx_models_v2.py @@ -14,6 +14,7 @@ # limitations under the License. import sqlalchemy as sa +from sqlalchemy import sql from neutron.db import model_base @@ -26,7 +27,8 @@ class SegmentationIdAllocation(model_base.BASEV2): primary_key=True) segmentation_id = sa.Column(sa.Integer, nullable=False, primary_key=True, autoincrement=False) - allocated = sa.Column(sa.Boolean, nullable=False, default=False) + allocated = sa.Column(sa.Boolean, nullable=False, default=False, + server_default=sql.false()) def __init__(self, physical_network, segmentation_id): self.physical_network = physical_network diff --git a/neutron/plugins/vmware/dbexts/models.py b/neutron/plugins/vmware/dbexts/models.py index 356332811..53bf24f20 100644 --- a/neutron/plugins/vmware/dbexts/models.py +++ b/neutron/plugins/vmware/dbexts/models.py @@ -17,6 +17,7 @@ from sqlalchemy import Boolean, Column, Enum, ForeignKey, Integer, String from sqlalchemy import orm +from sqlalchemy import sql from neutron.db import l3_db from neutron.db import model_base @@ -125,8 +126,10 @@ class NSXRouterExtAttributes(model_base.BASEV2): router_id = Column(String(36), ForeignKey('routers.id', ondelete="CASCADE"), primary_key=True) - distributed = Column(Boolean, default=False, nullable=False) - service_router = Column(Boolean, default=False, nullable=False) + distributed = Column(Boolean, default=False, server_default=sql.false(), + nullable=False) + service_router = Column(Boolean, default=False, server_default=sql.false(), + nullable=False) # Add a relationship to the Router model in order to instruct # SQLAlchemy to eagerly load this association router = orm.relationship( diff --git a/neutron/plugins/vmware/dbexts/qos_db.py b/neutron/plugins/vmware/dbexts/qos_db.py index b01050201..13d0ddb9d 100644 --- a/neutron/plugins/vmware/dbexts/qos_db.py +++ b/neutron/plugins/vmware/dbexts/qos_db.py @@ -16,6 +16,7 @@ import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.orm import exc +from sqlalchemy import sql from neutron.api.v2 import attributes as attr from neutron.db import db_base_plugin_v2 @@ -31,7 +32,7 @@ LOG = log.getLogger(__name__) class QoSQueue(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): name = sa.Column(sa.String(255)) - default = sa.Column(sa.Boolean, default=False) + default = sa.Column(sa.Boolean, default=False, server_default=sql.false()) min = sa.Column(sa.Integer, nullable=False) max = sa.Column(sa.Integer, nullable=True) qos_marking = sa.Column(sa.Enum('untrusted', 'trusted',