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

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