From 53f46a8451dd8e10a3b9e8f2b191044f9863ae83 Mon Sep 17 00:00:00 2001 From: Andrew Woodward Date: Tue, 24 Sep 2013 11:24:17 -0700 Subject: [PATCH] [6348] ceph-deploy should use same option seperator define subclass for Ceph config files. make new.new and conf.load use new CephConf add test case for config writing. Signed-off-by: Andrew Woodward (awoodward@mirantis.com) --- ceph_deploy/conf.py | 12 ++++++------ ceph_deploy/new.py | 3 ++- ceph_deploy/tests/test_conf.py | 9 +++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ceph_deploy/conf.py b/ceph_deploy/conf.py index a7b97a4..3fcdd21 100644 --- a/ceph_deploy/conf.py +++ b/ceph_deploy/conf.py @@ -13,15 +13,15 @@ class _TrimIndentFile(object): return line.lstrip(' \t') -def _optionxform(s): - s = s.replace('_', ' ') - s = '_'.join(s.split()) - return s +class CephConf(ConfigParser.RawConfigParser): + def optionxform(self, s): + s = s.replace('_', ' ') + s = '_'.join(s.split()) + return s def parse(fp): - cfg = ConfigParser.RawConfigParser() - cfg.optionxform = _optionxform + cfg = CephConf() ifp = _TrimIndentFile(fp) cfg.readfp(ifp) return cfg diff --git a/ceph_deploy/new.py b/ceph_deploy/new.py index 404d395..9a0945b 100644 --- a/ceph_deploy/new.py +++ b/ceph_deploy/new.py @@ -10,6 +10,7 @@ import socket from . import exc from .cliutil import priority +from .conf import CephConf from .util import arg_validators from .misc import mon_hosts @@ -42,7 +43,7 @@ def get_nonlocal_ip(host): def new(args): LOG.debug('Creating new cluster named %s', args.cluster) - cfg = ConfigParser.RawConfigParser() + cfg = CephConf() cfg.add_section('global') fsid = uuid.uuid4() diff --git a/ceph_deploy/tests/test_conf.py b/ceph_deploy/tests/test_conf.py index faa3688..79796c6 100644 --- a/ceph_deploy/tests/test_conf.py +++ b/ceph_deploy/tests/test_conf.py @@ -57,3 +57,12 @@ bar__ thud quux = baz cfg = conf.parse(f) assert cfg.get('foo', 'bar_thud_quux') == 'baz' assert cfg.get('foo', 'bar thud quux') == 'baz' + +def test_write_words_underscore(): + cfg = conf.CephConf() + cfg.add_section('foo') + cfg.set('foo', 'bar thud quux', 'baz') + f = StringIO() + cfg.write(f) + f.reset() + assert f.readlines() == ['[foo]\n', 'bar_thud_quux = baz\n','\n'] -- 2.47.3