import re
from ceph_volume import terminal, conf
from ceph_volume import exceptions
+from sys import version_info as sys_version_info
+
+if sys_version_info.major >= 3:
+ conf_parentclass = configparser.ConfigParser
+elif sys_version_info.major < 3:
+ conf_parentclass = configparser.SafeConfigParser
+else:
+ raise RuntimeError('Not expecting python version > 3 yet.')
logger = logging.getLogger(__name__)
ceph_file = open(abspath)
trimmed_conf = _TrimIndentFile(ceph_file)
with contextlib.closing(ceph_file):
- parser.readfp(trimmed_conf)
+ parser.read_conf(trimmed_conf)
conf.ceph = parser
return parser
except configparser.ParsingError as error:
raise RuntimeError('Unable to read configuration file: %s' % abspath)
-class Conf(configparser.SafeConfigParser):
+class Conf(conf_parentclass):
"""
- Subclasses from SafeConfigParser to give a few helpers for Ceph
+ Subclasses from ConfigParser to give a few helpers for Ceph
configuration.
"""
for name, val in options.items():
if isinstance(val, list):
options[name] = '\n'.join(val)
+
+ def read_conf(self, conffile):
+ if sys_version_info.major >= 3:
+ self.read_file(conffile)
+ elif sys_version_info.major < 3:
+ self.readfp(conffile)
+ else:
+ raise RuntimeError('Not expecting python version > 3 yet.')
def test_get_non_existing_list(self):
cfg = configuration.Conf()
cfg.is_valid = lambda: True
- cfg.readfp(self.conf_file)
+ cfg.read_conf(self.conf_file)
assert cfg.get_list('global', 'key') == []
def test_get_non_existing_list_get_default(self):
cfg = configuration.Conf()
cfg.is_valid = lambda: True
- cfg.readfp(self.conf_file)
+ cfg.read_conf(self.conf_file)
assert cfg.get_list('global', 'key', ['a']) == ['a']
def test_get_rid_of_comments(self):
default = 0 # this is a comment
"""))
- cfg.readfp(conf_file)
+ cfg.read_conf(conf_file)
assert cfg.get_list('foo', 'default') == ['0']
def test_gets_split_on_commas(self):
default = 0,1,2,3 # this is a comment
"""))
- cfg.readfp(conf_file)
+ cfg.read_conf(conf_file)
assert cfg.get_list('foo', 'default') == ['0', '1', '2', '3']
def test_spaces_and_tabs_are_ignored(self):
default = 0, 1, 2 ,3 # this is a comment
"""))
- cfg.readfp(conf_file)
+ cfg.read_conf(conf_file)
assert cfg.get_list('foo', 'default') == ['0', '1', '2', '3']