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]
|
iscsi-initiator-utils [platform:rpm !platform:suse]
|
||||||
open-iscsi [platform:suse platform:dpkg]
|
open-iscsi [platform:suse platform:dpkg]
|
||||||
|
lsscsi
|
||||||
|
|
||||||
# Binary dependencies for PDF doc generation
|
# Binary dependencies for PDF doc generation
|
||||||
fonts-liberation [doc platform:dpkg]
|
fonts-liberation [doc platform:dpkg]
|
||||||
|
|
|
@ -101,22 +101,30 @@ class LinuxSCSI(executor.Executor):
|
||||||
raise exception.VolumePathNotRemoved(volume_path=exist)
|
raise exception.VolumePathNotRemoved(volume_path=exist)
|
||||||
|
|
||||||
def get_device_info(self, device):
|
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,
|
dev_info = {'device': device, 'host': None,
|
||||||
'channel': None, 'id': None, 'lun': 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:
|
if out:
|
||||||
line = out.strip()
|
for line in out.strip().split('\n'):
|
||||||
line = line.replace(device + ": ", "")
|
# The last column of lsscsi is device name
|
||||||
info = line.split(" ")
|
if line.split()[-1] == device:
|
||||||
|
# The first column of lsscsi is [H:C:T:L]
|
||||||
for item in info:
|
hctl_info = line.split()[0].strip('[]').split(':')
|
||||||
if '=' in item:
|
dev_info['host'] = hctl_info[0]
|
||||||
pair = item.split('=')
|
dev_info['channel'] = hctl_info[1]
|
||||||
dev_info[pair[0]] = pair[1]
|
dev_info['id'] = hctl_info[2]
|
||||||
elif 'scsi' in item:
|
dev_info['lun'] = hctl_info[3]
|
||||||
dev_info['host'] = item.replace('scsi', '')
|
break
|
||||||
|
|
||||||
|
LOG.debug('dev_info=%s', str(dev_info))
|
||||||
return dev_info
|
return dev_info
|
||||||
|
|
||||||
def get_sysfs_wwn(self, device_names):
|
def get_sysfs_wwn(self, device_names):
|
||||||
|
|
|
@ -848,14 +848,12 @@ loop0 0"""
|
||||||
'multipathd', 'show', 'status', run_as_root=True, root_helper=None)
|
'multipathd', 'show', 'status', run_as_root=True, root_helper=None)
|
||||||
|
|
||||||
def test_get_device_info(self):
|
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:
|
with mock.patch.object(self.linuxscsi, '_execute') as exec_mock:
|
||||||
exec_mock.return_value = (ret, "")
|
exec_mock.return_value = (ret, "")
|
||||||
info = self.linuxscsi.get_device_info('/dev/adevice')
|
info = self.linuxscsi.get_device_info('/dev/adevice')
|
||||||
|
|
||||||
exec_mock.assert_called_once_with('sg_scan', '/dev/adevice',
|
exec_mock.assert_called_once_with('lsscsi')
|
||||||
root_helper=None,
|
|
||||||
run_as_root=True)
|
|
||||||
self.assertEqual(info, {'channel': '1',
|
self.assertEqual(info, {'channel': '1',
|
||||||
'device': '/dev/adevice',
|
'device': '/dev/adevice',
|
||||||
'host': '1',
|
'host': '1',
|
||||||
|
|
Loading…
Reference in New Issue