[PATCH] Handle request.drive being a list or string (#485622)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Prevents tracebacks with 'KeyError: 's''.  request.drive can be a
list or a string and when iterating it with a for loop, the string
is broken up in to individual characters.

For the fix, if we get a KeyError exception, treat request.drive as
a string and pull the disk from diskset.disks with request.drive as
the key.
---
 autopart.py        |   45 +++++++++++++++------
 fsset.py           |   12 ++++--
 iscsi.py           |   12 ++++--
 partIntfHelpers.py |  113 +++++++++++++++++++++++++++++++---------------------
 partRequests.py    |   11 ++++-
 5 files changed, 124 insertions(+), 69 deletions(-)

diff --git a/autopart.py b/autopart.py
index 81ed9b6..1a45f7e 100644
--- a/autopart.py
+++ b/autopart.py
@@ -68,13 +68,18 @@ else:
 # check that our "boot" partitions meet necessary constraints unless
 # the request has its ignore flag set
 def bootRequestCheck(req, diskset):
+    part = None
+
     if not req.device or req.ignoreBootConstraints:
         return PARTITION_SUCCESS
 
-    for drive in req.drive:
-        part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
-        if part:
-            break
+    try:
+        for drive in req.drive:
+            part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
+            if part:
+                break
+    except:
+        pass
 
     if not part:
         return PARTITION_SUCCESS
@@ -90,8 +95,14 @@ def bootRequestCheck(req, diskset):
         return bootAlphaCheckRequirements(part)
     elif (iutil.getPPCMachine() == "pSeries" or
           iutil.getPPCMachine() == "iSeries"):
-        for drive in req.drive:
-            part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
+        try:
+            for drive in req.drive:
+                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
+                if part and ((part.geometry.end * part.geometry.device.sectorSize /
+                              (1024.0 * 1024)) > 4096):
+                    return BOOTIPSERIES_TOO_HIGH
+        except KeyError:
+            part = diskset.disks[req.drive].getPartitionByPath("/dev/%s" % req.device)
             if part and ((part.geometry.end * part.geometry.device.sectorSize /
                           (1024.0 * 1024)) > 4096):
                 return BOOTIPSERIES_TOO_HIGH
@@ -734,10 +745,13 @@ def growParts(diskset, requests, newParts):
                 donegrowing = 0
 
                 # get amount of space actually used by current allocation
-                for drive in request.drive:
-                    part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
-                    if part:
-                        break
+                try:
+                    for drive in request.drive:
+                        part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
+                        if part:
+                            break
+                except KeyError:
+                    part = diskset.disks[request.drive].getPartitionByPath("/dev/%s" % request.device)
 
                 startSize = part.geometry.length
 
@@ -1020,8 +1034,15 @@ def processPartitioning(diskset, requests, newParts):
         elif request.preexist:
             # we need to keep track of the max size of preexisting partitions
             # FIXME: we should also get the max size for LVs at some point
-            part = diskset.disks[request.drive].getPartitionByPath("/dev/%s" % request.device)
-            request.maxResizeSize = part.getMaxAvailableSize(unit="MB")
+            try:
+                for drive in request.drive:
+                    part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
+                    if part:
+                        request.maxResizeSize += part.getMaxAvailableSize(unit="MB")
+            except KeyError:
+                part = diskset.disks[request.drive].getPartitionByPath("/dev/%s" % request.device)
+                if part:
+                    request.maxResizeSize += part.getMaxAvailableSize(unit="MB")
 
 ##     print("disk layout after everything is done")
 ##     print(diskset.diskState())
diff --git a/fsset.py b/fsset.py
index 88545f0..497e60c 100644
--- a/fsset.py
+++ b/fsset.py
@@ -1648,10 +1648,14 @@ MAILADDR root
                 if request.mountpoint == bootDev.mountpoint:
                     break
 
-            for drive in request.drive:
-                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % bootDev.device.device)
-                if part:
-                    break
+            try:
+                for drive in request.drive:
+                    part = diskset.disks[drive].getPartitionByPath("/dev/%s" % bootDev.device.device)
+                    if part:
+                        break
+            except KeyError:
+                part = diskset.disks[request.drive].getPartitionByPath("/dev/%s" % bootDev.device.device)
+                drive = request.drive
 
             # on EFI systems, *only* /boot/efi should be marked bootable
             # similarly, on pseries, we really only want the PReP partition
