[master 7/19] Hoist size related methods and attributes to DeviceFormat.

mulkieran installerbot-noreply at redhat.com
Thu Jun 18 21:04:08 UTC 2015


From: mulhern <amulhern at redhat.com>

Related: #56

Attributes are:
* _size
* _targetSize

Method are:
* size
* currentSize
* targetSize
* updateSizeInfo

_setTargetSize() now raises DeviceFormatError where previously it raised
FSError.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/__init__.py      | 75 +++++++++++++++++++++++++++++++++++++++--
 blivet/formats/fs.py            | 52 +++-------------------------
 tests/formats_test/fstesting.py |  6 ++--
 3 files changed, 79 insertions(+), 54 deletions(-)

diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index b3e58fa..e57cf20 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -183,6 +183,9 @@ def __init__(self, **kwargs):
         self._options = None
         self._device = None
 
+        self._size = kwargs.get("size", Size(0))
+        self._targetSize = self._size
+
         self.device = kwargs.get("device")
         self.uuid = kwargs.get("uuid")
         self.exists = kwargs.get("exists", False)
@@ -193,13 +196,15 @@ def __repr__(self):
              "  type = %(type)s  name = %(name)s  status = %(status)s\n"
              "  device = %(device)s  uuid = %(uuid)s  exists = %(exists)s\n"
              "  options = %(options)s  supported = %(supported)s"
-             "  formattable = %(format)s  resizable = %(resize)s\n" %
+             "  formattable = %(format)s  resizable = %(resize)s"
+             "  size = %(size)s  targetSize = %(targetSize)s\n" %
              {"classname": self.__class__.__name__, "id": "%#x" % id(self),
               "object_id": self.id,
               "type": self.type, "name": self.name, "status": self.status,
               "device": self.device, "uuid": self.uuid, "exists": self.exists,
               "options": self.options, "supported": self.supported,
-              "format": self.formattable, "resize": self.resizable})
+              "format": self.formattable, "resize": self.resizable,
+              "size": self._size, "targetSize": self.targetSize})
         return s
 
     @property
@@ -218,7 +223,8 @@ def dict(self):
         d = {"type": self.type, "name": self.name, "device": self.device,
              "uuid": self.uuid, "exists": self.exists,
              "options": self.options, "supported": self.supported,
-             "resizable": self.resizable}
+             "resizable": self.resizable, "size": self._size,
+             "targetSize": self.targetSize}
         return d
 
     def labeling(self):
@@ -278,6 +284,15 @@ def _getLabel(self):
         """
         return self._label
 
+    def _getSize(self):
+        """ Get this format's size. """
+        return self.targetSize if self.resizable else self._size
+
+    size = property(
+       lambda s: s._getSize(),
+       doc="This format's size, accounting for pending changes"
+    )
+
     def _setOptions(self, options):
         self._options = options
 
@@ -290,6 +305,55 @@ def _getOptions(self):
        doc="fstab entry option string"
     )
 
+    def _getTargetSize(self):
+        """ Get the target size.
+
+            :returns: the target size
+            :rtype: :class:`~.size.Size`
+        """
+        return self._targetSize
+
+    def _setTargetSize(self, newsize):
+        """ Set the target size.
+
+            :param :class:`~.size.Size` newsize: a size value
+
+            This is the size which the format is set to when the
+            format is resized.
+        """
+        if not isinstance(newsize, Size):
+            raise ValueError("new size must be of type Size")
+
+        if not self.exists:
+            raise DeviceFormatError("format has not been created")
+
+        if not self.resizable:
+            raise DeviceFormatError("format is not resizable")
+
+        if newsize < self.minSize:
+            raise ValueError("requested size %s must be at least minimum size %s" % (newsize, self.minSize))
+
+        if self.maxSize and newsize >= self.maxSize:
+            raise ValueError("requested size %s must be less than maximum size %s" % (newsize, self.maxSize))
+
+        self._targetSize = newsize
+
+    targetSize = property(
+      lambda s: s._getTargetSize(),
+      lambda s, v: s._setTargetSize(v),
+      doc="target size for a resize operation"
+    )
+
+    def updateSizeInfo(self):
+        """ Update this format's current size.
+
+            May also update this format's minimum size.
+
+            May also affect whether or not this filesystem is considered
+            resizable by setting self._resizable or other attributes.
+        """
+        pass
+
     def _deviceCheck(self, devspec):
         """ Verifies that device spec has a proper format.
 
@@ -590,6 +654,11 @@ def minSize(self):
         return self._minSize
 
     @property
+    def currentSize(self):
+        """ The format's current actual size. """
+        return self._size if self.exists else Size(0)
+
+    @property
     def hidden(self):
         """ Whether devices with this formatting should be hidden in UIs. """
         return self._hidden
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index e2c5ef3..fb24243 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -122,7 +122,6 @@ def __init__(self, **kwargs):
         self.fsprofile = kwargs.get("fsprofile")
 
         # filesystem size does not necessarily equal device size
