[PATCH 07/11] Allow for multiple calls to DeviceTree.processActions. (#881023, #846573)

David Lehman dlehman at redhat.com
Mon Feb 4 23:32:33 UTC 2013


Any commit of a DiskLabel will now trigger an update of its
origPartedDisk attribute so it always reflects the on-disk state.
---
 blivet/devicetree.py        | 5 ++++-
 blivet/formats/disklabel.py | 8 +++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index eee8ed6..a400656 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -84,6 +84,7 @@ class DeviceTree(object):
         # internal data members
         self._devices = []
         self._actions = []
+        self._completed_actions = []
 
         # a list of all device names we encounter
         self.names = []
@@ -235,7 +236,7 @@ class DeviceTree(object):
         for action in self._actions:
             log.debug("action: %s" % action)
 
-        for action in self._actions:
+        for action in self._actions[:]:
             log.info("executing action: %s" % action)
             if not dryRun:
                 try:
@@ -253,6 +254,8 @@ class DeviceTree(object):
                         device.updateName()
                         device.format.device = device.path
 
+                self._completed_actions.append(self._actions.pop(0))
+
     def _addDevice(self, newdev):
         """ Add a device to the tree.
 
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 018adf4..32e995d 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -74,7 +74,7 @@ class DiskLabel(DeviceFormat):
 
         if self.partedDevice:
             # set up the parted objects and raise exception on failure
-            self._origPartedDisk = self.partedDisk.duplicate()
+            self.updateOrigPartedDisk()
 
     def __deepcopy__(self, memo):
         """ Create a deep copy of a Disklabel instance.
@@ -131,6 +131,9 @@ class DiskLabel(DeviceFormat):
                   "grainSize": self.alignment.grainSize})
         return d
 
+    def updateOrigPartedDisk(self):
+        self._origPartedDisk = self.partedDisk.duplicate()
+
     def resetPartedDisk(self):
         """ Set this instance's partedDisk to reflect the disk's contents. """
         log_method_call(self, device=self.device)
@@ -290,6 +293,7 @@ class DiskLabel(DeviceFormat):
         except parted.DiskException as msg:
             raise DiskLabelCommitError(msg)
         else:
+            self.updateOrigPartedDisk()
             udev_settle()
 
     def commitToDisk(self):
@@ -300,6 +304,8 @@ class DiskLabel(DeviceFormat):
             self.partedDisk.commitToDevice()
         except parted.DiskException as msg:
             raise DiskLabelCommitError(msg)
+        else:
+            self.updateOrigPartedDisk()
 
     def addPartition(self, *args, **kwargs):
         partition = kwargs.get("partition", None)
-- 
1.8.1



More information about the anaconda-patches mailing list