From 0752a6f613abcf874efed2580303ff695fa099f0 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 3 May 2018 12:40:17 -0400 Subject: [PATCH] ceph-volume tests verify _map_dev_paths mappings Signed-off-by: Alfredo Deza (cherry picked from commit 2c4d46955e8d7f52b090cd8b5b5561a2dba443e5) --- .../ceph_volume/tests/util/test_disk.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/ceph-volume/ceph_volume/tests/util/test_disk.py b/src/ceph-volume/ceph_volume/tests/util/test_disk.py index b81db81bc95ba..625116b44b404 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_disk.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_disk.py @@ -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' -- 2.39.5