Skip to content

Commit 69e2254

Browse files
committed
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
1 parent 9dca977 commit 69e2254

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

ironic_python_agent/hardware.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -638,26 +638,34 @@ def _is_known_device(existing, new_device_name):
638638

639639
name = os.path.join('/dev', device['KNAME'])
640640

641+
extra = {}
641642
try:
642643
udev = pyudev.Devices.from_device_file(context, name)
643644
except pyudev.DeviceNotFoundByFileError as e:
644645
LOG.warning("Device %(dev)s is inaccessible, skipping... "
645646
"Error: %(error)s", {'dev': name, 'error': e})
646-
extra = {}
647647
except pyudev.DeviceNotFoundByNumberError as e:
648648
LOG.warning("Device %(dev)s is not supported by pyudev, "
649649
"skipping... Error: %(error)s",
650650
{'dev': name, 'error': e})
651-
extra = {}
652651
else:
653652
# TODO(lucasagomes): Since lsblk only supports
654653
# returning the short serial we are using
655-
# ID_SERIAL_SHORT here to keep compatibility with the
654+
# ID_SERIAL_SHORT first to keep compatibility with the
656655
# bash deploy ramdisk
657-
extra = {key: udev.get('ID_%s' % udev_key) for key, udev_key in
658-
[('wwn', 'WWN'), ('serial', 'SERIAL_SHORT'),
659-
('wwn_with_extension', 'WWN_WITH_EXTENSION'),
660-
('wwn_vendor_extension', 'WWN_VENDOR_EXTENSION')]}
656+
for key, udev_key in [
657+
('serial', 'SERIAL_SHORT'),
658+
('serial', 'SERIAL'),
659+
('wwn', 'WWN'),
660+
('wwn_with_extension', 'WWN_WITH_EXTENSION'),
661+
('wwn_vendor_extension', 'WWN_VENDOR_EXTENSION')
662+
]:
663+
if key in extra:
664+
continue
665+
value = (udev.get(f'ID_{udev_key}')
666+
or udev.get(f'DM_{udev_key}')) # devicemapper
667+
if value:
668+
extra[key] = value
661669

662670
# NOTE(lucasagomes): Newer versions of the lsblk tool supports
663671
# HCTL as a parameter but let's get it from sysfs to avoid breaking

ironic_python_agent/tests/unit/test_hardware.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,13 +1589,16 @@ def test_list_all_block_device_with_udev(self, mocked_execute, mocked_udev,
15891589
('', ''),
15901590
]
15911591

1592-
mocked_mpath.return_value = False
1593-
mocked_udev.side_effect = iter([
1592+
mocked_mpath.return_value = True
1593+
mocked_udev.side_effect = [
15941594
{'ID_WWN': 'wwn%d' % i, 'ID_SERIAL_SHORT': 'serial%d' % i,
1595+
'ID_SERIAL': 'do not use me',
15951596
'ID_WWN_WITH_EXTENSION': 'wwn-ext%d' % i,
15961597
'ID_WWN_VENDOR_EXTENSION': 'wwn-vendor-ext%d' % i}
1597-
for i in range(5)
1598-
])
1598+
for i in range(3)
1599+
] + [
1600+
{'DM_WWN': 'wwn3', 'DM_SERIAL': 'serial3'},
1601+
]
15991602
mocked_dev_vendor.return_value = 'Super Vendor'
16001603
devices = hardware.list_all_block_devices()
16011604
expected_devices = [
@@ -1629,19 +1632,19 @@ def test_list_all_block_device_with_udev(self, mocked_execute, mocked_udev,
16291632
wwn_vendor_extension='wwn-vendor-ext2',
16301633
serial='serial2',
16311634
hctl='1:0:0:0'),
1632-
hardware.BlockDevice(name='/dev/sdd',
1635+
hardware.BlockDevice(name='/dev/dm-0',
16331636
model='NWD-BLP4-1600',
16341637
size=1765517033472,
16351638
rotational=False,
16361639
vendor='Super Vendor',
16371640
wwn='wwn3',
1638-
wwn_with_extension='wwn-ext3',
1639-
wwn_vendor_extension='wwn-vendor-ext3',
1641+
wwn_with_extension=None,
1642+
wwn_vendor_extension=None,
16401643
serial='serial3',
16411644
hctl='1:0:0:0')
16421645
]
16431646

1644-
self.assertEqual(4, len(expected_devices))
1647+
self.assertEqual(4, len(devices))
16451648
for expected, device in zip(expected_devices, devices):
16461649
# Compare all attrs of the objects
16471650
for attr in ['name', 'model', 'size', 'rotational',
@@ -1650,7 +1653,7 @@ def test_list_all_block_device_with_udev(self, mocked_execute, mocked_udev,
16501653
self.assertEqual(getattr(expected, attr),
16511654
getattr(device, attr))
16521655
expected_calls = [mock.call('/sys/block/%s/device/scsi_device' % dev)
1653-
for dev in ('sda', 'sdb', 'sdc', 'sdd')]
1656+
for dev in ('sda', 'sdb', 'sdc', 'dm-0')]
16541657
mocked_listdir.assert_has_calls(expected_calls)
16551658
mocked_mpath.assert_called_once_with()
16561659

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes discovering WWN/serial numbers for devicemapper devices.

0 commit comments

Comments
 (0)