Fix sorting issue in python 3

Fix an error appear when trying to sort options when having many options
and many groups in python 3.4.

Change-Id: Iec7447e004f3708d92bd30aad94a17378fc25f31
Closes-Bug: #1463025
This commit is contained in:
Thomas Herve 2015-06-08 15:36:52 +02:00
parent 02a86d2eef
commit 0c9113f682
2 changed files with 15 additions and 1 deletions
oslo_config

@ -1595,7 +1595,7 @@ class _Namespace(argparse.Namespace):
namespace = _Namespace(self._conf)
namespace._parser._add_parsed_config_file(sections, normalized)
for opt, group in sorted(self._conf._all_cli_opts()):
for opt, group in self._conf._all_cli_opts():
group_name = group.name if group is not None else None
try:
value = opt._get_from_namespace(namespace, group_name)

@ -1431,6 +1431,20 @@ class ConfigFileOptsTestCase(BaseTestCase):
self.assertTrue(hasattr(self.conf, 'foo'))
self.assertEqual(self.conf.foo, 'bar-%08x')
def test_conf_file_sorted_group(self):
# Create enough groups for the sorted problem to appear
for i in range(10):
group = cfg.OptGroup('group%s' % i, 'options')
self.conf.register_group(group)
self.conf.register_cli_opt(cfg.StrOpt('opt1'), group=group)
paths = self.create_tempfiles(
[('test', '[group1]\nopt1 = foo\n[group2]\nopt2 = bar\n')])
self.conf(['--config-file', paths[0]])
self.assertEqual(self.conf.group1.opt1, 'foo')
class ConfigFileReloadTestCase(BaseTestCase):