ceph-daemon: py2: tolerate whitespace before config key name

The py2 ConfigParser doesn't like whitespace before the config option
name.  (The py3 version doesn't care.)  Filter it out before parsing.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2019-12-06 15:43:23 -06:00
parent 9d4e7e2f27
commit 3036d11c60
3 changed files with 18 additions and 7 deletions

View File

@ -100,7 +100,7 @@ KEYRING=`mktemp -p $TMPDIR`
IP=127.0.0.1
cat <<EOF > $ORIG_CONFIG
[global]
log to file = true
log to file = true
EOF
$SUDO $CEPH_DAEMON --image $IMAGE_MASTER bootstrap \
--mon-id a \

View File

@ -45,6 +45,7 @@ import json
import logging
import os
import random
import re
import select
import shutil
import socket
@ -180,6 +181,19 @@ def call_throws(command, **kwargs):
##################################
def read_config(fn):
# type: (Optional[str]) -> ConfigParser
# bend over backwards here because py2's ConfigParser doesn't like
# whitespace before config option names (e.g., '\n foo = bar\n').
# Yeesh!
cp = ConfigParser()
if fn:
with open(fn, 'r') as f:
raw_conf = f.read()
nice_conf = re.sub('\n(\s)+', '\n', raw_conf)
cp.readfp(StringIO(nice_conf))
return cp
def pathify(p):
# type: (str) -> str
if not p.startswith('/'):
@ -392,8 +406,7 @@ def get_legacy_config_fsid(cluster, legacy_dir=None):
if legacy_dir is not None:
config_file = os.path.abspath(legacy_dir + config_file)
config = ConfigParser()
config.read(config_file)
config = read_config(config_file)
if config.has_section('global') and config.has_option('global', 'fsid'):
return config.get('global', 'fsid')
@ -985,9 +998,7 @@ def command_bootstrap():
logging.info('Cluster fsid: %s' % fsid)
# config
cp = ConfigParser()
if args.config:
cp.read(args.config)
cp = read_config(args.config)
if args.mon_ip:
addr_arg = '[v2:%s:3300,v1:%s:6789]' % (args.mon_ip, args.mon_ip)
mon_ip = args.mon_ip

View File

@ -27,7 +27,7 @@ rm -f $OSD_IMAGE_NAME
cat <<EOF > c
[global]
log to file = true
log to file = true
EOF
$CEPH_DAEMON $A \