diff options
author | Zhongyue Luo <zhongyue.nah@intel.com> | 2013-09-12 21:23:36 +0800 |
---|---|---|
committer | Zhongyue Luo <zhongyue.nah@intel.com> | 2013-09-23 23:01:51 +0900 |
commit | 7ec9a88fc451386c23e472036849385da038f4fa (patch) | |
tree | 200ec493875489f2eea1bbb55e18a4f62f8b2f71 /tests/test_cfg.py | |
parent | f2be4e83f04579ee0cd87e8601868f310c951fac (diff) | |
download | oslo-config-7ec9a88fc451386c23e472036849385da038f4fa.tar.gz |
Raises error if duplicate keys found in DictOpt
DictOpt didn't report when the input values had duplicate keys.
This would be a problem if the user had put in duplicate keys in
the conf file and the service didn't work as expected.
(c.f) Neutrons provider network mapping options
This patch raises a ConfigFileValueError when duplicate keys are found.
Fixes bug #1228995
Change-Id: I91e1bd0eda4ed4fd6c7eb6ea5d4a89d583d1305e
Diffstat (limited to 'tests/test_cfg.py')
-rw-r--r-- | tests/test_cfg.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_cfg.py b/tests/test_cfg.py index 8d939ca..3f2fafc 100644 --- a/tests/test_cfg.py +++ b/tests/test_cfg.py @@ -1022,6 +1022,30 @@ class ConfigFileOptsTestCase(BaseTestCase): self.assertTrue(hasattr(self.conf, 'foo')) self.assertEqual(self.conf.foo, {'key': 'bar:baz'}) + def test_conf_file_dict_value_no_colon(self): + self.conf.register_opt(cfg.DictOpt('foo')) + + paths = self.create_tempfiles([('test', + '[DEFAULT]\n' + 'foo = key:bar,baz\n')]) + + self.conf(['--config-file', paths[0]]) + + self.assertRaises(cfg.ConfigFileValueError, self.conf._get, 'foo') + self.assertRaises(AttributeError, getattr, self.conf, 'foo') + + def test_conf_file_dict_value_duplicate_key(self): + self.conf.register_opt(cfg.DictOpt('foo')) + + paths = self.create_tempfiles([('test', + '[DEFAULT]\n' + 'foo = key:bar,key:baz\n')]) + + self.conf(['--config-file', paths[0]]) + + self.assertRaises(cfg.ConfigFileValueError, self.conf._get, 'foo') + self.assertRaises(AttributeError, getattr, self.conf, 'foo') + def test_conf_file_dict_values_override_deprecated(self): self.conf.register_cli_opt(cfg.DictOpt('foo', deprecated_name='oldfoo')) |