]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/ceph-volume/ceph_volume/tests/test_configuration.py
update sources to v12.2.3
[ceph.git] / ceph / src / ceph-volume / ceph_volume / tests / test_configuration.py
index 5ef7fae47f8bcc2cca3afa851b4372d0528cdcf0..0009532c44efb23e6030462b00b720fd2fe1e1a2 100644 (file)
@@ -7,6 +7,15 @@ from textwrap import dedent
 import pytest
 from ceph_volume import configuration, exceptions
 
+tabbed_conf = """
+[global]
+            default = 0
+            other_h = 1 # comment
+            other_c = 1 ; comment
+            colon = ;
+            hash = #
+"""
+
 
 class TestConf(object):
 
@@ -64,6 +73,27 @@ class TestConf(object):
 
 class TestLoad(object):
 
+    def test_load_from_path(self, tmpdir):
+        conf_path = os.path.join(str(tmpdir), 'ceph.conf')
+        with open(conf_path, 'w') as conf:
+            conf.write(tabbed_conf)
+        result = configuration.load(conf_path)
+        assert result.get('global', 'default') == '0'
+
+    def test_load_with_colon_comments(self, tmpdir):
+        conf_path = os.path.join(str(tmpdir), 'ceph.conf')
+        with open(conf_path, 'w') as conf:
+            conf.write(tabbed_conf)
+        result = configuration.load(conf_path)
+        assert result.get('global', 'other_c') == '1'
+
+    def test_load_with_hash_comments(self, tmpdir):
+        conf_path = os.path.join(str(tmpdir), 'ceph.conf')
+        with open(conf_path, 'w') as conf:
+            conf.write(tabbed_conf)
+        result = configuration.load(conf_path)
+        assert result.get('global', 'other_h') == '1'
+
     def test_path_does_not_exist(self):
         with pytest.raises(exceptions.ConfigurationError):
             conf = configuration.load('/path/does/not/exist/ceph.con')
@@ -73,7 +103,15 @@ class TestLoad(object):
         ceph_conf = os.path.join(str(tmpdir), 'ceph.conf')
         with open(ceph_conf, 'w') as config:
             config.write(']broken] config\n[[')
-        configuration.load(ceph_conf)
+        with pytest.raises(RuntimeError):
+            configuration.load(ceph_conf)
         stdout, stderr = capsys.readouterr()
-        assert 'Unable to read configuration file' in stdout
         assert 'File contains no section headers' in stdout
+
+    @pytest.mark.parametrize('commented', ['colon','hash'])
+    def test_coment_as_a_value(self, tmpdir, commented):
+        conf_path = os.path.join(str(tmpdir), 'ceph.conf')
+        with open(conf_path, 'w') as conf:
+            conf.write(tabbed_conf)
+        result = configuration.load(conf_path)
+        assert result.get('global', commented) == ''