]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
ML2 tunnel drivers validate provider networks correctly
authormathieu-rohon <mathieu.rohon@gmail.com>
Thu, 25 Jul 2013 08:38:16 +0000 (10:38 +0200)
committerMark McClain <mark.mcclain@dreamhost.com>
Fri, 26 Jul 2013 15:58:24 +0000 (11:58 -0400)
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
neutron/plugins/ml2/drivers/type_flat.py
neutron/plugins/ml2/drivers/type_gre.py
neutron/plugins/ml2/drivers/type_local.py
neutron/plugins/ml2/drivers/type_tunnel.py
neutron/plugins/ml2/drivers/type_vlan.py
neutron/plugins/ml2/drivers/type_vxlan.py
neutron/plugins/ml2/managers.py
neutron/plugins/ml2/plugin.py

index 23e7e5d3efb087c59a0e4dfcc8010826b3dede56..5bc7ca8393f6c309e8bf41741d9ac99471b6ae18 100644 (file)
@@ -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
index af67366e509b83b7c1c4ad8e8c00e63cc7ecdeff..72904508b691cb1f9a42878f868f9c3179edc5c0 100644 (file)
@@ -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):
index 906d61f867d2fe057e653ff7efca99e650aa780a..d0a9e53073bce80c511bbfbc321e483befc14738 100644 (file)
@@ -58,8 +58,7 @@ class GreEndpoints(model_base.BASEV2):
         return "<GreTunnelEndpoint(%s)>" % 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):
index 1fb0f2e961313b25ba68c5cf0773b54f43dcb240..712d4f37440cac34350907ea5481057a8c5533e1 100644 (file)
@@ -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
index b447f5582bc5cf4b35c6a23a31724e94dbd109a2..341a023f22722378bfa85b01860abce7778ee906 100644 (file)
@@ -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):
 
index 185be432cf4fddf216b35c543d8447997e791bd3..ccecaf171863fc20dde90d9dca60912b4d5ad308 100644 (file)
@@ -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]
index 949a11b757ecb82981ae5f99a2a72cb4f0d297a0..75f7d0b0ff223a351a81b05b6dd511bb80300145 100644 (file)
@@ -65,8 +65,7 @@ class VxlanEndpoints(model_base.BASEV2):
         return "<VxlanTunnelEndpoint(%s)>" % 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):
index e53bce7f8b171b34b5423bdded8b05b8ade12d88..3e30e534c8805d6cb4a3280d0ff018fcee954d16 100644 (file)
@@ -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)
index 891386481ecac0b5e3bc672a8872be8d0b81e3c5..729bf06d6a8856dfcce427ad4d8ccae23bb09772 100644 (file)
@@ -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))):