[PATCH 1/2] Properly revert changes when cancelling Partition destruction

Vratislav Podzimek vpodzime at redhat.com
Thu Sep 11 14:09:56 UTC 2014


When a partition is scheduled to be destroyed, the action removes it's device
from the devicetree and from its parent's format. While the former change is
reverted in the devicetree's action cancelling, the latter one is ignored and
needs this fix.

Related: rhbz#1085201
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/deviceaction.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index db4c7a7..fb11f8e 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -336,6 +336,14 @@ class ActionDestroyDevice(DeviceAction):
     def __init__(self, device):
         # XXX should we insist that device.fs be None?
         DeviceAction.__init__(self, device)
+        self._origPartition = None
+        self._origDiskFormat = None
+
+        if isinstance(device, PartitionDevice) and device.disk is not None:
+            # removing partition, save it and its format in case we have to
+            # revert changes when canceling this action
+            self._origPartition = device.partedPartition
+            self._origDiskFormat = device.disk.format
 
     def execute(self):
         super(ActionDestroyDevice, self).execute()
@@ -349,6 +357,13 @@ class ActionDestroyDevice(DeviceAction):
             except Exception: # pylint: disable=broad-except
                 log_exception_info(fmt_str="failed to remove info for device %s from libparted cache", fmt_args=[self.device])
 
+    def cancel(self):
+        super(ActionDestroyDevice, self).cancel()
+
+        # canceling partition removal, add the partition back to its disk format
+        if self._origDiskFormat and self._origPartition:
+            self._origDiskFormat.addPartition(self._origPartition)
+
     def requires(self, action):
         """ Return True if self requires action.
 
-- 
1.9.3



More information about the anaconda-patches mailing list