neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

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

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