-        self._size = kwargs.get("size", Size(0))
         self._minInstanceSize = Size(0)    # min size of this FS instance
 
         # Resize operations are limited to error-free filesystems whose current
@@ -146,11 +145,9 @@ def __init__(self, **kwargs):
     def __repr__(self):
         s = DeviceFormat.__repr__(self)
         s += ("  mountpoint = %(mountpoint)s  mountopts = %(mountopts)s\n"
-              "  label = %(label)s  size = %(size)s"
-              "  targetSize = %(targetSize)s\n" %
+              "  label = %(label)s\n" %
               {"mountpoint": self.mountpoint, "mountopts": self.mountopts,
-               "label": self.label, "size": self._size,
-               "targetSize": self.targetSize})
+               "label": self.label})
         return s
 
     @property
@@ -163,8 +160,8 @@ def desc(self):
     @property
     def dict(self):
         d = super(FS, self).dict
-        d.update({"mountpoint": self.mountpoint, "size": self._size,
-                  "label": self.label, "targetSize": self.targetSize,
+        d.update({"mountpoint": self.mountpoint,
+                  "label": self.label,
                   "mountable": self.mountable})
         return d
 
@@ -196,42 +193,6 @@ def labelFormatOK(self, label):
     label = property(lambda s: s._getLabel(), lambda s,l: s._setLabel(l),
        doc="this filesystem's label")
 
-    def _setTargetSize(self, newsize):
-        """ Set the target size for this filesystem.
-
-            :param :class:`~.size.Size` newsize: the newsize
-        """
-        if not isinstance(newsize, Size):
-            raise ValueError("new size must be of type Size")
-
-        if not self.exists:
-            raise FSError("filesystem has not been created")
-
-        if not self.resizable:
-            raise FSError("filesystem is not resizable")
-
-        if newsize < self.minSize:
-            raise ValueError("requested size %s must be at least minimum size %s" % (newsize, self.minSize))
-
-        if self.maxSize and newsize >= self.maxSize:
-            raise ValueError("requested size %s must be less than maximum size %s" % (newsize, self.maxSize))
-
-        self._targetSize = newsize
-
-    def _getTargetSize(self):
-        """ Get this filesystem's target size. """
-        return self._targetSize
-
-    targetSize = property(_getTargetSize, _setTargetSize,
-                          doc="Target size for this filesystem")
-
-    def _getSize(self):
-        """ Get this filesystem's size. """
-        return self.targetSize if self.resizable else self._size
-
-    size = property(_getSize, doc="This filesystem's size, accounting "
-                                  "for pending changes")
-
     def updateSizeInfo(self):
         """ Update this filesystem's current and minimum size (for resize). """
 
@@ -326,11 +287,6 @@ def _padSize(self, size):
         return padded
 
     @property
-    def currentSize(self):
-        """ The filesystem's current actual size. """
-        return self._size if self.exists else Size(0)
-
-    @property
     def free(self):
         """ The amount of space that can be gained by resizing this
             filesystem to its minimum size.
diff --git a/tests/formats_test/fstesting.py b/tests/formats_test/fstesting.py
index 32c85af..fd205f2 100644
--- a/tests/formats_test/fstesting.py
+++ b/tests/formats_test/fstesting.py
@@ -6,7 +6,7 @@
 import tempfile
 
 from tests import loopbackedtestcase
-from blivet.errors import FSError, FSResizeError
+from blivet.errors import DeviceFormatError, FSError, FSResizeError
 from blivet.size import Size, ROUND_DOWN
 from blivet.formats import fs
 
@@ -197,9 +197,9 @@ def testResize(self):
         if not can_resize(an_fs):
             self.assertFalse(an_fs.resizable)
             # Not resizable, so can not do resizing actions.
-            with self.assertRaises(FSError):
+            with self.assertRaises(DeviceFormatError):
                 an_fs.targetSize = Size("64 MiB")
-            with self.assertRaises(FSError):
+            with self.assertRaises(DeviceFormatError):
                 an_fs.doResize()
         else:
             self.assertTrue(an_fs.resizable)


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/32e00809054054f4ac940f35c5d12f5b580461e1


More information about the anaconda-patches mailing list