[blivet 11/13] Remove redundant checks in existing resize() methods.

mulhern amulhern at redhat.com
Fri Dec 6 16:50:11 UTC 2013


It is expected that the resize methods will only be called via the
ActionResizeDevice.execute method. Since this is the case, the removed
checks are redundant.

If it is possible to call the resize methods not through
ActionResizeDevice.execute then the checks that were removed
are not nearly sufficient.

Some comments have been updated, too.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devices.py | 42 ++++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/blivet/devices.py b/blivet/devices.py
index b5435cc..23f3a8b 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -684,9 +684,13 @@ class StorageDevice(Device):
         return spec
 
     def resize(self):
-        """ Resize the device.
+        """ Resize a device to self.targetSize.
 
-            New size should already be set.
+            This method should only be invoked via the
+            ActionResizeDevice.execute method. All the pre-conditions
+            enforced by ActionResizeDevice.__init__ are assumed to hold.
+
+            Returns nothing.
         """
         raise NotImplementedError("resize method not defined for StorageDevice")
 
@@ -1588,27 +1592,23 @@ class PartitionDevice(StorageDevice):
         return (constraint, newGeometry)
 
     def resize(self):
-        """ Resize the device.
-
-            self.targetSize must be set to the new size.
-        """
         log_method_call(self, self.name, status=self.status)
         self._preDestroy()
-        if self.targetSize != self.currentSize:
-            # partedDisk has been restored to _origPartedDisk, so
-            # recalculate resize geometry because we may have new
-            # partitions on the disk, which could change constraints
-            partedDisk = self.disk.format.partedDisk
-            partition = partedDisk.getPartitionByPath(self.path)
-            (constraint, geometry) = self._computeResize(partition)
-
-            partedDisk.setPartitionGeometry(partition=partition,
-                                            constraint=constraint,
-                                            start=geometry.start,
-                                            end=geometry.end)
 
-            self.disk.format.commit()
-            self._currentSize = partition.getSize()
+        # partedDisk has been restored to _origPartedDisk, so
+        # recalculate resize geometry because we may have new
+        # partitions on the disk, which could change constraints
+        partedDisk = self.disk.format.partedDisk
+        partition = partedDisk.getPartitionByPath(self.path)
+        (constraint, geometry) = self._computeResize(partition)
+
+        partedDisk.setPartitionGeometry(partition=partition,
+                                        constraint=constraint,
+                                        start=geometry.start,
+                                        end=geometry.end)
+
+        self.disk.format.commit()
+        self._currentSize = partition.getSize()
 
     def _preDestroy(self):
         StorageDevice._preDestroy(self)
@@ -2740,8 +2740,6 @@ class LVMLogicalVolumeDevice(DMDevice):
 
     def resize(self):
         log_method_call(self, self.name, status=self.status)
-        if not self.exists:
-            raise DeviceError("device has not been created", self.name)
 
         # Setup VG parents (in case they are dmraid partitions for example)
         self.vg.setupParents(orig=True)
-- 
1.8.3.1



More information about the anaconda-patches mailing list