[blivet:rhel7/master 4/5] size related changes to save_right_side() (#1076055)

mulhern amulhern at redhat.com
Thu Sep 25 18:03:35 UTC 2014

Related: rhbz#1076055

Changes are:

* Call resizeDevice() on use_dev instead of device.
Add a comment explaining why the user may sometimes find the
results disturbing.

* Omit incorrect checks about changed size.
Size can only be changed if sizeEntry field is sensitive.
The conditions here are bound to grow stale and have already diverged from
the ones that enable or disable the sensitivity of the sizeEntry field.

* Comment a chunk of code for my better understanding.

* Omit incorrect check for changed_size.
It's wrong, because we want to check properties of the raw device, not
the device, so it's a bug source. Also it's redundant, by same
argument as above.

* Handle case where device.maxSize is 0 differently
Previously, if maxSize was 0, meaning no specified maxSize, and size was
not set, size was set to 0. Now, size is set to old_size instead since it
is not clear when maxSize is not given what size ought to be.

If statements rearranged a bit to increase clarity with this extra
condition and log.info and log.warning messages added.

Signed-off-by: mulhern <amulhern at redhat.com>
 pyanaconda/ui/gui/spokes/custom.py | 44 ++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 4c06cd7..761d0d6 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -1298,13 +1298,11 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         # we are interested in size human readable representation change because
         # that's what the user sees
-        same_size = self._device_size_text == self._sizeEntry.get_text()
-        if same_size:
-            size = old_size
-        else:
+        changed_size = self._device_size_text != self._sizeEntry.get_text()
+        if changed_size:
             size = size_from_entry(self._sizeEntry)
-        changed_size = ((use_dev.resizable or not use_dev.exists) and
-                        not same_size)
+        else:
+            size = old_size
         log.debug("old size: %s", old_size)
         log.debug("new size: %s", size)
@@ -1507,6 +1505,9 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                    changed_container or changed_container_encrypted or
                    changed_container_raid_level or changed_container_size)
+        # If the underlying device does not exist, best just to make a
+        # new representation of the device, instead of to schedule a
+        # whole lot of actions.
         if not use_dev.exists:
             if not changed:
                 log.debug("nothing changed for new device")
@@ -1617,16 +1618,23 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             with ui_storage_logger():
-        if changed_size and device.resizable:
-            # If no size was specified, we just want to grow to
-            # the maximum.  But resizeDevice doesn't take None for
-            # a value.
+        if changed_size:
+            max_size = device.maxSize
+            min_size = device.minSize
             if not size:
-                size = device.maxSize
-            elif size < device.minSize:
-                size = device.minSize
-            elif size > device.maxSize:
-                size = device.maxSize
+                if max_size:
+                    log.info("No size specified, using maximum size for this device (%d).", max_size)
+                    size = max_size
+                else:
+                    log.warning("No size specified and no maximum size available, setting size back to original size (%d).", old_size)
+                    size = old_size
+            else:
+                if size < min_size:
+                    log.warning("Size specified (%d) is less than the minimum size for this device (%d), using minimum size.", size, min_size)
+                    size = min_size
+                elif max_size and size > max_size:
+                    log.warning("Size specified (%d) is greater than the maximum size for this device (%d), using maximum size.", size, max_size)
+                    size = max_size
             # And then we need to re-check that the max size is actually
             # different from the current size.
@@ -1644,7 +1652,11 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                 with ui_storage_logger():
-                        self.__storage.resizeDevice(device, size)
+                        # Always actually set size of raw_device.
+                        # The user sees the size of the device.
+                        # Therefore, the size the user sees may be
+                        # slightly smaller than the size they requested.
+                        self.__storage.resizeDevice(use_dev, size)
                     except StorageError as e:
                         log.error("failed to schedule device resize: %s", e)
                         device.size = old_size

More information about the anaconda-patches mailing list