From c1b1af72e93da37383d6111195bfc8c63cc49fae Mon Sep 17 00:00:00 2001 From: mathieu-rohon Date: Thu, 25 Jul 2013 10:38:16 +0200 Subject: [PATCH] ML2 tunnel drivers validate provider networks correctly there was a copy/paste error in GRE/VXlan type drivers implementation. the segment wasn't returned while validating the provider network. Change-Id: I7df6d2e714d09618644f935a9ed41354b62de9d0 Fixes: bug #1202244 --- neutron/plugins/ml2/driver_api.py | 1 - neutron/plugins/ml2/drivers/type_flat.py | 2 -- neutron/plugins/ml2/drivers/type_gre.py | 15 +------------- neutron/plugins/ml2/drivers/type_local.py | 2 -- neutron/plugins/ml2/drivers/type_tunnel.py | 23 +++++++++++++++++++++- neutron/plugins/ml2/drivers/type_vlan.py | 6 ++---- neutron/plugins/ml2/drivers/type_vxlan.py | 15 +------------- neutron/plugins/ml2/managers.py | 2 +- neutron/plugins/ml2/plugin.py | 4 +++- 9 files changed, 30 insertions(+), 40 deletions(-) diff --git a/neutron/plugins/ml2/driver_api.py b/neutron/plugins/ml2/driver_api.py index 23e7e5d3efb..5bc7ca8393f 100644 --- a/neutron/plugins/ml2/driver_api.py +++ b/neutron/plugins/ml2/driver_api.py @@ -67,7 +67,6 @@ class TypeDriver(object): """Validate attributes of a provider network segment. :param segment: segment dictionary using keys defined above - :returns: segment dictionary with any defaulted attributes added :raises: neutron.common.exceptions.InvalidInput if invalid Called outside transaction context to validate the provider diff --git a/neutron/plugins/ml2/drivers/type_flat.py b/neutron/plugins/ml2/drivers/type_flat.py index af67366e509..72904508b69 100644 --- a/neutron/plugins/ml2/drivers/type_flat.py +++ b/neutron/plugins/ml2/drivers/type_flat.py @@ -96,8 +96,6 @@ class FlatTypeDriver(api.TypeDriver): msg = _("%s prohibited for flat provider network") % key raise exc.InvalidInput(error_message=msg) - return segment - def reserve_provider_segment(self, session, segment): physical_network = segment[api.PHYSICAL_NETWORK] with session.begin(subtransactions=True): diff --git a/neutron/plugins/ml2/drivers/type_gre.py b/neutron/plugins/ml2/drivers/type_gre.py index 906d61f867d..d0a9e53073b 100644 --- a/neutron/plugins/ml2/drivers/type_gre.py +++ b/neutron/plugins/ml2/drivers/type_gre.py @@ -58,8 +58,7 @@ class GreEndpoints(model_base.BASEV2): return "" % self.ip_address -class GreTypeDriver(api.TypeDriver, - type_tunnel.TunnelTypeDriver): +class GreTypeDriver(type_tunnel.TunnelTypeDriver): def get_type(self): return TYPE_GRE @@ -73,18 +72,6 @@ class GreTypeDriver(api.TypeDriver, ) self._sync_gre_allocations() - def validate_provider_segment(self, segment): - physical_network = segment.get(api.PHYSICAL_NETWORK) - if physical_network: - msg = _("provider:physical_network specified for GRE " - "network") - raise exc.InvalidInput(error_message=msg) - - segmentation_id = segment.get(api.SEGMENTATION_ID) - if not segmentation_id: - msg = _("segmentation_id required for GRE provider network") - raise exc.InvalidInput(error_message=msg) - def reserve_provider_segment(self, session, segment): segmentation_id = segment.get(api.SEGMENTATION_ID) with session.begin(subtransactions=True): diff --git a/neutron/plugins/ml2/drivers/type_local.py b/neutron/plugins/ml2/drivers/type_local.py index 1fb0f2e9613..712d4f37440 100644 --- a/neutron/plugins/ml2/drivers/type_local.py +++ b/neutron/plugins/ml2/drivers/type_local.py @@ -47,8 +47,6 @@ class LocalTypeDriver(api.TypeDriver): msg = _("%s prohibited for local provider network") % key raise exc.InvalidInput(error_message=msg) - return segment - def reserve_provider_segment(self, session, segment): # No resources to reserve pass diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py index b447f5582bc..341a023f227 100644 --- a/neutron/plugins/ml2/drivers/type_tunnel.py +++ b/neutron/plugins/ml2/drivers/type_tunnel.py @@ -17,13 +17,14 @@ from abc import ABCMeta, abstractmethod from neutron.common import exceptions as exc from neutron.common import topics from neutron.openstack.common import log +from neutron.plugins.ml2 import driver_api as api LOG = log.getLogger(__name__) TUNNEL = 'tunnel' -class TunnelTypeDriver(object): +class TunnelTypeDriver(api.TypeDriver): """Define stable abstract interface for ML2 type drivers. tunnel type networks rely on tunnel endpoints. This class defines abstract @@ -63,6 +64,26 @@ class TunnelTypeDriver(object): LOG.info(_("%(type)s ID ranges: %(range)s"), {'type': tunnel_type, 'range': current_range}) + def validate_provider_segment(self, segment): + physical_network = segment.get(api.PHYSICAL_NETWORK) + if physical_network: + msg = _("provider:physical_network specified for %s " + "network") % segment.get(api.NETWORK_TYPE) + raise exc.InvalidInput(error_message=msg) + + segmentation_id = segment.get(api.SEGMENTATION_ID) + if not segmentation_id: + msg = _("segmentation_id required for %s provider " + "network") % segment.get(api.NETWORK_TYPE) + raise exc.InvalidInput(error_message=msg) + + for key, value in segment.items(): + if value and key not in [api.NETWORK_TYPE, + api.SEGMENTATION_ID]: + msg = (_("%(key)s prohibited for %(tunnel)s provider network"), + {'key': key, 'tunnel': segment.get(api.NETWORK_TYPE)}) + raise exc.InvalidInput(error_message=msg) + class TunnelRpcCallbackMixin(object): diff --git a/neutron/plugins/ml2/drivers/type_vlan.py b/neutron/plugins/ml2/drivers/type_vlan.py index 185be432cf4..ccecaf17186 100644 --- a/neutron/plugins/ml2/drivers/type_vlan.py +++ b/neutron/plugins/ml2/drivers/type_vlan.py @@ -107,7 +107,7 @@ class VlanTypeDriver(api.TypeDriver): # process vlan ranges for each configured physical network for (physical_network, - vlan_ranges) in self.network_vlan_ranges.iteritems(): + vlan_ranges) in self.network_vlan_ranges.items(): # determine current configured allocatable vlans for # this physical network vlan_ids = set() @@ -181,15 +181,13 @@ class VlanTypeDriver(api.TypeDriver): 'max': q_const.MAX_VLAN_TAG}) raise exc.InvalidInput(error_message=msg) - for key, value in segment.iteritems(): + for key, value in segment.items(): if value and key not in [api.NETWORK_TYPE, api.PHYSICAL_NETWORK, api.SEGMENTATION_ID]: msg = _("%s prohibited for VLAN provider network") % key raise exc.InvalidInput(error_message=msg) - return segment - def reserve_provider_segment(self, session, segment): physical_network = segment[api.PHYSICAL_NETWORK] vlan_id = segment[api.SEGMENTATION_ID] diff --git a/neutron/plugins/ml2/drivers/type_vxlan.py b/neutron/plugins/ml2/drivers/type_vxlan.py index 949a11b757e..75f7d0b0ff2 100644 --- a/neutron/plugins/ml2/drivers/type_vxlan.py +++ b/neutron/plugins/ml2/drivers/type_vxlan.py @@ -65,8 +65,7 @@ class VxlanEndpoints(model_base.BASEV2): return "" % self.ip_address -class VxlanTypeDriver(api.TypeDriver, - type_tunnel.TunnelTypeDriver): +class VxlanTypeDriver(type_tunnel.TunnelTypeDriver): def get_type(self): return TYPE_VXLAN @@ -80,18 +79,6 @@ class VxlanTypeDriver(api.TypeDriver, ) self._sync_vxlan_allocations() - def validate_provider_segment(self, segment): - physical_network = segment.get(api.PHYSICAL_NETWORK) - if physical_network: - msg = _("provider:physical_network specified for VXLAN " - "network") - raise exc.InvalidInput(error_message=msg) - - segmentation_id = segment.get(api.SEGMENTATION_ID) - if segmentation_id is None: - msg = _("segmentation_id required for VXLAN provider network") - raise exc.InvalidInput(error_message=msg) - def reserve_provider_segment(self, session, segment): segmentation_id = segment.get(api.SEGMENTATION_ID) with session.begin(subtransactions=True): diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index e53bce7f8b1..3e30e534c88 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -82,7 +82,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): network_type = segment[api.NETWORK_TYPE] driver = self.drivers.get(network_type) if driver: - return driver.obj.validate_provider_segment(segment) + driver.obj.validate_provider_segment(segment) else: msg = _("network_type value '%s' not supported") % network_type raise exc.InvalidInput(error_message=msg) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 891386481ec..729bf06d6a8 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -131,7 +131,9 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, segment = {api.NETWORK_TYPE: network_type, api.PHYSICAL_NETWORK: physical_network, api.SEGMENTATION_ID: segmentation_id} - return self.type_manager.validate_provider_segment(segment) + self.type_manager.validate_provider_segment(segment) + + return segment if (attributes.is_attr_set(attrs.get(provider.PHYSICAL_NETWORK)) or attributes.is_attr_set(attrs.get(provider.SEGMENTATION_ID))):