Normalize group sections
The current implementation doesn't distinguish between different cases for the group sections. As result, some options are grouped in different places or even duplicate their values. This change normalize the group sections to lower case with the exception of DEFAULT group. Change-Id: Ia6bced383d36977005e2bf4532bdca9e9d4fe515 Closes-Bug: #1646084
This commit is contained in:
parent
30dbe55791
commit
1dbf887909
|
@ -37,6 +37,7 @@ from oslo_config import cfg
|
|||
import stevedore.named # noqa
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
UPPER_CASE_GROUP_NAMES = ['DEFAULT']
|
||||
|
||||
_generator_opts = [
|
||||
cfg.StrOpt(
|
||||
|
@ -347,6 +348,22 @@ def _cleanup_opts(read_opts):
|
|||
if namespace not in clean:
|
||||
clean[namespace] = collections.OrderedDict()
|
||||
for group, opts in listing:
|
||||
# NOTE: Normalize group names to lowe-case except those defined in
|
||||
# UPPER_CASE_GROUP_NAMES
|
||||
if group:
|
||||
group_name = getattr(group, 'name', str(group))
|
||||
if group_name.upper() in UPPER_CASE_GROUP_NAMES:
|
||||
normalized_gn = group_name.upper()
|
||||
else:
|
||||
normalized_gn = group_name.lower()
|
||||
if normalized_gn != group_name:
|
||||
LOG.warning('normalizing group name %r to %r', group_name,
|
||||
normalized_gn)
|
||||
if hasattr(group, 'name'):
|
||||
group.name = normalized_gn
|
||||
else:
|
||||
group = normalized_gn
|
||||
|
||||
if group not in clean[namespace]:
|
||||
clean[namespace][group] = collections.OrderedDict()
|
||||
for opt in opts:
|
||||
|
@ -355,8 +372,8 @@ def _cleanup_opts(read_opts):
|
|||
# recreate the list of (namespace, [(group, [opt_1, opt_2])]) tuples
|
||||
# from the cleaned structure.
|
||||
cleaned_opts = [
|
||||
(namespace, [(group, list(clean[namespace][group].values()))
|
||||
for group in clean[namespace]])
|
||||
(namespace, [(g, list(clean[namespace][g].values()))
|
||||
for g in clean[namespace]])
|
||||
for namespace in clean
|
||||
]
|
||||
|
||||
|
|
|
@ -953,6 +953,19 @@ class IgnoreDoublesTestCase(base.BaseTestCase):
|
|||
("group3", self.opts)])]
|
||||
self.assertEqual(e, generator._cleanup_opts(o))
|
||||
|
||||
def test_cleanup_opts_dup_mixed_case_groups_opt(self):
|
||||
o = [("namespace1", [
|
||||
("default", self.opts),
|
||||
("Default", self.opts + [self.opts[1]]),
|
||||
("DEFAULT", self.opts + [self.opts[2]]),
|
||||
("group1", self.opts + [self.opts[1]]),
|
||||
("Group1", self.opts),
|
||||
("GROUP1", self.opts + [self.opts[2]])])]
|
||||
e = [("namespace1", [
|
||||
("DEFAULT", self.opts),
|
||||
("group1", self.opts)])]
|
||||
self.assertEqual(e, generator._cleanup_opts(o))
|
||||
|
||||
def test_cleanup_opts_dup_namespace_groups_opts(self):
|
||||
o = [("namespace1", [
|
||||
("group1", self.opts + [self.opts[1]]),
|
||||
|
|
Loading…
Reference in New Issue