From ae4b4300f9dacee68ce5a1dfd88c601424d2229d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 24 Sep 2024 10:47:52 +0900 Subject: [PATCH] Convert [ml2] physical_network_mtus to DictOpt This option accepts a dictionary value. Use the native oslo.config implementation so that its value is parsed at config layer and explicit error is returned to users in case an invalid value is configured. Change-Id: I35195eea928f99ba4ae2bcdea51436d250062d47 --- neutron/conf/plugins/ml2/config.py | 14 +++++++------- neutron/plugins/ml2/drivers/helpers.py | 9 +-------- .../unit/plugins/ml2/drivers/test_type_flat.py | 14 ++------------ .../unit/plugins/ml2/drivers/test_type_vlan.py | 4 ++-- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/neutron/conf/plugins/ml2/config.py b/neutron/conf/plugins/ml2/config.py index cd56ee6794a..651ec614b9b 100644 --- a/neutron/conf/plugins/ml2/config.py +++ b/neutron/conf/plugins/ml2/config.py @@ -51,13 +51,13 @@ ml2_opts = [ 'This option allows specifying a physical network MTU ' 'value that differs from the default global_physnet_mtu ' 'value.')), - cfg.ListOpt('physical_network_mtus', - default=[], - help=_("A list of mappings of physical networks to MTU " - "values. The format of the mapping is " - ":. This mapping allows " - "specifying a physical network MTU value that " - "differs from the default global_physnet_mtu value.")), + cfg.DictOpt('physical_network_mtus', + default={}, + help=_("Mappings of physical networks to MTU values. " + "The format of the mapping is :. " + "This mapping allows specifying a physical network MTU " + "value that differs from " + "the default global_physnet_mtu value.")), cfg.StrOpt('external_network_type', help=_("Default network type for external networks when no " "provider attributes are specified. By default it is " diff --git a/neutron/plugins/ml2/drivers/helpers.py b/neutron/plugins/ml2/drivers/helpers.py index 91b0b1ea1f3..9f0891b50fd 100644 --- a/neutron/plugins/ml2/drivers/helpers.py +++ b/neutron/plugins/ml2/drivers/helpers.py @@ -22,7 +22,6 @@ from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import directory from neutron_lib.plugins.ml2 import api from neutron_lib.plugins import utils as p_utils -from neutron_lib.utils import helpers from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log @@ -37,13 +36,7 @@ class BaseTypeDriver(api.ML2TypeDriver): """BaseTypeDriver for functions common to Segment and flat.""" def __init__(self): - try: - self.physnet_mtus = helpers.parse_mappings( - cfg.CONF.ml2.physical_network_mtus, unique_values=False - ) - except Exception as e: - LOG.error("Failed to parse physical_network_mtus: %s", e) - self.physnet_mtus = [] + self.physnet_mtus = cfg.CONF.ml2.physical_network_mtus def get_mtu(self, physical_network=None): return p_utils.get_deployment_physnet_mtu() diff --git a/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py b/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py index 4b3cf36f042..0538ab986eb 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py +++ b/neutron/tests/unit/plugins/ml2/drivers/test_type_flat.py @@ -38,7 +38,7 @@ class FlatTypeTest(testlib_api.SqlTestCase): group='ml2_type_flat') self.driver = type_flat.FlatTypeDriver() self.context = context.Context() - self.driver.physnet_mtus = [] + self.driver.physnet_mtus = {} def _get_allocation(self, context, segment): return flat_obj.FlatAllocation.get_object( @@ -145,23 +145,13 @@ class FlatTypeTest(testlib_api.SqlTestCase): self.driver.physnet_mtus = {} self.assertEqual(0, self.driver.get_mtu('physnet1')) - def test_parse_physical_network_mtus(self): - cfg.CONF.set_override( - 'physical_network_mtus', - ['physnet1:1500', 'physnet2:1500', 'physnet3:9000'], - group='ml2') - driver = type_flat.FlatTypeDriver() - self.assertEqual('1500', driver.physnet_mtus['physnet1']) - self.assertEqual('1500', driver.physnet_mtus['physnet2']) - self.assertEqual('9000', driver.physnet_mtus['physnet3']) - class FlatTypeDefaultTest(base.BaseTestCase): def setUp(self): super(FlatTypeDefaultTest, self).setUp() self.driver = type_flat.FlatTypeDriver() - self.driver.physnet_mtus = [] + self.driver.physnet_mtus = {} def test_validate_provider_segment_default(self): segment = {api.NETWORK_TYPE: p_const.TYPE_FLAT, diff --git a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py index e707ca42f4f..2ced3bedcb5 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py +++ b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py @@ -66,7 +66,7 @@ class VlanTypeTest(testlib_api.SqlTestCase): self.driver = type_vlan.VlanTypeDriver() self.driver._sync_vlan_allocations() self.context = context.Context() - self.driver.physnet_mtus = [] + self.driver.physnet_mtus = {} self.setup_coreplugin(CORE_PLUGIN) def test_parse_network_exception_handling(self): @@ -328,7 +328,7 @@ class VlanTypeAllocationTest(testlib_api.SqlTestCase): ranges, group='ml2_type_vlan') driver = type_vlan.VlanTypeDriver() - driver.physnet_mtus = [] + driver.physnet_mtus = {} driver._sync_vlan_allocations() # swap config order from DB order after sync has happened to # ensure config order is followed and not DB order