From e93aaf456a97bab2a9207e3c97defec66a4688be Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Tue, 18 Feb 2014 09:22:11 +0000 Subject: [PATCH] BigSwitch: Add address pair support to plugin Adds support for the address pair extension to the BigSwitch/restproxy plugin. Implements: blueprint bsn-address-pairs Change-Id: If03e8752155bcb8b21f5a427c54640c5b63f77f3 --- .../versions/fcac4c42e2cc_bsn_addresspairs.py | 58 +++++++++++++++++++ neutron/plugins/bigswitch/plugin.py | 18 +++++- .../unit/bigswitch/test_restproxy_plugin.py | 6 ++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.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 index 000000000..9d80be9fb --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/fcac4c42e2cc_bsn_addresspairs.py @@ -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') diff --git a/neutron/plugins/bigswitch/plugin.py b/neutron/plugins/bigswitch/plugin.py index 267b896b2..32b273d79 100644 --- a/neutron/plugins/bigswitch/plugin.py +++ b/neutron/plugins/bigswitch/plugin.py @@ -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'] diff --git a/neutron/tests/unit/bigswitch/test_restproxy_plugin.py b/neutron/tests/unit/bigswitch/test_restproxy_plugin.py index 69fb5b7b0..72425f254 100644 --- a/neutron/tests/unit/bigswitch/test_restproxy_plugin.py +++ b/neutron/tests/unit/bigswitch/test_restproxy_plugin.py @@ -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 -- 2.45.2