]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: fix warnings raised by pytest
authorRishabh Dave <ridave@redhat.com>
Tue, 17 Sep 2019 08:10:55 +0000 (13:40 +0530)
committerJakub Sobczak <ksobczak16@gmail.com>
Tue, 1 Oct 2019 19:16:26 +0000 (21:16 +0200)
Warnings are related to configparser. Update tests too.

Fixes: https://tracker.ceph.com/issues/41907
Signed-off-by: Rishabh Dave <ridave@redhat.com>
(cherry picked from commit 31a0c7e77bf5d0193e90e6693b424ca5305b47cc)

src/ceph-volume/ceph_volume/configuration.py
src/ceph-volume/ceph_volume/tests/test_configuration.py

index 6379ef67a7d82523ad52d6afdd12f48e25b54e9e..a9b908e1c05826576603a5683456a7428c5b53d7 100644 (file)
@@ -8,6 +8,14 @@ import os
 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__)
@@ -50,7 +58,7 @@ def load(abspath=None):
         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:
@@ -59,9 +67,9 @@ def load(abspath=None):
         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.
     """
 
@@ -215,3 +223,11 @@ class Conf(configparser.SafeConfigParser):
             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.')
index 2e26ead7c82ed7b1979cd4dd30ff552a8088020f..9af6cd9bedf81114b6fd6d1de94bc710606e1d2e 100644 (file)
@@ -28,13 +28,13 @@ class TestConf(object):
     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):
@@ -45,7 +45,7 @@ class TestConf(object):
         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):
@@ -56,7 +56,7 @@ class TestConf(object):
         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):
@@ -67,7 +67,7 @@ class TestConf(object):
         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']