[anaconda:master 7/7] Rewrite _bound_size()

mulhern amulhern at redhat.com
Mon Oct 13 21:16:04 UTC 2014


Fix a bug where the possibility of maxSize() being 0, a value which is used
to mean no maxSize() given, is not taken into account.

Since, a fall back is needed in case this happens, pass old_size to
_bound_size as well.

Rearrange if statement a bit to make it clearer now that additional
possibilities are taken into account.

Do a bit more logging, in case something useful-to-know or bad happens.

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

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index deffb19..706b05a 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -722,15 +722,39 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         log.debug("resetting device %s", original_device.name)
         self._storage_playground.resetDevice(original_device)
 
-    def _bound_size(self, size, device):
-        # If no size was specified, we just want to grow to the maximum.
-        # But resizeDevice doesn't take None for a value.
+    def _bound_size(self, size, device, old_size):
+        """ Returns a size bounded by the maximum and minimum size for
+            the device.
+
+            :param size: the candidate size
+            :type size: :class:`blivet.size.Size`
+            :param device: the device being displayed
+            :type device: :class:`blivet.devices.StorageDevice`
+            :param size: the fallback size
+            :type size: :class:`blivet.size.Size`
+            :returns: a size to which to set the device
+            :rtype: :class:`blivet.size.Size`
+
+            If size is 0, interpreted as set size to maximum possible.
+
+            If no maximum size is available, reset size to old_size, but
+            log a warning.
+        """
+        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)
+            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
 
         return size
 
@@ -752,7 +776,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             use_old_size = use_dev.size
 
         # bound size to boundaries given by the device
-        size = self._bound_size(use_size, use_dev)
+        size = self._bound_size(use_size, use_dev, use_old_size)
 
         # And then we need to re-check that the max size is actually
         # different from the current size.
-- 
1.9.3



More information about the anaconda-patches mailing list