]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume trim tabbed/whitespaced configuration files when loading them
authorAlfredo Deza <adeza@redhat.com>
Thu, 30 Nov 2017 13:58:04 +0000 (08:58 -0500)
committerAlfredo Deza <adeza@redhat.com>
Thu, 30 Nov 2017 13:58:04 +0000 (08:58 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/configuration.py

index eda58f09b95c145944b1506b9ce5eaaf538b45e2..e4f9bde2fed0e029e0ff51470e0ec235d19dced0 100644 (file)
@@ -2,6 +2,7 @@ try:
     import configparser
 except ImportError:
     import ConfigParser as configparser
+import contextlib
 import logging
 import os
 import re
@@ -31,14 +32,20 @@ class _TrimIndentFile(object):
 
 
 def load(abspath=None):
+    if not os.path.exists(abspath):
+        raise exceptions.ConfigurationError(abspath=abspath)
+
     parser = Conf()
     try:
-        parser.read_path(abspath)
-        return parser
+        ceph_file = open(abspath)
+        trimmed_conf = _TrimIndentFile(ceph_file)
+        with contextlib.closing(ceph_file):
+            parser.readfp(trimmed_conf)
+            return parser
     except configparser.ParsingError as error:
-        terminal.error('Unable to read configuration file: %s' % abspath)
-        terminal.error(str(error))
         logger.exception('Unable to parse INI-style file: %s' % abspath)
+        terminal.error(str(error))
+        raise RuntimeError('Unable to read configuration file: %s' % abspath)
 
 
 class Conf(configparser.SafeConfigParser):
@@ -52,9 +59,6 @@ class Conf(configparser.SafeConfigParser):
         return self.read(path)
 
     def is_valid(self):
-        if not os.path.exists(self.path):
-            raise exceptions.ConfigurationError(abspath=self.path)
-
         try:
             self.get('global', 'fsid')
         except (configparser.NoSectionError, configparser.NoOptionError):