[master 15/19] Factor out aligning of size to resize unit into a separate method.
mulkieran
installerbot-noreply at redhat.com
Thu Jun 18 21:04:16 UTC 2015
From: mulhern <amulhern at redhat.com>
Related: #56
Use it where appropriate.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/formats/__init__.py | 23 ++++++++++++++++++++---
blivet/formats/fs.py | 2 +-
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 7fa25cb..0a69ef8 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -359,6 +359,24 @@ def updateSizeInfo(self):
"""
pass
+ def _alignToResizeUnit(self, newsize, direction=ROUND_DOWN):
+ """ Returns a new size aligned to the units of the resize tool.
+
+ :param :class:`~.Size` newsize: the proposed new size
+ :returns: newsize modified to yield an aligned size
+ :param direction: one of (decimal.ROUND_UP, decimal.ROUND_DOWN)
+ :rtype: :class:`~.Size`
+
+ The default is to round down.
+
+ If no resize unit available, returns newsize.
+ """
+ try:
+ return newsize.roundToNearest(self._resizeTask.unit, rounding=direction)
+ except NotImplementedError:
+ log.warning("Trying to align size to resize unit, but no resize unit available.")
+ return newsize
+
def _deviceCheck(self, devspec):
""" Verifies that device spec has a proper format.
@@ -600,12 +618,11 @@ def resize(self, **kwargs):
def _resize(self, **kwargs):
""" Do generic resizing actions. """
- # Bump target size to nearest whole number of the resize tool's units.
+
# We always round down because the fs has to fit on whatever device
# contains it. To round up would risk quietly setting a target size too
# large for the device to hold.
- rounded = self.targetSize.roundToNearest(self._resizeTask.unit,
- rounding=ROUND_DOWN)
+ rounded = self._alignToResizeUnit(self.targetSize)
# 1. target size was between the min size and max size values prior to
# rounding (see _setTargetSize)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index f4547ca..bf23ba9 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -281,7 +281,7 @@ def _padSize(self, size):
# make sure the padded and rounded min size is not larger than
# the current size
- padded = min(padded.roundToNearest(self._resizeTask.unit, rounding=ROUND_UP), self.currentSize)
+ padded = min(self._alignToResizeUnit(padded, ROUND_UP), self.currentSize)
return padded
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/7b2db07bcd30b97d8ac05e3930efd49dd6ae6c15
More information about the anaconda-patches
mailing list