]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-15016] Opt out of a backwards-incompatible change in configparser
authorOleh Prypin <oleh@pryp.in>
Thu, 9 Jun 2016 13:46:09 +0000 (16:46 +0300)
committerOleh Prypin <oleh@pryp.in>
Thu, 9 Jun 2016 13:48:47 +0000 (16:48 +0300)
Signed-off-by: Oleh Prypin <oleh@pryp.in>
ceph_deploy/conf/ceph.py
ceph_deploy/tests/test_conf.py

index 6568fe55d877913a4306a06d00b3a06bdd3ddebe..e14ad6d62bf5d0dedf439127307c33dcbe24d3a6 100644 (file)
@@ -3,6 +3,7 @@ try:
 except ImportError:
     import ConfigParser as configparser
 import contextlib
+import sys
 
 from ceph_deploy import exc
 
@@ -19,6 +20,12 @@ class _TrimIndentFile(object):
         return iter(self.readline, '')
 
 class CephConf(configparser.RawConfigParser):
+    def __init__(self, *args, **kwargs):
+        if sys.version_info >= (3, 2):
+            kwargs.setdefault('strict', False)
+        # super() cannot be used with an old-style class
+        configparser.RawConfigParser.__init__(self, *args, **kwargs)
+
     def optionxform(self, s):
         s = s.replace('_', ' ')
         s = '_'.join(s.split())
index eb378909b2ff1b186dfa123b1dc22b2d61c3c2bc..8d435df6ad1ed7a198a2f1fac8e1c243269096a9 100644 (file)
@@ -61,6 +61,7 @@ bar__ thud   quux = baz
     assert cfg.get('foo', 'bar_thud_quux') == 'baz'
     assert cfg.get('foo', 'bar thud quux') == 'baz'
 
+
 def test_write_words_underscore():
     cfg = conf.ceph.CephConf()
     cfg.add_section('foo')
@@ -69,3 +70,17 @@ def test_write_words_underscore():
     cfg.write(f)
     f.seek(0)
     assert f.readlines() == ['[foo]\n', 'bar_thud_quux = baz\n','\n']
+
+
+def test_section_repeat():
+    f = StringIO("""\
+[foo]
+bar = bez
+thud = quux
+
+[foo]
+bar = baz
+""")
+    cfg = conf.ceph.parse(f)
+    assert cfg.get('foo', 'bar') == 'baz'
+    assert cfg.get('foo', 'thud') == 'quux'