diff --git a/iscsi.py b/iscsi.py
index f6643db..e9aedb0 100644
--- a/iscsi.py
+++ b/iscsi.py
@@ -300,10 +300,14 @@ class iscsi(object):
             req = anaconda.id.partitions.getRequestByMountPoint("/")
             root_requests = anaconda.id.partitions.getUnderlyingRequests(req)
             for req in root_requests:
-                for drive in req.drive:
-                    part = anaconda.id.diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
-                    if part:
-                        break
+                try:
+                    for drive in req.drive:
+                        part = anaconda.id.diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
+                        if part:
+                            break
+                except KeyError:
+                    part = anaconda.id.diskset.disks[req.drive].getPartitionByPath("/dev/%s" % req.device)
+                    drive = req.drive
                 if not part:
                     continue
                 if drive not in root_drives:
diff --git a/partIntfHelpers.py b/partIntfHelpers.py
index 0c6541c..01fc7a9 100644
--- a/partIntfHelpers.py
+++ b/partIntfHelpers.py
@@ -235,6 +235,14 @@ def doDeletePartitionByRequest(intf, requestlist, partition,
     del partition
     return 1
 
+def _skipPart(part):
+    if part.type & parted.PARTITION_FREESPACE or \
+       part.type & parted.PARTITION_METADATA or \
+       part.type & parted.PARTITION_PROTECTED:
+        return True
+    else:
+        return False
+
 def doDeletePartitionsByDevice(intf, requestlist, diskset, device,
 			       confirm=1, quiet=0):
     """ Remove all partitions currently on device """
@@ -257,20 +265,25 @@ def doDeletePartitionsByDevice(intf, requestlist, diskset, device,
     reqparts = {}
 
     for req in requests:
-        for drive in req.drive:
-            part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
+        def _gatherPart(part, uniqueID):
+            reqIDs.add(uniqueID)
 
-            if part.type & parted.PARTITION_FREESPACE or \
-               part.type & parted.PARTITION_METADATA or \
-               part.type & parted.PARTITION_PROTECTED:
-                continue
+            if reqparts.has_key(uniqueID):
+                reqparts[uniqueID].append(part)
+            else:
+                reqparts[uniqueID] = [ part ]
 
-            reqIDs.add(req.uniqueID)
+        try:
+            for drive in req.drive:
+                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
 
-            if reqparts.has_key(req.uniqueID):
-                reqparts[req.uniqueID].append(part)
-            else:
-                reqparts[req.uniqueID] = [ part ]
+                if not _skipPart(part):
+                    _gatherPart(part, req.uniqueID)
+        except KeyError:
+            part = diskset.disks[req.drive].getPartitionByPath("/dev/%s" % req.device)
+
+            if not _skipPart(part):
+                _gatherPart(part, req.uniqueID)
 
     reqIDs = list(reqIDs)
 
@@ -297,15 +310,15 @@ def doDeletePartitionsByDevice(intf, requestlist, diskset, device,
         leftIDs = set()
 
         for req in left_requests:
-            for drive in req.drive:
-                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
-
-                if part.type & parted.PARTITION_FREESPACE or \
-                   part.type & parted.PARTITION_METADATA or \
-                   part.type & parted.PARTITION_PROTECTED:
-                    continue
-
-                leftIDs.add(req.uniqueID)
+            try:
+                for drive in req.drive:
+                    part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
+                    if not _skipPart(part):
+                        leftIDs.add(req.uniqueID)
+            except KeyError:
+                part = diskset.disks[req.drive].getPartitionByPath("/dev/%s" % req.device)
+                if not _skipPart(part):
+                    leftIDs.add(req.uniqueID)
 
         leftIDs = list(leftIDs)
 
@@ -399,38 +412,46 @@ def doEditPartitionByRequest(intf, requestlist, part):
 
 def checkForSwapNoMatch(anaconda):
     """Check for any partitions of type 0x82 which don't have a swap fs."""
+    def _formatSwapWindow(part, request):
+        if (part and (not part.type & parted.PARTITION_FREESPACE)
+            and (part.getFlag(parted.PARTITION_SWAP))
+            and (request.fstype and request.fstype.getName() != "swap")
+            and (not request.format)):
+            rc = anaconda.intf.messageWindow(_("Format as Swap?"),
+                                    _("/dev/%s has a partition type of 0x82 "
+                                      "(Linux swap) but does not appear to "
+                                      "be formatted as a Linux swap "
+                                      "partition.\n\n"
+                                      "Would you like to format this "
+                                      "partition as a swap partition?")
+                                    % (request.device), type = "yesno",
+                                    custom_icon="question")
+            if rc == 1:
+                request.format = 1
+                request.fstype = fsset.fileSystemTypeGet("swap")
+                if request.fstype.getName() == "software RAID":
+                    part.setFlag(parted.PARTITION_RAID)
+                else:
+                    part.unsetFlag(parted.PARTITION_RAID)
+
+                partedUtils.set_partition_file_system_type(part,
+                                                           request.fstype)
+
     diskset = anaconda.id.diskset
 
     for request in anaconda.id.partitions.requests:
         if not request.dev or not request.fstype:
             continue
 
-        for drive in request.drive:
-            part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
-
-            if (part and (not part.type & parted.PARTITION_FREESPACE)
-                and (part.getFlag(parted.PARTITION_SWAP))
-                and (request.fstype and request.fstype.getName() != "swap")
-                and (not request.format)):
-                rc = anaconda.intf.messageWindow(_("Format as Swap?"),
-                                        _("/dev/%s has a partition type of 0x82 "
-                                          "(Linux swap) but does not appear to "
-                                          "be formatted as a Linux swap "
-                                          "partition.\n\n"
-                                          "Would you like to format this "
-                                          "partition as a swap partition?")
-                                        % (request.device), type = "yesno",
-                                        custom_icon="question")
-                if rc == 1:
-                    request.format = 1
-                    request.fstype = fsset.fileSystemTypeGet("swap")
-                    if request.fstype.getName() == "software RAID":
-                        part.setFlag(parted.PARTITION_RAID)
-                    else:
-                        part.unsetFlag(parted.PARTITION_RAID)
-
-                    partedUtils.set_partition_file_system_type(part,
-                                                               request.fstype)
+        try:
+            for drive in request.drive:
+                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
+                if part:
+                    _formatSwapWindow(part, request)
+        except KeyError:
+            part = diskset.disks[request.drive].getPartitionByPath("/dev/%s" % request.device)
+            if part:
+                _formatSwapWindow(part, request)
 
 def mustHaveSelectedDrive(intf):
     txt =_("You need to select at least one hard drive to install %s.") % (productName,)
diff --git a/partRequests.py b/partRequests.py
index d4b41ce..afc9f65 100644
--- a/partRequests.py
+++ b/partRequests.py
@@ -519,9 +519,14 @@ class PartitionSpec(RequestSpec):
         """Return the actual size allocated for the request in megabytes."""
         size = 0
 
-        for drive in self.drive:
-            part = diskset.disks[drive].getPartitionByPath("/dev/%s" % self.device)
-
+        try:
+            for drive in self.drive:
+                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % self.device)
+
+                if part:
+                    size += part.getSize(unit="MB")
+        except KeyError:
+            part = diskset.disks[self.drive].getPartitionByPath("/dev/%s" % self.device)
             if part:
                 size += part.getSize(unit="MB")
 
-- 
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux