]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-daemon: py2: tolerate whitespace before config key name 32098/head
authorSage Weil <sage@redhat.com>
Fri, 6 Dec 2019 21:43:23 +0000 (15:43 -0600)
committerSage Weil <sage@redhat.com>
Mon, 9 Dec 2019 13:15:13 +0000 (07:15 -0600)
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>
qa/standalone/test_ceph_daemon.sh
src/ceph-daemon/ceph-daemon
test_ceph_daemon.sh

index cf5760c8a6bbb7d966b3b1437865e41b6b042e9e..63492296455f948b33fa13a72964754acb02d1a7 100755 (executable)
@@ -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 \
index 7edfccc4632b38de36b3e386110d10be953ed2ec..aeb77bab9f5b0f9d0e11e8d5656f24a238e01c20 100755 (executable)
@@ -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
index e2608a0085d02131c920dea1d5130dc297a86ee2..cf4113ba595849a8a60cf6e993a983d1c80e513b 100755 (executable)
@@ -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 \