From c1da514645be26a27177f88dad5dba3c76513909 Mon Sep 17 00:00:00 2001
From: Julia Kreger <juliaashleykreger@gmail.com>
Date: Mon, 10 Feb 2020 14:28:02 -0800
Subject: [PATCH] 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
---
 ironic_python_agent/hardware.py                 | 5 +++++
 ironic_python_agent/tests/unit/test_hardware.py | 6 +++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index b87f1a04d..48104f389 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -371,6 +371,11 @@ def list_all_block_devices(block_type='disk',
             LOG.warning("Device %(dev)s is inaccessible, skipping... "
                         "Error: %(error)s", {'dev': name, 'error': e})
             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:
             # TODO(lucasagomes): Since lsblk only supports
             # returning the short serial we are using
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index 5c1bf753d..63fa0caf0 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -1666,7 +1666,11 @@ class TestGenericHardwareManager(base.IronicAgentTest):
         mock_listdir.return_value = [os.path.basename(x)
                                      for x in sorted(by_path_map)]
         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'
         devices = hardware.list_all_block_devices()
         expected_devices = [