From: Irena Berezovsky Date: Thu, 18 Dec 2014 04:34:59 +0000 (+0200) Subject: Add support for flat networks in SRIOV Mechanism Driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=baadeab8c16966d9f47949f216e0fa2ae57960b9;p=openstack-build%2Fneutron-build.git Add support for flat networks in SRIOV Mechanism Driver Allow flat network segment to be bound by SRIOV Mechanism Driver. Populate vif_details with vlan_id = 0 to support flat networking (according to man page of ip command). Change-Id: Ibbe2db51ed370f416e81d90d203049e7c39eff5b Closes-Bug: 1403626 --- diff --git a/neutron/plugins/ml2/drivers/mech_sriov/exceptions.py b/neutron/plugins/ml2/drivers/mech_sriov/exceptions.py new file mode 100644 index 000000000..7b761de96 --- /dev/null +++ b/neutron/plugins/ml2/drivers/mech_sriov/exceptions.py @@ -0,0 +1,23 @@ +# Copyright (c) 2014 OpenStack Foundation +# All Rights Reserved. +# +# 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. + +"""Exceptions used by SRIOV Mechanism Driver.""" + +from neutron.common import exceptions + + +class SriovUnsupportedNetworkType(exceptions.NeutronException): + """Method was invoked for unsupported network type.""" + message = _("Unsupported network type %(net_type)s.") diff --git a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py index 577ba57bd..dd3421dc9 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver.py @@ -22,9 +22,11 @@ from neutron.i18n import _LE, _LW from neutron.openstack.common import log from neutron.plugins.common import constants as p_const from neutron.plugins.ml2 import driver_api as api +from neutron.plugins.ml2.drivers.mech_sriov import exceptions as exc LOG = log.getLogger(__name__) +FLAT_VLAN = 0 sriov_opts = [ cfg.ListOpt('supported_pci_vendor_devs', @@ -77,6 +79,7 @@ class SriovNicSwitchMechanismDriver(api.MechanismDriver): self.supported_vnic_types = supported_vnic_types self.vif_type = vif_type self.vif_details = vif_details + self.supported_network_types = (p_const.TYPE_VLAN, p_const.TYPE_FLAT) def initialize(self): try: @@ -120,7 +123,7 @@ class SriovNicSwitchMechanismDriver(api.MechanismDriver): if self.check_segment(segment, agent): context.set_binding(segment[api.ID], self.vif_type, - self.get_vif_details(context, segment), + self._get_vif_details(segment), constants.PORT_STATUS_ACTIVE) LOG.debug("Bound using segment: %s", segment) return True @@ -134,7 +137,7 @@ class SriovNicSwitchMechanismDriver(api.MechanismDriver): :returns: True if segment can be bound for agent """ network_type = segment[api.NETWORK_TYPE] - if network_type == p_const.TYPE_VLAN: + if network_type in self.supported_network_types: if agent: mappings = agent['configurations'].get('device_mappings', {}) LOG.debug("Checking segment: %(segment)s " @@ -160,11 +163,17 @@ class SriovNicSwitchMechanismDriver(api.MechanismDriver): return True return False - def get_vif_details(self, context, segment): - if segment[api.NETWORK_TYPE] == p_const.TYPE_VLAN: - vlan_id = str(segment[api.SEGMENTATION_ID]) - self.vif_details[portbindings.VIF_DETAILS_VLAN] = vlan_id - return self.vif_details + def _get_vif_details(self, segment): + network_type = segment[api.NETWORK_TYPE] + if network_type == p_const.TYPE_FLAT: + vlan_id = FLAT_VLAN + elif network_type == p_const.TYPE_VLAN: + vlan_id = segment[api.SEGMENTATION_ID] + else: + raise exc.SriovUnsupportedNetworkType(net_type=network_type) + vif_details = self.vif_details.copy() + vif_details[portbindings.VIF_DETAILS_VLAN] = str(vlan_id) + return vif_details def _parse_pci_vendor_config(self, pci_vendor_list): parsed_list = [] diff --git a/neutron/tests/unit/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py b/neutron/tests/unit/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py index 978273378..92ec081e9 100644 --- a/neutron/tests/unit/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py +++ b/neutron/tests/unit/ml2/drivers/mech_sriov/test_mech_sriov_nic_switch.py @@ -15,12 +15,14 @@ import mock from oslo.config import cfg +import testtools from neutron.common import constants from neutron.extensions import portbindings from neutron.plugins.common import constants as p_const from neutron.plugins.ml2 import config # noqa from neutron.plugins.ml2 import driver_api as api +from neutron.plugins.ml2.drivers.mech_sriov import exceptions as exc from neutron.plugins.ml2.drivers.mech_sriov import mech_driver from neutron.tests.unit.ml2 import _test_mech_agent as base @@ -94,6 +96,11 @@ class SriovSwitchMechGenericTestCase(SriovNicSwitchMechanismBaseTestCase, segment[api.NETWORK_TYPE] = p_const.TYPE_GRE self.assertFalse(self.driver.check_segment(segment)) + def test_check_segment_allows_supported_network_types(self): + for network_type in self.driver.supported_network_types: + segment = {api.NETWORK_TYPE: network_type} + self.assertTrue(self.driver.check_segment(segment)) + class SriovMechVlanTestCase(SriovNicSwitchMechanismBaseTestCase, base.AgentMechanismBaseTestCase): @@ -206,6 +213,17 @@ class SriovSwitchMechVifDetailsTestCase(SriovNicSwitchMechanismBaseTestCase): vlan_id = int(vif_details.get(portbindings.VIF_DETAILS_VLAN)) self.assertEqual(1234, vlan_id) + def test_get_vif_details_for_flat_network(self): + segment = {api.NETWORK_TYPE: p_const.TYPE_FLAT} + vif_details = self.driver._get_vif_details(segment) + vlan_id = vif_details[portbindings.VIF_DETAILS_VLAN] + self.assertEqual('0', vlan_id) + + def test_get_vif_details_unsupported_net(self): + segment = {api.NETWORK_TYPE: 'foo'} + with testtools.ExpectedException(exc.SriovUnsupportedNetworkType): + self.driver._get_vif_details(segment) + class SriovSwitchMechConfigTestCase(SriovNicSwitchMechanismBaseTestCase): def _set_config(self, pci_devs=['aa:bb']): @@ -231,4 +249,4 @@ class SriovSwitchMechConfigTestCase(SriovNicSwitchMechanismBaseTestCase): def test_pci_vendor_config_wrong_entry(self): self._set_config('wrong_entry') - self.assertRaises(cfg.Error, self.driver.initialize) + self.assertRaises(cfg.Error, self.driver.initialize) \ No newline at end of file