Merge "Normalize group sections"
This commit is contained in:
commit
978522a8b2
|
@ -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