neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0017-Exclude-unusable-disks-from-PartitionFactory.patch

881dcd
From f02dbed9143664246d400b0f5654062dff5383fc Mon Sep 17 00:00:00 2001
881dcd
From: Vojtech Trefny <vtrefny@redhat.com>
881dcd
Date: Thu, 13 Jan 2022 16:53:30 +0100
881dcd
Subject: [PATCH 1/2] Exclude unusable disks from PartitionFactory
881dcd
881dcd
We already remove disks that are too small or not partitionable
881dcd
in the PartitionSetFactory which allows us to create partitions
881dcd
on multipath devices where Anaconda tells us to use both the mpath
881dcd
device and the backing disks, we should do the same for the
881dcd
PartitionFactory.
881dcd
881dcd
Resolves: rhbz#2017432
881dcd
---
881dcd
 blivet/devicefactory.py | 18 ++++++++++++++++++
881dcd
 1 file changed, 18 insertions(+)
881dcd
881dcd
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
881dcd
index 0f7fdfa1..45b38b0f 100644
881dcd
--- a/blivet/devicefactory.py
881dcd
+++ b/blivet/devicefactory.py
881dcd
@@ -1056,6 +1056,24 @@ class PartitionFactory(DeviceFactory):
881dcd
                                             **kwargs)
881dcd
         return device
881dcd
 
881dcd
+    def _configure(self):
881dcd
+        disks = []
881dcd
+        for disk in self.disks:
881dcd
+            if not disk.partitioned:
881dcd
+                log.debug("removing unpartitioned disk %s", disk.name)
881dcd
+            elif not disk.format.supported:
881dcd
+                log.debug("removing disk with unsupported format %s", disk.name)
881dcd
+            else:
881dcd
+                disks.append(disk)
881dcd
+
881dcd
+        if not disks:
881dcd
+            raise DeviceFactoryError("no usable disks specified for partition")
881dcd
+
881dcd
+        log.debug("setting new factory disks to %s", [d.name for d in disks])
881dcd
+        self.disks = disks  # pylint: disable=attribute-defined-outside-init
881dcd
+
881dcd
+        super(PartitionFactory, self)._configure()
881dcd
+
881dcd
     def _set_disks(self):
881dcd
         self.raw_device.req_disks = self.disks[:]
881dcd
 
881dcd
-- 
881dcd
2.34.1
881dcd
881dcd
881dcd
From a9adcb050a16ab8231c81ced68302d6ad685ccf4 Mon Sep 17 00:00:00 2001
881dcd
From: Vojtech Trefny <vtrefny@redhat.com>
881dcd
Date: Thu, 13 Jan 2022 17:27:08 +0100
881dcd
Subject: [PATCH 2/2] Show better error when using unitialized disk in
881dcd
 do_partitioning
881dcd
881dcd
Now all we get is "KeyError: '/dev/sda'" for example.
881dcd
881dcd
Related: rhbz#2017432
881dcd
---
881dcd
 blivet/partitioning.py | 5 ++++-
881dcd
 1 file changed, 4 insertions(+), 1 deletion(-)
881dcd
881dcd
diff --git a/blivet/partitioning.py b/blivet/partitioning.py
881dcd
index 53f9cc3f..23b150f9 100644
881dcd
--- a/blivet/partitioning.py
881dcd
+++ b/blivet/partitioning.py
881dcd
@@ -764,7 +764,10 @@ def allocate_partitions(storage, disks, partitions, freespace, boot_disk=None):
881dcd
         growth = 0  # in sectors
881dcd
         # loop through disks
881dcd
         for _disk in req_disks:
881dcd
-            disklabel = disklabels[_disk.path]
881dcd
+            try:
881dcd
+                disklabel = disklabels[_disk.path]
881dcd
+            except KeyError:
881dcd
+                raise PartitioningError("Requested disk %s doesn't have a usable disklabel for partitioning" % _disk.name)
881dcd
             best = None
881dcd
             current_free = free
881dcd
             try:
881dcd
-- 
881dcd
2.34.1
881dcd