Skip to content

Commit

Permalink
Return devicename if no /dev/disk/by-id path
Browse files Browse the repository at this point in the history
If no /dev/disk/by-id symlink is found, e.g. because that path does not
exist (as it is a case in VMs), the devicename that was provided in the
first place is returned.

Signed-off-by: Alexander Graul <[email protected]>
  • Loading branch information
agraul committed Aug 24, 2018
1 parent d554981 commit 3c26439
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion srv/salt/_modules/cephdisks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions srv/salt/_modules/osd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 1 addition & 4 deletions srv/salt/_modules/proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/_modules/test_cephdisks.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,22 @@ 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
cephdisks.__salt__ = {}
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')
Expand Down

0 comments on commit 3c26439

Please sign in to comment.