From 89c9183aad044f2811dafa7e072a1db2f3412d31 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 30 Nov 2017 08:58:04 -0500 Subject: [PATCH] ceph-volume trim tabbed/whitespaced configuration files when loading them Signed-off-by: Alfredo Deza (cherry picked from commit 9706e8cc9eb53d0f01fc78978625c1d18bf4667e) --- src/ceph-volume/ceph_volume/configuration.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ceph-volume/ceph_volume/configuration.py b/src/ceph-volume/ceph_volume/configuration.py index eda58f09b95c..e4f9bde2fed0 100644 --- a/src/ceph-volume/ceph_volume/configuration.py +++ b/src/ceph-volume/ceph_volume/configuration.py @@ -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): -- 2.47.3