From: Oleh Prypin Date: Thu, 9 Jun 2016 13:46:09 +0000 (+0300) Subject: [RM-15016] Opt out of a backwards-incompatible change in configparser X-Git-Tag: v1.5.35~10^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e2df002c22c6542746978d7f15a088a81cf82758;p=ceph-deploy.git [RM-15016] Opt out of a backwards-incompatible change in configparser Signed-off-by: Oleh Prypin --- diff --git a/ceph_deploy/conf/ceph.py b/ceph_deploy/conf/ceph.py index 6568fe5..e14ad6d 100644 --- a/ceph_deploy/conf/ceph.py +++ b/ceph_deploy/conf/ceph.py @@ -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()) diff --git a/ceph_deploy/tests/test_conf.py b/ceph_deploy/tests/test_conf.py index eb37890..8d435df 100644 --- a/ceph_deploy/tests/test_conf.py +++ b/ceph_deploy/tests/test_conf.py @@ -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'