neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0028-Add-recognition-of-Dell-FW-RAID-to-udev-device_is_disk.patch

0b05ab
From 4e23e410bb5fcab5db931ad42a9b46af6be4fb3d Mon Sep 17 00:00:00 2001
0b05ab
From: David Lehman <dlehman@redhat.com>
0b05ab
Date: Thu, 16 Jan 2020 13:14:29 -0500
0b05ab
Subject: [PATCH 1/2] Add recognition of Dell FW RAID to udev.device_is_disk.
0b05ab
0b05ab
Resolves: rhbz#1758102
0b05ab
---
0b05ab
 blivet/udev.py     | 16 +++++++++++++++-
0b05ab
 tests/udev_test.py | 42 ++++++++++++++++++++++++++++++++++++++++++
0b05ab
 2 files changed, 57 insertions(+), 1 deletion(-)
0b05ab
0b05ab
diff --git a/blivet/udev.py b/blivet/udev.py
0b05ab
index 53e7b7ca..df2b4e64 100644
0b05ab
--- a/blivet/udev.py
0b05ab
+++ b/blivet/udev.py
0b05ab
@@ -353,7 +353,7 @@ def device_is_disk(info):
0b05ab
                  device_is_dm_lvm(info) or
0b05ab
                  device_is_dm_crypt(info) or
0b05ab
                  (device_is_md(info) and
0b05ab
-                  not device_get_md_container(info))))
0b05ab
+                  (not device_get_md_container(info) and not all(device_is_disk(d) for d in device_get_slaves(info))))))
0b05ab
 
0b05ab
 
0b05ab
 def device_is_partition(info):
0b05ab
@@ -432,6 +432,20 @@ def device_get_devname(info):
0b05ab
     return info.get('DEVNAME')
0b05ab
 
0b05ab
 
0b05ab
+def device_get_slaves(info):
0b05ab
+    """ Return a list of udev device objects representing this device's slaves. """
0b05ab
+    slaves_dir = device_get_sysfs_path(info) + "/slaves/"
0b05ab
+    names = list()
0b05ab
+    if os.path.isdir(slaves_dir):
0b05ab
+        names = os.listdir(slaves_dir)
0b05ab
+
0b05ab
+    slaves = list()
0b05ab
+    for name in names:
0b05ab
+        slaves.append(get_device(device_node="/dev/" + name))
0b05ab
+
0b05ab
+    return slaves
0b05ab
+
0b05ab
+
0b05ab
 def device_get_md_level(info):
0b05ab
     """ Returns the RAID level of the array of which this device is a member.
0b05ab
 
0b05ab
diff --git a/tests/udev_test.py b/tests/udev_test.py
0b05ab
index 5cc81a05..beb8109c 100644
0b05ab
--- a/tests/udev_test.py
0b05ab
+++ b/tests/udev_test.py
0b05ab
@@ -35,3 +35,45 @@ class UdevTest(unittest.TestCase):
0b05ab
         import blivet.udev
0b05ab
         blivet.udev.trigger()
0b05ab
         self.assertTrue(blivet.udev.util.run_program.called)
0b05ab
+
0b05ab
+    @mock.patch('blivet.udev.device_is_cdrom', return_value=False)
0b05ab
+    @mock.patch('blivet.udev.device_is_partition', return_value=False)
0b05ab
+    @mock.patch('blivet.udev.device_is_dm_partition', return_value=False)
0b05ab
+    @mock.patch('blivet.udev.device_is_dm_lvm', return_value=False)
0b05ab
+    @mock.patch('blivet.udev.device_is_dm_crypt', return_value=False)
0b05ab
+    @mock.patch('blivet.udev.device_is_md')
0b05ab
+    @mock.patch('blivet.udev.device_get_md_container')
0b05ab
+    @mock.patch('blivet.udev.device_get_slaves')
0b05ab
+    def test_udev_device_is_disk_md(self, *args):
0b05ab
+        import blivet.udev
0b05ab
+        info = dict(DEVTYPE='disk', SYS_PATH=mock.sentinel.md_path)
0b05ab
+        (device_get_slaves, device_get_md_container, device_is_md) = args[:3]  # pylint: disable=unbalanced-tuple-unpacking
0b05ab
+
0b05ab
+        disk_parents = [dict(DEVTYPE="disk", SYS_PATH='/fake/path/2'),
0b05ab
+                        dict(DEVTYPE="disk", SYS_PATH='/fake/path/3')]
0b05ab
+        partition_parents = [dict(DEVTYPE="partition", SYS_PATH='/fake/path/2'),
0b05ab
+                             dict(DEVTYPE="partition", SYS_PATH='/fake/path/3')]
0b05ab
+        mixed_parents = [dict(DEVTYPE="partition", SYS_PATH='/fake/path/2'),
0b05ab
+                         dict(DEVTYPE="partition", SYS_PATH='/fake/path/3')]
0b05ab
+
0b05ab
+        blivet.udev.os.path.exists.return_value = False  # has_range checked in device_is_disk
0b05ab
+        device_is_md.return_value = True
0b05ab
+
0b05ab
+        # Intel FW RAID (MD RAID w/ container layer)
0b05ab
+        # device_get_container will return some mock value which will evaluate to True
0b05ab
+        device_get_md_container.return_value = mock.sentinel.md_container
0b05ab
+        device_get_slaves.side_effect = lambda info: list()
0b05ab
+        self.assertTrue(blivet.udev.device_is_disk(info))
0b05ab
+
0b05ab
+        # Normal MD RAID
0b05ab
+        device_get_slaves.side_effect = lambda info: partition_parents if info['SYS_PATH'] == mock.sentinel.md_path else list()
0b05ab
+        device_get_md_container.return_value = None
0b05ab
+        self.assertFalse(blivet.udev.device_is_disk(info))
0b05ab
+
0b05ab
+        # Dell FW RAID (MD RAID whose members are all whole disks)
0b05ab
+        device_get_slaves.side_effect = lambda info: disk_parents if info['SYS_PATH'] == mock.sentinel.md_path else list()
0b05ab
+        self.assertTrue(blivet.udev.device_is_disk(info))
0b05ab
+
0b05ab
+        # Normal MD RAID (w/ at least one non-disk member)
0b05ab
+        device_get_slaves.side_effect = lambda info: mixed_parents if info['SYS_PATH'] == mock.sentinel.md_path else list()
0b05ab
+        self.assertFalse(blivet.udev.device_is_disk(info))
0b05ab
-- 
0b05ab
2.24.1
0b05ab
0b05ab
0b05ab
From 1d75298702f55830a3d69858c3b0b7defa7bf6f2 Mon Sep 17 00:00:00 2001
0b05ab
From: David Lehman <dlehman@redhat.com>
0b05ab
Date: Tue, 21 Jan 2020 15:28:27 -0500
0b05ab
Subject: [PATCH 2/2] Fix udev test names so they actually get run.
0b05ab
0b05ab
---
0b05ab
 tests/udev_test.py | 4 ++--
0b05ab
 1 file changed, 2 insertions(+), 2 deletions(-)
0b05ab
0b05ab
diff --git a/tests/udev_test.py b/tests/udev_test.py
0b05ab
index beb8109c..653eeb6d 100644
0b05ab
--- a/tests/udev_test.py
0b05ab
+++ b/tests/udev_test.py
0b05ab
@@ -26,12 +26,12 @@ class UdevTest(unittest.TestCase):
0b05ab
         for device in devices:
0b05ab
             self.assertNotEqual(blivet.udev.get_device(device.sys_path), None)
0b05ab
 
0b05ab
-    def udev_settle_test(self):
0b05ab
+    def test_udev_settle(self):
0b05ab
         import blivet.udev
0b05ab
         blivet.udev.settle()
0b05ab
         self.assertTrue(blivet.udev.util.run_program.called)
0b05ab
 
0b05ab
-    def udev_trigger_test(self):
0b05ab
+    def test_udev_trigger(self):
0b05ab
         import blivet.udev
0b05ab
         blivet.udev.trigger()
0b05ab
         self.assertTrue(blivet.udev.util.run_program.called)
0b05ab
-- 
0b05ab
2.24.1
0b05ab