From 32046e6e2d3200b60d23604a795b2e36267b0481 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Mon, 12 Aug 2013 18:11:09 -0700 Subject: [PATCH] Set BigSwitch plugin to use existing host database model The BigSwitch plugin had a data model duplicating one that was recently added into the base portbindings db file. This patch removes the BigSwitch model and updates the BigSwitch plugin to reference the plugin- agnostic model. Fixes: bug #1211641 Change-Id: I1fdbf8690e71fb2d6e9d6a6dbd0571fa2c32a7e0 --- .../176a85fc7d79_add_portbindings_db.py | 1 + .../86cf4d88bd3_remove_bigswitch_por.py | 59 +++++++++++++++++++ .../plugins/bigswitch/db/porttracker_db.py | 21 +++---- neutron/plugins/bigswitch/plugin.py | 14 ++--- 4 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py diff --git a/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py b/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py index 4674852691..e7c48c81e7 100644 --- a/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py +++ b/neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py @@ -32,6 +32,7 @@ down_revision = 'f489cf14a79c' migration_for_plugins = [ 'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2', 'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2', + 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2', 'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2', ] diff --git a/neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py b/neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py new file mode 100644 index 0000000000..7d91893e2e --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py @@ -0,0 +1,59 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2013 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. +# + +"""remove bigswitch port tracking table + +Revision ID: 86cf4d88bd3 +Revises: 569e98a8132b +Create Date: 2013-08-13 21:59:04.373496 + +""" + +# revision identifiers, used by Alembic. +revision = '86cf4d88bd3' +down_revision = '569e98a8132b' + +# Change to ['*'] if this migration applies to all plugins + +migration_for_plugins = [ + 'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2' +] + +from alembic import op +import sqlalchemy as sa + + +from neutron.db import migration + + +def upgrade(active_plugins=None, options=None): + if not migration.should_run(active_plugins, migration_for_plugins): + return + + op.drop_table('portlocations') + + +def downgrade(active_plugins=None, options=None): + if not migration.should_run(active_plugins, migration_for_plugins): + return + + op.create_table('portlocations', + sa.Column('port_id', sa.String(length=255), + primary_key=True, nullable=False), + sa.Column('host_id', + sa.String(length=255), nullable=False) + ) diff --git a/neutron/plugins/bigswitch/db/porttracker_db.py b/neutron/plugins/bigswitch/db/porttracker_db.py index 845516b1c8..36e8af72d5 100644 --- a/neutron/plugins/bigswitch/db/porttracker_db.py +++ b/neutron/plugins/bigswitch/db/porttracker_db.py @@ -15,36 +15,29 @@ # License for the specific language governing permissions and limitations # under the License. -import sqlalchemy as sa - from neutron.api.v2 import attributes -from neutron.db import model_base +from neutron.db import portbindings_db from neutron.openstack.common import log as logging LOG = logging.getLogger(__name__) -class PortLocation(model_base.BASEV2): - port_id = sa.Column(sa.String(255), primary_key=True) - host_id = sa.Column(sa.String(255), nullable=False) - - def get_port_hostid(context, port_id): with context.session.begin(subtransactions=True): - query = context.session.query(PortLocation) + query = context.session.query(portbindings_db.PortBindingPort) res = query.filter_by(port_id=port_id).first() if not res: return False - return res.host_id + return res.host -def put_port_hostid(context, port_id, host_id): - if not attributes.is_attr_set(host_id): +def put_port_hostid(context, port_id, host): + if not attributes.is_attr_set(host): LOG.warning(_("No host_id in port request to track port location.")) return if port_id == '': - LOG.warning(_("Received an empty port ID for host '%s'"), host_id) + LOG.warning(_("Received an empty port ID for host '%s'"), host) return with context.session.begin(subtransactions=True): - location = PortLocation(port_id=port_id, host_id=host_id) + location = portbindings_db.PortBindingPort(port_id=port_id, host=host) context.session.merge(location) diff --git a/neutron/plugins/bigswitch/plugin.py b/neutron/plugins/bigswitch/plugin.py index feb78650f6..641dfa9105 100644 --- a/neutron/plugins/bigswitch/plugin.py +++ b/neutron/plugins/bigswitch/plugin.py @@ -560,11 +560,11 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2, # Update DB port["port"]["admin_state_up"] = False - if (portbindings.HOST_ID in port['port'] - and 'device_id' in port['port']): - porttracker_db.put_port_hostid(context, port['port']['device_id'], - port['port'][portbindings.HOST_ID]) new_port = super(NeutronRestProxyV2, self).create_port(context, port) + if (portbindings.HOST_ID in port['port'] + and 'id' in new_port): + porttracker_db.put_port_hostid(context, new_port['id'], + port['port'][portbindings.HOST_ID]) net = super(NeutronRestProxyV2, self).get_network(context, new_port["network_id"]) @@ -657,8 +657,8 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2, new_port = super(NeutronRestProxyV2, self).update_port(context, port_id, port) if (portbindings.HOST_ID in port['port'] - and 'device_id' in port['port']): - porttracker_db.put_port_hostid(context, port['port']['device_id'], + and 'id' in new_port): + porttracker_db.put_port_hostid(context, new_port['id'], port['port'][portbindings.HOST_ID]) # update on networl ctrl try: @@ -1335,7 +1335,7 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2, cfg_vif_type) cfg_vif_type = portbindings.VIF_TYPE_OVS hostid = porttracker_db.get_port_hostid(context, - port.get("device_id")) + port['id']) if hostid: override = self._check_hostvif_override(hostid) if override: