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