Ignore pyudev errors about device number

Pyudev is used to return extra data about a device
using the udev interface.

Sometimes that lookup doesn't quite work, like on
md devices after restarting them. As such, we will
now tollerate the failure and continue the process
as before.

Change-Id: Ibbc1759fe2cd3d7d09019b4e80d3c61d54c844dd
Story: 2007281
Task: 38726
(cherry picked from commit c1da514645)
This commit is contained in:
Julia Kreger
2020-02-10 14:28:02 -08:00
committed by Riccardo Pittau
parent 205f89a944
commit 7e4c2432c4
2 changed files with 10 additions and 1 deletions

View File

@@ -371,6 +371,11 @@ def list_all_block_devices(block_type='disk',
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 = {} extra = {}
except pyudev.DeviceNotFoundByNumberError as e:
LOG.warning("Device %(dev)s is not supported by pyudev, "
"skipping... Error: %(error)s",
{'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

View File

@@ -1629,7 +1629,11 @@ class TestGenericHardwareManager(base.IronicAgentTest):
mock_listdir.return_value = [os.path.basename(x) mock_listdir.return_value = [os.path.basename(x)
for x in sorted(by_path_map)] for x in sorted(by_path_map)]
mocked_execute.return_value = (BLK_DEVICE_TEMPLATE, '') mocked_execute.return_value = (BLK_DEVICE_TEMPLATE, '')
mocked_udev.side_effect = pyudev.DeviceNotFoundByFileError() mocked_udev.side_effect = [pyudev.DeviceNotFoundByFileError(),
pyudev.DeviceNotFoundByNumberError('block',
1234),
pyudev.DeviceNotFoundByFileError(),
pyudev.DeviceNotFoundByFileError()]
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 = [