[master 16/30] Read labels via fsreadlabel tasks.
mulkieran
installerbot-noreply at redhat.com
Fri Apr 17 21:49:41 UTC 2015
From: mulhern <amulhern at redhat.com>
Related: #12
This particular step is low stress, as currently filesystem label reading
is only done for testing.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/formats/fs.py | 35 +++++++++++++++--------------------
tests/tasks_test/fslabeling.py | 6 +++---
2 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 42165b6..f794319 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -27,7 +27,8 @@
import tempfile
from ..tasks import fslabeling
-from ..errors import FormatCreateError, FSError, FSResizeError
+from ..tasks import fsreadlabel
+from ..errors import FormatCreateError, FSError, FSReadLabelError, FSResizeError
from . import DeviceFormat, register_device_format
from .. import util
from .. import platform
@@ -58,6 +59,7 @@ class FS(DeviceFormat):
_fsck = "" # fs check utility
_fsckErrors = {} # fs check command error codes & msgs
_infofs = "" # fs info utility
+ _readlabelClass = None # read label
_defaultFormatOptions = [] # default options passed to mkfs
_defaultMountOptions = ["defaults"] # default options passed to mount
_defaultCheckOptions = []
@@ -96,6 +98,10 @@ def getTaskObject(klass):
raise TypeError("FS is an abstract class.")
DeviceFormat.__init__(self, **kwargs)
+
+ # Create task objects
+ self._readlabel = getTaskObject(self._readlabelClass)
+
self.mountpoint = kwargs.get("mountpoint")
self.mountopts = kwargs.get("mountopts")
self.label = kwargs.get("label")
@@ -739,27 +745,12 @@ def readLabel(self):
:return: the filesystem's label
:rtype: str
- Raises a FSError if the label can not be read.
+ Raises a FSReadLabelError if the label can not be read.
"""
- if not self.exists:
- raise FSError("filesystem has not been created")
-
- if not os.path.exists(self.device):
- raise FSError("device does not exist")
-
- if not self.relabels() or not self._labelfs.label_app.reads:
- raise FSError("no application to read label for filesystem %s" % self.type)
-
- (rc, out) = util.run_program_and_capture_output(self._labelfs.label_app.readLabelCommand(self))
- if rc:
- raise FSError("read label failed")
-
- label = out.strip()
-
- if label == "":
- return ""
+ if self._readlabel is not None:
+ return self._readlabel.doTask()
else:
- return self._labelfs.label_app.extractLabel(label)
+ raise FSReadLabelError("label reading not implemented for filesystem %s" % self.type)
def writeLabel(self):
""" Create a label for this filesystem.
@@ -965,6 +956,7 @@ class Ext2FS(FS):
_dump = True
_check = True
_infofs = "dumpe2fs"
+ _readlabelClass = fsreadlabel.Ext2FSReadLabel
_defaultInfoOptions = ["-h"]
_existingSizeFields = ["Block count:", "Block size:"]
_resizefsUnit = MiB
@@ -1101,6 +1093,7 @@ class FATFS(FS):
_formattable = True
_maxSize = Size("1 TiB")
_packages = [ "dosfstools" ]
+ _readlabelClass = fsreadlabel.DosFSReadLabel
_defaultMountOptions = ["umask=0077", "shortname=winnt"]
_defaultCheckOptions = ["-n"]
# FIXME this should be fat32 in some cases
@@ -1255,6 +1248,7 @@ class XFS(FS):
_supported = True
_packages = ["xfsprogs"]
_infofs = "xfs_db"
+ _readlabelClass = fsreadlabel.XFSReadLabel
_defaultInfoOptions = ["-c", "sb 0", "-c", "p dblocks",
"-c", "p blocksize"]
_existingSizeFields = ["dblocks =", "blocksize ="]
@@ -1360,6 +1354,7 @@ class NTFS(FS):
_defaultCheckOptions = ["-c"]
_packages = ["ntfsprogs"]
_infofs = "ntfsinfo"
+ _readlabelClass = fsreadlabel.NTFSReadLabel
_defaultInfoOptions = ["-m"]
_existingSizeFields = ["Cluster Size:", "Volume Size in Clusters:"]
_resizefsUnit = B
diff --git a/tests/tasks_test/fslabeling.py b/tests/tasks_test/fslabeling.py
index 9c6dabb..6785133 100644
--- a/tests/tasks_test/fslabeling.py
+++ b/tests/tasks_test/fslabeling.py
@@ -4,7 +4,7 @@
from six import add_metaclass
from tests import loopbackedtestcase
-from blivet.errors import FSError
+from blivet.errors import FSError, FSReadLabelError
from blivet.size import Size
@add_metaclass(abc.ABCMeta)
@@ -40,7 +40,7 @@ def testLabeling(self):
an_fs = self._fs_class(device=self.loopDevices[0], label=self._invalid_label)
self.assertIsNone(an_fs.create())
- with self.assertRaisesRegexp(FSError, "no application to read label"):
+ with self.assertRaises(FSReadLabelError):
an_fs.readLabel()
an_fs.label = "an fs"
@@ -81,7 +81,7 @@ def testLabeling(self):
an_fs = self._fs_class(device=self.loopDevices[0], label=self._invalid_label)
self.assertIsNone(an_fs.create())
- with self.assertRaisesRegexp(FSError, "no application to read label"):
+ with self.assertRaises(FSReadLabelError):
an_fs.readLabel()
an_fs.label = "an fs"
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/02c68d324369dc5c87e64f0f83bf5dce884244b4
More information about the anaconda-patches
mailing list