Blame SOURCES/0006-Fix-resolving-devices-with-names-that-look-like-BIOS.patch

3d02e2
From 344e624f91010b6041c22ee8a24c9305b82af969 Mon Sep 17 00:00:00 2001
3d02e2
From: Vojtech Trefny <vtrefny@redhat.com>
3d02e2
Date: Tue, 18 May 2021 12:54:02 +0200
3d02e2
Subject: [PATCH] Fix resolving devices with names that look like BIOS drive
3d02e2
 number
3d02e2
3d02e2
A RAID array named "10" will not be resolved because we try to
3d02e2
resolve it using EDD data and after this lookup fails, we don't
3d02e2
try the name.
3d02e2
3d02e2
Resolves: rhbz#1960798
3d02e2
---
3d02e2
 blivet/devicetree.py     | 18 +++++++++---------
3d02e2
 tests/devicetree_test.py |  4 ++++
3d02e2
 2 files changed, 13 insertions(+), 9 deletions(-)
3d02e2
3d02e2
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
3d02e2
index 88e9f0e5..f4ae1968 100644
3d02e2
--- a/blivet/devicetree.py
3d02e2
+++ b/blivet/devicetree.py
3d02e2
@@ -634,20 +634,20 @@ class DeviceTreeBase(object):
3d02e2
                     (label.startswith("'") and label.endswith("'"))):
3d02e2
                 label = label[1:-1]
3d02e2
             device = self.labels.get(label)
3d02e2
-        elif re.match(r'(0x)?[A-Fa-f0-9]{2}(p\d+)?$', devspec):
3d02e2
-            # BIOS drive number
3d02e2
-            (drive, _p, partnum) = devspec.partition("p")
3d02e2
-            spec = int(drive, 16)
3d02e2
-            for (edd_name, edd_number) in self.edd_dict.items():
3d02e2
-                if edd_number == spec:
3d02e2
-                    device = self.get_device_by_name(edd_name + partnum)
3d02e2
-                    break
3d02e2
         elif options and "nodev" in options.split(","):
3d02e2
             device = self.get_device_by_name(devspec)
3d02e2
             if not device:
3d02e2
                 device = self.get_device_by_path(devspec)
3d02e2
         else:
3d02e2
-            if not devspec.startswith("/dev/"):
3d02e2
+            if re.match(r'(0x)?[A-Fa-f0-9]{2}(p\d+)?$', devspec):
3d02e2
+                # BIOS drive number
3d02e2
+                (drive, _p, partnum) = devspec.partition("p")
3d02e2
+                spec = int(drive, 16)
3d02e2
+                for (edd_name, edd_number) in self.edd_dict.items():
3d02e2
+                    if edd_number == spec:
3d02e2
+                        device = self.get_device_by_name(edd_name + partnum)
3d02e2
+                        break
3d02e2
+            if not device and not devspec.startswith("/dev/"):
3d02e2
                 device = self.get_device_by_name(devspec)
3d02e2
                 if not device:
3d02e2
                     devspec = "/dev/" + devspec
3d02e2
diff --git a/tests/devicetree_test.py b/tests/devicetree_test.py
3d02e2
index 11f8469d..b033343d 100644
3d02e2
--- a/tests/devicetree_test.py
3d02e2
+++ b/tests/devicetree_test.py
3d02e2
@@ -49,6 +49,9 @@ class DeviceTreeTestCase(unittest.TestCase):
3d02e2
         dev3 = StorageDevice("sdp2", exists=True)
3d02e2
         dt._add_device(dev3)
3d02e2
 
3d02e2
+        dev4 = StorageDevice("10", exists=True)
3d02e2
+        dt._add_device(dev4)
3d02e2
+
3d02e2
         dt.edd_dict.update({"dev1": 0x81,
3d02e2
                             "dev2": 0x82})
3d02e2
 
3d02e2
@@ -62,6 +65,7 @@ class DeviceTreeTestCase(unittest.TestCase):
3d02e2
         self.assertEqual(dt.resolve_device("0x82"), dev2)
3d02e2
 
3d02e2
         self.assertEqual(dt.resolve_device(dev3.name), dev3)
3d02e2
+        self.assertEqual(dt.resolve_device(dev4.name), dev4)
3d02e2
 
3d02e2
     def test_device_name(self):
3d02e2
         # check that devicetree.names property contains all device's names
3d02e2
-- 
3d02e2
2.31.1
3d02e2