From: Federico Ressi Date: Wed, 15 Jul 2015 16:23:22 +0000 (+0100) Subject: Support delegation of bind_port to networking-odl backend driver. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=53831c685bb6f9897dd384003c1307def062de05;p=openstack-build%2Fneutron-build.git Support delegation of bind_port to networking-odl backend driver. 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 --- diff --git a/neutron/plugins/ml2/drivers/opendaylight/driver.py b/neutron/plugins/ml2/drivers/opendaylight/driver.py index 28d6931f5..052285025 100644 --- a/neutron/plugins/ml2/drivers/opendaylight/driver.py +++ b/neutron/plugins/ml2/drivers/opendaylight/driver.py @@ -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) diff --git a/neutron/tests/unit/plugins/ml2/drivers/opendaylight/test_driver.py b/neutron/tests/unit/plugins/ml2/drivers/opendaylight/test_driver.py index 03b835467..09f6d0ca5 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/opendaylight/test_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/opendaylight/test_driver.py @@ -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)