[blivet:rhel7/master 5/8] Extend the list of things to be omitted if moddisk is False (#1043763)

mulhern amulhern at redhat.com
Mon Mar 3 21:33:43 UTC 2014


Related: rhbz#1043763

If moddisk is False then avoid removing partitions, but also avoid removing
logical volumes and subvolumes.

The idea is to leave information about what is on the device intact, but to
remove it from the list of devices.

Only the top few lines have actually changed, the rest is indentation only.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicetree.py | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 38da3e3..0fdffdb 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -294,31 +294,31 @@ class DeviceTree(object):
             log.debug("%s has %d kids" % (dev.name, dev.kids))
             raise ValueError("Cannot remove non-leaf device '%s'" % dev.name)
 
-        # if this is a partition we need to remove it from the parted.Disk
-        if moddisk and isinstance(dev, PartitionDevice) and \
-                dev.disk is not None:
-            # if this partition hasn't been allocated it could not have
-            # a disk attribute
-            if dev.partedPartition.type == parted.PARTITION_EXTENDED and \
-                    len(dev.disk.format.logicalPartitions) > 0:
-                raise ValueError("Cannot remove extended partition %s.  "
-                        "Logical partitions present." % dev.name)
-
-            dev.disk.format.removePartition(dev.partedPartition)
-
-            # adjust all other PartitionDevice instances belonging to the
-            # same disk so the device name matches the potentially altered
-            # name of the parted.Partition
-            for device in self._devices:
-                if isinstance(device, PartitionDevice) and \
-                   device.disk == dev.disk:
-                    device.updateName()
-        elif hasattr(dev, "pool"):
-            dev.pool._removeLogVol(dev)
-        elif hasattr(dev, "vg"):
-            dev.vg._removeLogVol(dev)
-        elif hasattr(dev, "volume"):
-            dev.volume._removeSubVolume(dev.name)
+        if moddisk:
+            # if this is a partition we need to remove it from the parted.Disk
+            if isinstance(dev, PartitionDevice) and dev.disk is not None:
+                # if this partition hasn't been allocated it could not have
+                # a disk attribute
+                if dev.partedPartition.type == parted.PARTITION_EXTENDED and \
+                        len(dev.disk.format.logicalPartitions) > 0:
+                    raise ValueError("Cannot remove extended partition %s.  "
+                            "Logical partitions present." % dev.name)
+
+                dev.disk.format.removePartition(dev.partedPartition)
+
+                # adjust all other PartitionDevice instances belonging to the
+                # same disk so the device name matches the potentially altered
+                # name of the parted.Partition
+                for device in self._devices:
+                    if isinstance(device, PartitionDevice) and \
+                       device.disk == dev.disk:
+                        device.updateName()
+            elif hasattr(dev, "pool"):
+                dev.pool._removeLogVol(dev)
+            elif hasattr(dev, "vg"):
+                dev.vg._removeLogVol(dev)
+            elif hasattr(dev, "volume"):
+                dev.volume._removeSubVolume(dev.name)
 
         self._devices.remove(dev)
         if dev.name in self.names and getattr(dev, "complete", True):
-- 
1.8.3.1



More information about the anaconda-patches mailing list