]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
BigSwitch: Add address pair support to plugin
authorKevin Benton <blak111@gmail.com>
Tue, 18 Feb 2014 09:22:11 +0000 (09:22 +0000)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:42 +0000 (15:20 +0800)
Adds support for the address pair extension to
the BigSwitch/restproxy plugin.

Implements: blueprint bsn-address-pairs
Change-Id: If03e8752155bcb8b21f5a427c54640c5b63f77f3

neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py [new file with mode: 0644]
neutron/plugins/bigswitch/plugin.py
neutron/tests/unit/bigswitch/test_restproxy_plugin.py

diff --git a/neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py b/neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py
new file mode 100644 (file)
index 0000000..9d80be9
--- /dev/null
@@ -0,0 +1,58 @@
+# 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.
+#
+
+"""bsn_addresspairs
+
+Revision ID: fcac4c42e2cc
+Revises: 2eeaf963a447
+Create Date: 2014-02-23 12:56:00.402855
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'fcac4c42e2cc'
+down_revision = '2eeaf963a447'
+
+# 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.create_table(
+        'allowedaddresspairs',
+        sa.Column('port_id', sa.String(length=36), nullable=False),
+        sa.Column('mac_address', sa.String(length=32), nullable=False),
+        sa.Column('ip_address', sa.String(length=64), nullable=False),
+        sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'),
+        sa.PrimaryKeyConstraint('port_id', 'mac_address', 'ip_address'),
+    )
+
+
+def downgrade(active_plugins=None, options=None):
+    if not migration.should_run(active_plugins, migration_for_plugins):
+        return
+
+    op.drop_table('allowedaddresspairs')
index 267b896b2a3c9b068e16603509d0be11fd555633..32b273d7989f60fe84939d9ce46e8ce6f7340aff 100644 (file)
@@ -61,6 +61,7 @@ from neutron.common import topics
 from neutron import context as qcontext
 from neutron.db import agents_db
 from neutron.db import agentschedulers_db
+from neutron.db import allowedaddresspairs_db as addr_pair_db
 from neutron.db import api as db
 from neutron.db import db_base_plugin_v2
 from neutron.db import dhcp_rpc_base
@@ -70,6 +71,7 @@ from neutron.db import l3_db
 from neutron.db import models_v2
 from neutron.db import securitygroups_db as sg_db
 from neutron.db import securitygroups_rpc_base as sg_rpc_base
+from neutron.extensions import allowedaddresspairs as addr_pair
 from neutron.extensions import external_net
 from neutron.extensions import extra_dhcp_opt as edo_ext
 from neutron.extensions import l3
@@ -414,6 +416,7 @@ class NeutronRestProxyV2Base(db_base_plugin_v2.NeutronDbPluginV2,
 
 
 class NeutronRestProxyV2(NeutronRestProxyV2Base,
+                         addr_pair_db.AllowedAddressPairsMixin,
                          extradhcpopt_db.ExtraDhcpOptMixin,
                          agentschedulers_db.DhcpAgentSchedulerDbMixin,
                          sg_rpc_base.SecurityGroupServerRpcMixin):
@@ -421,7 +424,7 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
     _supported_extension_aliases = ["external-net", "router", "binding",
                                     "router_rules", "extra_dhcp_opt", "quotas",
                                     "dhcp_agent_scheduler", "agent",
-                                    "security-group"]
+                                    "security-group", "allowed-address-pairs"]
 
     @property
     def supported_extension_aliases(self):
@@ -629,6 +632,10 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
             host_id = port['port'][portbindings.HOST_ID]
             porttracker_db.put_port_hostid(context, new_port['id'],
                                            host_id)
+        new_port[addr_pair.ADDRESS_PAIRS] = (
+            self._process_create_allowed_address_pairs(
+                context, new_port,
+                port['port'].get(addr_pair.ADDRESS_PAIRS)))
         self._process_port_create_extra_dhcp_opts(context, new_port,
                                                   dhcp_opts)
         new_port = self._extend_port_dict_binding(context, new_port)
@@ -698,9 +705,16 @@ class NeutronRestProxyV2(NeutronRestProxyV2Base,
             # Update DB
             new_port = super(NeutronRestProxyV2,
                              self).update_port(context, port_id, port)
+            ctrl_update_required = False
+            if addr_pair.ADDRESS_PAIRS in port['port']:
+                ctrl_update_required |= (
+                    self.update_address_pairs_on_port(context, port_id, port,
+                                                      orig_port, new_port))
+            if 'fixed_ips' in port['port']:
+                self._check_fixed_ips_and_address_pairs_no_overlap(
+                    context, new_port)
             self._update_extra_dhcp_opts_on_port(context, port_id, port,
                                                  new_port)
-            ctrl_update_required = False
             old_host_id = porttracker_db.get_port_hostid(context,
                                                          orig_port['id'])
             if (portbindings.HOST_ID in port['port']
index 69fb5b7b01f95b999f8dacdaa4b46a467b96b410..72425f254605639db963948292325b3e66d22404 100644 (file)
@@ -27,6 +27,7 @@ from neutron.tests.unit.bigswitch import fake_server
 from neutron.tests.unit.bigswitch import test_base
 from neutron.tests.unit import test_api_v2
 import neutron.tests.unit.test_db_plugin as test_plugin
+import neutron.tests.unit.test_extension_allowedaddresspairs as test_addr_pair
 
 
 class BigSwitchProxyPluginV2TestCase(test_base.BigSwitchTestBase,
@@ -280,3 +281,8 @@ class TestBigSwitchProxySync(BigSwitchProxyPluginV2TestCase):
         plugin_obj = NeutronManager.get_plugin()
         result = plugin_obj._send_all_data()
         self.assertEqual(result[0], 200)
+
+
+class TestBigSwitchAddressPairs(BigSwitchProxyPluginV2TestCase,
+                                test_addr_pair.TestAllowedAddressPairs):
+    pass