]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume tests verify _map_dev_paths mappings
authorAlfredo Deza <adeza@redhat.com>
Thu, 3 May 2018 16:40:17 +0000 (12:40 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 4 May 2018 17:22:51 +0000 (13:22 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/tests/util/test_disk.py

index b81db81bc95bad949554fbe7430c715e5799d59b..625116b44b404618e9a40aecc2e3e0df552dc72c 100644 (file)
@@ -1,3 +1,4 @@
+import os
 from ceph_volume.util import disk
 
 
@@ -39,3 +40,47 @@ class TestDeviceFamily(object):
         result = disk.device_family('sdaa5')
         for parsed in result:
             assert parsed['NAME'] in names
+
+
+class TestMapDevPaths(object):
+
+    def test_errors_return_empty_mapping(self, tmpdir):
+        bad_dir = os.path.join(str(tmpdir), 'nonexisting')
+        assert disk._map_dev_paths(bad_dir) == {}
+
+    def test_base_name_and_abspath(self, tmpfile):
+        sda_path = tmpfile(name='sda', contents='')
+        directory = os.path.dirname(sda_path)
+        result = disk._map_dev_paths(directory)
+        assert result.keys() == ['sda']
+        assert result['sda'] == sda_path
+
+    def test_abspath_included(self, tmpfile):
+        sda_path = tmpfile(name='sda', contents='')
+        directory = os.path.dirname(sda_path)
+        result = disk._map_dev_paths(directory, include_abspath=True)
+        assert sorted(result.keys()) == sorted(['sda', sda_path])
+        assert result['sda'] == sda_path
+        assert result[sda_path] == 'sda'
+
+    def test_realpath_included(self, tmpfile):
+        sda_path = tmpfile(name='sda', contents='')
+        directory = os.path.dirname(sda_path)
+        dm_path = os.path.join(directory, 'dm-0')
+        os.symlink(sda_path, os.path.join(directory, 'dm-0'))
+        result = disk._map_dev_paths(directory, include_realpath=True)
+        assert sorted(result.keys()) == sorted(['sda', 'dm-0'])
+        assert result['sda'] == dm_path
+        assert result['dm-0'] == dm_path
+
+    def test_absolute_and_realpath_included(self, tmpfile):
+        dm_path = tmpfile(name='dm-0', contents='')
+        directory = os.path.dirname(dm_path)
+        sda_path = os.path.join(directory, 'sda')
+        os.symlink(sda_path, os.path.join(directory, 'sda'))
+        result = disk._map_dev_paths(directory, include_realpath=True, include_abspath=True)
+        assert sorted(result.keys()) == sorted([dm_path, sda_path, 'sda', 'dm-0'])
+        assert result['sda'] == sda_path
+        assert result['dm-0'] == dm_path
+        assert result[sda_path] == sda_path
+        assert result[dm_path] == 'dm-0'