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)
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
from . import exc
from .cliutil import priority
+from .conf import CephConf
from .util import arg_validators
from .misc import mon_hosts
def new(args):
LOG.debug('Creating new cluster named %s', args.cluster)
- cfg = ConfigParser.RawConfigParser()
+ cfg = CephConf()
cfg.add_section('global')
fsid = uuid.uuid4()
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']