diff --git a/srv/salt/_modules/cephdisks.py b/srv/salt/_modules/cephdisks.py index 11f41098d..fbde054d5 100644 --- a/srv/salt/_modules/cephdisks.py +++ b/srv/salt/_modules/cephdisks.py @@ -517,7 +517,7 @@ def device_(devicename, pathname=None, match=None): _devices = _stdout.split() index = _prefer_underscores(_devices) return _devices[index] - return "" + return devicename def _match_setting(match): diff --git a/srv/salt/_modules/osd.py b/srv/salt/_modules/osd.py index a409dfe42..163adb4da 100644 --- a/srv/salt/_modules/osd.py +++ b/srv/salt/_modules/osd.py @@ -1816,18 +1816,18 @@ def osd_fsid(self, osd_id): log.error("file {} is missing".format(filename)) return None - # pylint: disable=no-self-use - def _uuid_device(self, device, pathname="/dev/disk/by-id"): + # pylint: disable=no-self-use, no-else-return + def _uuid_device(self, device): """ Return the uuid device, prefer the most descriptive """ if os.path.exists(device): - if os.path.exists(pathname): - devicename = __salt__['cephdisks.device'](device) - if devicename: - return devicename + devicename = __salt__['cephdisks.device'](device) + # if the devicename and device are the same, cephdisks.device did not find any symlinks + if devicename != device: + return devicename + else: return readlink(device) - return readlink(device) return None diff --git a/srv/salt/_modules/proposal.py b/srv/salt/_modules/proposal.py index bf2062d23..7ac60b9d7 100644 --- a/srv/salt/_modules/proposal.py +++ b/srv/salt/_modules/proposal.py @@ -236,10 +236,7 @@ def _device(drive): """ Default to Device File value. Prefer most descriptive. """ - devicename = __salt__['cephdisks.device'](drive['Device File']) - if devicename: - return devicename - return drive['Device File'] + return __salt__['cephdisks.device'](drive['Device File']) def generate(**kwargs): diff --git a/tests/unit/_modules/test_cephdisks.py b/tests/unit/_modules/test_cephdisks.py index a94e3b5de..147491096 100644 --- a/tests/unit/_modules/test_cephdisks.py +++ b/tests/unit/_modules/test_cephdisks.py @@ -420,14 +420,14 @@ def test_device_matches(self, pu, ms, ps): pu.return_value = -1 cephdisks.__salt__ = {} cephdisks.__salt__['helper.run'] = mock.Mock() - cephdisks.__salt__['helper.run'].return_value = (0, '/dev/sda', "") + cephdisks.__salt__['helper.run'].return_value = (0, '/dev/disk/by-id/sda', "") ret = cephdisks.device_('/dev/sda') - assert ret == '/dev/sda' + assert ret == '/dev/disk/by-id/sda' @mock.patch('srv.salt._modules.cephdisks._pathname_setting') @mock.patch('srv.salt._modules.cephdisks._match_setting') @mock.patch('srv.salt._modules.cephdisks._prefer_underscores') - def test_device_no_match(self, pu, ms, ps): + def test_device_returns_input_if_no_match(self, pu, ms, ps): ps.return_value = '/dev/disk/by-id' ms.return_value = '-name ata* -o -name scsi* -o -name nvme*' pu.return_value = -1 @@ -435,7 +435,7 @@ def test_device_no_match(self, pu, ms, ps): cephdisks.__salt__['helper.run'] = mock.Mock() cephdisks.__salt__['helper.run'].return_value = (0, "", "") ret = cephdisks.device_('/dev/sda') - assert ret == "" + assert ret == "/dev/sda" def test_match_setting_arg(self): ret = cephdisks._match_setting('custom')