From d860109bf60421a721e5009ca6f66a767bfd3488 Mon Sep 17 00:00:00 2001 From: Lajos Katona Date: Fri, 28 Sep 2018 10:08:10 +0200 Subject: [PATCH] supported_vnic_type configurable for sriov Now supported_vnic_types is hardcoded to the mechanism drivers, but that can depend on several factors, like type of the NIC, admin decision, etc. With this patch we put the right to decide which vnic types are supported for ovs agent into the hands of the admin, by allowing blacklisting items from the mechanism driver specific list. Background: http://eavesdrop.openstack.org/meetings/neutron_qos/2018/ neutron_qos.2018-07-31-15.00.log.html#l-58 Change-Id: Iad9e2e966df53b4164d2a56a93215c69825b5241 Partial-Bug: #1578989 See-Also: https://review.openstack.org/502306 (nova spec) See-Also: https://review.openstack.org/508149 (neutron spec) --- doc/source/admin/config-ml2.rst | 2 +- .../ml2/drivers/mech_sriov/mech_sriov_conf.py | 35 +++++++++ neutron/opts.py | 6 +- .../mech_sriov/mech_driver/mech_driver.py | 16 +++- .../mech_driver/test_mech_sriov_nic_switch.py | 75 +++++++++++++++++++ ...nfigurable-for-sriov-094f7663e8975e9b.yaml | 9 +++ 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 neutron/conf/plugins/ml2/drivers/mech_sriov/mech_sriov_conf.py create mode 100644 releasenotes/notes/make-supported-vnic-types-configurable-for-sriov-094f7663e8975e9b.yaml diff --git a/doc/source/admin/config-ml2.rst b/doc/source/admin/config-ml2.rst index b9ed28ba9a3..68a77ad0200 100644 --- a/doc/source/admin/config-ml2.rst +++ b/doc/source/admin/config-ml2.rst @@ -283,7 +283,7 @@ The ``vnic_type_blacklist`` option is used to remove values from the mechanism d - yes (ovs_driver vnic_type_blacklist, see: `Configuration Reference <../configuration/ml2-conf.html#ovs_driver>`__) * - SRIOV - direct, macvtap, direct_physical - - no + - yes (sriov_driver vnic_type_blacklist, see: `Configuration Reference <../configuration/ml2-conf.html#sriov_driver>`__) Extension Drivers diff --git a/neutron/conf/plugins/ml2/drivers/mech_sriov/mech_sriov_conf.py b/neutron/conf/plugins/ml2/drivers/mech_sriov/mech_sriov_conf.py new file mode 100644 index 00000000000..d044860828b --- /dev/null +++ b/neutron/conf/plugins/ml2/drivers/mech_sriov/mech_sriov_conf.py @@ -0,0 +1,35 @@ +# Copyright (c) 2018 Ericsson +# +# 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. + +from oslo_config import cfg + +from neutron._i18n import _ + + +sriov_driver_opts = [ + cfg.ListOpt('vnic_type_blacklist', + default=[], + help=_("Comma-separated list of VNIC types for which support " + "is administratively prohibited by the mechanism " + "driver. Please note that the supported vnic_types " + "depend on your network interface card, on the kernel " + "version of your operating system, and on other " + "factors. " + "In case of sriov mechanism driver the valid " + "VNIC types are direct, macvtap and direct-physical.")), +] + + +def register_sriov_mech_driver_opts(cfg=cfg.CONF): + cfg.register_opts(sriov_driver_opts, "SRIOV_DRIVER") diff --git a/neutron/opts.py b/neutron/opts.py index f968902a47a..ea58b1ea362 100644 --- a/neutron/opts.py +++ b/neutron/opts.py @@ -47,6 +47,7 @@ import neutron.conf.plugins.ml2.drivers.l2pop import neutron.conf.plugins.ml2.drivers.linuxbridge import neutron.conf.plugins.ml2.drivers.macvtap import neutron.conf.plugins.ml2.drivers.mech_sriov.agent_common +import neutron.conf.plugins.ml2.drivers.mech_sriov.mech_sriov_conf import neutron.conf.plugins.ml2.drivers.openvswitch.mech_ovs_conf import neutron.conf.plugins.ml2.drivers.ovs_conf import neutron.conf.quota @@ -259,7 +260,10 @@ def list_ml2_conf_opts(): neutron.conf.plugins.ml2.drivers.l2pop.l2_population_options), ('ovs_driver', neutron.conf.plugins.ml2.drivers.openvswitch.mech_ovs_conf. - ovs_driver_opts) + ovs_driver_opts), + ('sriov_driver', + neutron.conf.plugins.ml2.drivers.mech_sriov.mech_sriov_conf. + sriov_driver_opts) ] diff --git a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py index 77ecb00bb17..ca44975d681 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/mech_driver/mech_driver.py @@ -16,8 +16,11 @@ from neutron_lib.api.definitions import portbindings from neutron_lib import constants from neutron_lib.plugins.ml2 import api +from oslo_config import cfg + from oslo_log import log +from neutron.conf.plugins.ml2.drivers.mech_sriov import mech_sriov_conf from neutron.plugins.ml2.drivers import mech_agent from neutron.plugins.ml2.drivers.mech_sriov.mech_driver \ import exceptions as exc @@ -28,6 +31,9 @@ LOG = log.getLogger(__name__) FLAT_VLAN = 0 +mech_sriov_conf.register_sriov_mech_driver_opts() + + class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): """Mechanism Driver for SR-IOV capable NIC based switching. @@ -54,7 +60,15 @@ class SriovNicSwitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): :param supported_vnic_types: The binding:vnic_type values we can bind """ self.agent_type = agent_type - self.supported_vnic_types = supported_vnic_types + + # TODO(lajoskatona): move this blacklisting to + # SimpleAgentMechanismDriverBase. By that e blacklisting and validation + # of the vnic_types would be available for all mechanism drivers. + self.supported_vnic_types = self.blacklist_supported_vnic_types( + vnic_types=supported_vnic_types, + blacklist=cfg.CONF.SRIOV_DRIVER.vnic_type_blacklist + ) + # NOTE(ndipanov): PF passthrough requires a different vif type self.vnic_type_for_vif_type = ( {vtype: portbindings.VIF_TYPE_HOSTDEV_PHY diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py index 5bd958bfc7b..a5c67b02ca6 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/mech_driver/test_mech_sriov_nic_switch.py @@ -17,8 +17,10 @@ import mock from neutron_lib.api.definitions import portbindings from neutron_lib import constants from neutron_lib.plugins.ml2 import api +from oslo_config import cfg import testtools +from neutron.conf.plugins.ml2.drivers.mech_sriov import mech_sriov_conf from neutron.plugins.ml2.drivers.mech_sriov.mech_driver \ import exceptions as exc from neutron.plugins.ml2.drivers.mech_sriov.mech_driver import mech_driver @@ -195,3 +197,76 @@ class SriovSwitchMechVifDetailsTestCase(SriovNicSwitchMechanismBaseTestCase): self.driver.bind_port(context) self.assertEqual(constants.PORT_STATUS_ACTIVE, context._bound_state) + + +class SriovSwitchMechVnicTypesTestCase(SriovNicSwitchMechanismBaseTestCase): + + def setUp(self): + self.override_vnic_types = [portbindings.VNIC_DIRECT, + portbindings.VNIC_MACVTAP] + self.driver_with_vnic_types = \ + mech_driver.SriovNicSwitchMechanismDriver( + supported_vnic_types=self.override_vnic_types) + self.default_supported_vnics = [ + portbindings.VNIC_DIRECT, + portbindings.VNIC_MACVTAP, + portbindings.VNIC_DIRECT_PHYSICAL] + self.blacklist_cfg = { + 'SRIOV_DRIVER': { + 'vnic_type_blacklist': [] + } + } + super(SriovSwitchMechVnicTypesTestCase, self).setUp() + + def test_default_vnic_types(self): + self.assertEqual(self.default_supported_vnics, + self.driver.supported_vnic_types) + + def test_override_default_vnic_types(self): + self.assertEqual( + self.override_vnic_types, + self.driver_with_vnic_types.supported_vnic_types) + + def test_vnic_type_blacklist_valid_item(self): + self.blacklist_cfg['SRIOV_DRIVER']['vnic_type_blacklist'] = \ + [portbindings.VNIC_MACVTAP] + + fake_conf = cfg.CONF + fake_conf_fixture = base.MechDriverConfFixture( + fake_conf, self.blacklist_cfg, + mech_sriov_conf.register_sriov_mech_driver_opts) + self.useFixture(fake_conf_fixture) + + test_driver = mech_driver.SriovNicSwitchMechanismDriver( + supported_vnic_types=self.default_supported_vnics) + + supported_vnic_types = test_driver.supported_vnic_types + self.assertNotIn(portbindings.VNIC_MACVTAP, supported_vnic_types) + self.assertEqual(len(self.default_supported_vnics) - 1, + len(supported_vnic_types)) + + def test_vnic_type_blacklist_not_valid_item(self): + self.blacklist_cfg['SRIOV_DRIVER']['vnic_type_blacklist'] = ['foo'] + fake_conf = cfg.CONF + fake_conf_fixture = base.MechDriverConfFixture( + fake_conf, self.blacklist_cfg, + mech_sriov_conf.register_sriov_mech_driver_opts) + self.useFixture(fake_conf_fixture) + + self.assertRaises(ValueError, + mech_driver.SriovNicSwitchMechanismDriver) + + def test_vnic_type_blacklist_all_items(self): + self.blacklist_cfg['SRIOV_DRIVER']['vnic_type_blacklist'] = \ + [portbindings.VNIC_DIRECT, + portbindings.VNIC_MACVTAP, + portbindings.VNIC_DIRECT_PHYSICAL] + + fake_conf = cfg.CONF + fake_conf_fixture = base.MechDriverConfFixture( + fake_conf, self.blacklist_cfg, + mech_sriov_conf.register_sriov_mech_driver_opts) + self.useFixture(fake_conf_fixture) + + self.assertRaises(ValueError, + mech_driver.SriovNicSwitchMechanismDriver) diff --git a/releasenotes/notes/make-supported-vnic-types-configurable-for-sriov-094f7663e8975e9b.yaml b/releasenotes/notes/make-supported-vnic-types-configurable-for-sriov-094f7663e8975e9b.yaml new file mode 100644 index 00000000000..4f2ce776b25 --- /dev/null +++ b/releasenotes/notes/make-supported-vnic-types-configurable-for-sriov-094f7663e8975e9b.yaml @@ -0,0 +1,9 @@ +--- +other: + - | + Add new configuration group ``sriov_driver`` and new configuration option + under it ``vnic_type_blacklist``, to make the previously hardcoded + ``supported_vnic_types`` parameter of the SriovNicSwitchMechanismDriver + configurable. + The ``vnic_types`` listed in the blacklist will be removed from the + supported_vnic_types list.