Fix discovering WWN/serial for devicemapper devices
UDev prefix is DM_ not ID_ for them. On top of that, they don't have short serials (or at least don't always have). Change-Id: I5b6075fbff72201a2fd620f789978acceafc417b
This commit is contained in:
parent
9dca97736f
commit
69e2254503
@ -638,26 +638,34 @@ def list_all_block_devices(block_type='disk',
|
|||||||
|
|
||||||
name = os.path.join('/dev', device['KNAME'])
|
name = os.path.join('/dev', device['KNAME'])
|
||||||
|
|
||||||
|
extra = {}
|
||||||
try:
|
try:
|
||||||
udev = pyudev.Devices.from_device_file(context, name)
|
udev = pyudev.Devices.from_device_file(context, name)
|
||||||
except pyudev.DeviceNotFoundByFileError as e:
|
except pyudev.DeviceNotFoundByFileError as e:
|
||||||
LOG.warning("Device %(dev)s is inaccessible, skipping... "
|
LOG.warning("Device %(dev)s is inaccessible, skipping... "
|
||||||
"Error: %(error)s", {'dev': name, 'error': e})
|
"Error: %(error)s", {'dev': name, 'error': e})
|
||||||
extra = {}
|
|
||||||
except pyudev.DeviceNotFoundByNumberError as e:
|
except pyudev.DeviceNotFoundByNumberError as e:
|
||||||
LOG.warning("Device %(dev)s is not supported by pyudev, "
|
LOG.warning("Device %(dev)s is not supported by pyudev, "
|
||||||
"skipping... Error: %(error)s",
|
"skipping... Error: %(error)s",
|
||||||
{'dev': name, 'error': e})
|
{'dev': name, 'error': e})
|
||||||
extra = {}
|
|
||||||
else:
|
else:
|
||||||
# TODO(lucasagomes): Since lsblk only supports
|
# TODO(lucasagomes): Since lsblk only supports
|
||||||
# returning the short serial we are using
|
# returning the short serial we are using
|
||||||
# ID_SERIAL_SHORT here to keep compatibility with the
|
# ID_SERIAL_SHORT first to keep compatibility with the
|
||||||
# bash deploy ramdisk
|
# bash deploy ramdisk
|
||||||
extra = {key: udev.get('ID_%s' % udev_key) for key, udev_key in
|
for key, udev_key in [
|
||||||
[('wwn', 'WWN'), ('serial', 'SERIAL_SHORT'),
|
('serial', 'SERIAL_SHORT'),
|
||||||
('wwn_with_extension', 'WWN_WITH_EXTENSION'),
|
('serial', 'SERIAL'),
|
||||||
('wwn_vendor_extension', 'WWN_VENDOR_EXTENSION')]}
|
('wwn', 'WWN'),
|
||||||
|
('wwn_with_extension', 'WWN_WITH_EXTENSION'),
|
||||||
|
('wwn_vendor_extension', 'WWN_VENDOR_EXTENSION')
|
||||||
|
]:
|
||||||
|
if key in extra:
|
||||||
|
continue
|
||||||
|
value = (udev.get(f'ID_{udev_key}')
|
||||||
|
or udev.get(f'DM_{udev_key}')) # devicemapper
|
||||||
|
if value:
|
||||||
|
extra[key] = value
|
||||||
|
|
||||||
# NOTE(lucasagomes): Newer versions of the lsblk tool supports
|
# NOTE(lucasagomes): Newer versions of the lsblk tool supports
|
||||||
# HCTL as a parameter but let's get it from sysfs to avoid breaking
|
# HCTL as a parameter but let's get it from sysfs to avoid breaking
|
||||||
|
@ -1589,13 +1589,16 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
|||||||
('', ''),
|
('', ''),
|
||||||
]
|
]
|
||||||
|
|
||||||
mocked_mpath.return_value = False
|
mocked_mpath.return_value = True
|
||||||
mocked_udev.side_effect = iter([
|
mocked_udev.side_effect = [
|
||||||
{'ID_WWN': 'wwn%d' % i, 'ID_SERIAL_SHORT': 'serial%d' % i,
|
{'ID_WWN': 'wwn%d' % i, 'ID_SERIAL_SHORT': 'serial%d' % i,
|
||||||
|
'ID_SERIAL': 'do not use me',
|
||||||
'ID_WWN_WITH_EXTENSION': 'wwn-ext%d' % i,
|
'ID_WWN_WITH_EXTENSION': 'wwn-ext%d' % i,
|
||||||
'ID_WWN_VENDOR_EXTENSION': 'wwn-vendor-ext%d' % i}
|
'ID_WWN_VENDOR_EXTENSION': 'wwn-vendor-ext%d' % i}
|
||||||
for i in range(5)
|
for i in range(3)
|
||||||
])
|
] + [
|
||||||
|
{'DM_WWN': 'wwn3', 'DM_SERIAL': 'serial3'},
|
||||||
|
]
|
||||||
mocked_dev_vendor.return_value = 'Super Vendor'
|
mocked_dev_vendor.return_value = 'Super Vendor'
|
||||||
devices = hardware.list_all_block_devices()
|
devices = hardware.list_all_block_devices()
|
||||||
expected_devices = [
|
expected_devices = [
|
||||||
@ -1629,19 +1632,19 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
|||||||
wwn_vendor_extension='wwn-vendor-ext2',
|
wwn_vendor_extension='wwn-vendor-ext2',
|
||||||
serial='serial2',
|
serial='serial2',
|
||||||
hctl='1:0:0:0'),
|
hctl='1:0:0:0'),
|
||||||
hardware.BlockDevice(name='/dev/sdd',
|
hardware.BlockDevice(name='/dev/dm-0',
|
||||||
model='NWD-BLP4-1600',
|
model='NWD-BLP4-1600',
|
||||||
size=1765517033472,
|
size=1765517033472,
|
||||||
rotational=False,
|
rotational=False,
|
||||||
vendor='Super Vendor',
|
vendor='Super Vendor',
|
||||||
wwn='wwn3',
|
wwn='wwn3',
|
||||||
wwn_with_extension='wwn-ext3',
|
wwn_with_extension=None,
|
||||||
wwn_vendor_extension='wwn-vendor-ext3',
|
wwn_vendor_extension=None,
|
||||||
serial='serial3',
|
serial='serial3',
|
||||||
hctl='1:0:0:0')
|
hctl='1:0:0:0')
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertEqual(4, len(expected_devices))
|
self.assertEqual(4, len(devices))
|
||||||
for expected, device in zip(expected_devices, devices):
|
for expected, device in zip(expected_devices, devices):
|
||||||
# Compare all attrs of the objects
|
# Compare all attrs of the objects
|
||||||
for attr in ['name', 'model', 'size', 'rotational',
|
for attr in ['name', 'model', 'size', 'rotational',
|
||||||
@ -1650,7 +1653,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
|||||||
self.assertEqual(getattr(expected, attr),
|
self.assertEqual(getattr(expected, attr),
|
||||||
getattr(device, attr))
|
getattr(device, attr))
|
||||||
expected_calls = [mock.call('/sys/block/%s/device/scsi_device' % dev)
|
expected_calls = [mock.call('/sys/block/%s/device/scsi_device' % dev)
|
||||||
for dev in ('sda', 'sdb', 'sdc', 'sdd')]
|
for dev in ('sda', 'sdb', 'sdc', 'dm-0')]
|
||||||
mocked_listdir.assert_has_calls(expected_calls)
|
mocked_listdir.assert_has_calls(expected_calls)
|
||||||
mocked_mpath.assert_called_once_with()
|
mocked_mpath.assert_called_once_with()
|
||||||
|
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixes discovering WWN/serial numbers for devicemapper devices.
|
Loading…
Reference in New Issue
Block a user