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