Merge "Replace sg_scan with lsscsi to get '[H:C:T:L]'"
This commit is contained in:
commit
5208e7bdc4
|
@ -17,6 +17,7 @@ libopenssl-devel [platform:suse !platform:rpm]
|
|||
|
||||
iscsi-initiator-utils [platform:rpm !platform:suse]
|
||||
open-iscsi [platform:suse platform:dpkg]
|
||||
lsscsi
|
||||
|
||||
# Binary dependencies for PDF doc generation
|
||||
fonts-liberation [doc platform:dpkg]
|
||||
|
|
|
@ -101,22 +101,30 @@ class LinuxSCSI(executor.Executor):
|
|||
raise exception.VolumePathNotRemoved(volume_path=exist)
|
||||
|
||||
def get_device_info(self, device):
|
||||
(out, _err) = self._execute('sg_scan', device, run_as_root=True,
|
||||
root_helper=self._root_helper)
|
||||
dev_info = {'device': device, 'host': None,
|
||||
'channel': None, 'id': None, 'lun': None}
|
||||
# The input argument 'device' can be of 2 types:
|
||||
# (a) /dev/disk/by-path/XXX which is a symlink to /dev/sdX device
|
||||
# (b) /dev/sdX
|
||||
# If it's a symlink, get the /dev/sdX name first
|
||||
if os.path.islink(device):
|
||||
device = '/dev/' + os.readlink(device).split('/')[-1]
|
||||
# Else it's already a /dev/sdX device.
|
||||
# Then get it from lsscsi output
|
||||
(out, _err) = self._execute('lsscsi')
|
||||
if out:
|
||||
line = out.strip()
|
||||
line = line.replace(device + ": ", "")
|
||||
info = line.split(" ")
|
||||
|
||||
for item in info:
|
||||
if '=' in item:
|
||||
pair = item.split('=')
|
||||
dev_info[pair[0]] = pair[1]
|
||||
elif 'scsi' in item:
|
||||
dev_info['host'] = item.replace('scsi', '')
|
||||
for line in out.strip().split('\n'):
|
||||
# The last column of lsscsi is device name
|
||||
if line.split()[-1] == device:
|
||||
# The first column of lsscsi is [H:C:T:L]
|
||||
hctl_info = line.split()[0].strip('[]').split(':')
|
||||
dev_info['host'] = hctl_info[0]
|
||||
dev_info['channel'] = hctl_info[1]
|
||||
dev_info['id'] = hctl_info[2]
|
||||
dev_info['lun'] = hctl_info[3]
|
||||
break
|
||||
|
||||
LOG.debug('dev_info=%s', str(dev_info))
|
||||
return dev_info
|
||||
|
||||
def get_sysfs_wwn(self, device_names):
|
||||
|
|
|
@ -848,14 +848,12 @@ loop0 0"""
|
|||
'multipathd', 'show', 'status', run_as_root=True, root_helper=None)
|
||||
|
||||
def test_get_device_info(self):
|
||||
ret = "/dev/sg0 scsi1 channel=1 id=0 lun=0 [em]\n"
|
||||
ret = "[1:1:0:0] disk Vendor Array 0100 /dev/adevice\n"
|
||||
with mock.patch.object(self.linuxscsi, '_execute') as exec_mock:
|
||||
exec_mock.return_value = (ret, "")
|
||||
info = self.linuxscsi.get_device_info('/dev/adevice')
|
||||
|
||||
exec_mock.assert_called_once_with('sg_scan', '/dev/adevice',
|
||||
root_helper=None,
|
||||
run_as_root=True)
|
||||
exec_mock.assert_called_once_with('lsscsi')
|
||||
self.assertEqual(info, {'channel': '1',
|
||||
'device': '/dev/adevice',
|
||||
'host': '1',
|
||||
|
|
Loading…
Reference in New Issue