Merge "Convert [ml2] physical_network_mtus to DictOpt"

This commit is contained in:
Zuul
2024-12-09 23:05:09 +00:00
committed by Gerrit Code Review
4 changed files with 12 additions and 29 deletions
+7 -7
View File
@@ -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 "
"<physnet>:<mtu val>. 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 <physnet>:<mtu val>. "
"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 "
+1 -8
View File
@@ -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()
@@ -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().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,
@@ -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