]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Set BigSwitch plugin to use existing host database model
authorKevin Benton <kevin.benton@bigswitch.com>
Tue, 13 Aug 2013 01:11:09 +0000 (18:11 -0700)
committerKevin Benton <kevin.benton@bigswitch.com>
Sun, 18 Aug 2013 15:38:14 +0000 (08:38 -0700)
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

neutron/db/migration/alembic_migrations/versions/176a85fc7d79_add_portbindings_db.py
neutron/db/migration/alembic_migrations/versions/86cf4d88bd3_remove_bigswitch_por.py [new file with mode: 0644]
neutron/plugins/bigswitch/db/porttracker_db.py
neutron/plugins/bigswitch/plugin.py

index 46748526917095cb0cb4620f03384b3c62a61ce5..e7c48c81e734d797f520febfb525564783d852d1 100644 (file)
@@ -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 (file)
index 0000000..7d91893
--- /dev/null
@@ -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)
+                    )
index 845516b1c8bed4876445f79de65226d942934cec..36e8af72d56d70168ceb17d8144e08fe11a96404 100644 (file)
 #    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)
index feb78650f6fdc47a7ea597cd9d2ccc2879bbbcaa..641dfa91050a72b7dd1feb45bc8a677791fcbfeb 100644 (file)
@@ -560,11 +560,11 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2,
 
         # Update DB
         port["port"]["admin_state_up"] = False
+        new_port = super(NeutronRestProxyV2, self).create_port(context, 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])
-        new_port = super(NeutronRestProxyV2, self).create_port(context, port)
         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: