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