]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Support delegation of bind_port to networking-odl backend driver.
authorFederico Ressi <federico.ressi@intel.com>
Wed, 15 Jul 2015 16:23:22 +0000 (17:23 +0100)
committerFederico Ressi <federico.ressi@intel.com>
Mon, 10 Aug 2015 14:07:59 +0000 (14:07 +0000)
The OpenDaylightMechanismDriver delegates bind_port to networking-odl
backend driver. Move check_segment toghether with bind_port as is
used only there. This will enabled extension of bind_port to
support other port types such as vhost-user in a separated patch-set
to networking-odl without requiring further changes to the front-end
component in neutron.

Change-Id: I27948ac0b440b8b4d04e496971593850e78739d0
Closes-Bug: #1477483
Depends-On: Id663147020b9780129c65ba0bb6d743a9de9cd4b

neutron/plugins/ml2/drivers/opendaylight/driver.py
neutron/tests/unit/plugins/ml2/drivers/opendaylight/test_driver.py

index 28d6931f5a1e7bd037dc6f0afbf07019ece7b03b..052285025142367995052d67bc66367c92ca21f5 100644 (file)
@@ -18,9 +18,6 @@ from networking_odl.ml2 import mech_driver
 from oslo_config import cfg
 from oslo_log import log
 
-from neutron.common import constants as n_const
-from neutron.extensions import portbindings
-from neutron.plugins.common import constants
 from neutron.plugins.ml2 import driver_api as api
 
 LOG = log.getLogger(__name__)
@@ -59,8 +56,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
         for opt in required_opts:
             if not getattr(self, opt):
                 raise cfg.RequiredOptError(opt, 'ml2_odl')
-        self.vif_type = portbindings.VIF_TYPE_OVS
-        self.vif_details = {portbindings.CAP_PORT_FILTER: True}
+
         self.odl_drv = mech_driver.OpenDaylightDriver()
 
     # Postcommit hooks are used to trigger synchronization.
@@ -93,33 +89,4 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
         self.odl_drv.synchronize('delete', odl_const.ODL_PORTS, context)
 
     def bind_port(self, context):
-        LOG.debug("Attempting to bind port %(port)s on "
-                  "network %(network)s",
-                  {'port': context.current['id'],
-                   'network': context.network.current['id']})
-        for segment in context.segments_to_bind:
-            if self.check_segment(segment):
-                context.set_binding(segment[api.ID],
-                                    self.vif_type,
-                                    self.vif_details,
-                                    status=n_const.PORT_STATUS_ACTIVE)
-                LOG.debug("Bound using segment: %s", segment)
-                return
-            else:
-                LOG.debug("Refusing to bind port for segment ID %(id)s, "
-                          "segment %(seg)s, phys net %(physnet)s, and "
-                          "network type %(nettype)s",
-                          {'id': segment[api.ID],
-                           'seg': segment[api.SEGMENTATION_ID],
-                           'physnet': segment[api.PHYSICAL_NETWORK],
-                           'nettype': segment[api.NETWORK_TYPE]})
-
-    def check_segment(self, segment):
-        """Verify a segment is valid for the OpenDaylight MechanismDriver.
-
-        Verify the requested segment is supported by ODL and return True or
-        False to indicate this to callers.
-        """
-        network_type = segment[api.NETWORK_TYPE]
-        return network_type in [constants.TYPE_LOCAL, constants.TYPE_GRE,
-                                constants.TYPE_VXLAN, constants.TYPE_VLAN]
+        self.odl_drv.bind_port(context)
index 03b8354676457cad6f023c96b771f2dfb11b9f3c..09f6d0ca53006896317a2244f9d8d346cc6c4413 100644 (file)
@@ -90,3 +90,17 @@ class TestODLShim(test_plugin.Ml2PluginV2TestCase):
         self.driver.odl_drv.synchronize.assert_called_with('delete',
                                                            const.ODL_PORTS,
                                                            self.context)
+
+    def test_bind_port_delegation(self):
+        # given front-end with attached back-end
+        front_end = self.driver
+        front_end.odl_drv = back_end = mock.MagicMock(
+            spec=driver.OpenDaylightMechanismDriver)
+        # given PortContext to be forwarded to back-end without using
+        context = object()
+
+        # when binding port
+        front_end.bind_port(context)
+
+        # then port is bound by back-end
+        back_end.bind_port.assert_called_once_with(context)