[blivet:rhel7/master 06/10] Indicate whether the filesystem can label (#1038590)
mulhern
amulhern at redhat.com
Thu Jan 9 18:54:56 UTC 2014
Related: rhbz#1038590
The labeling() classmethod returns False if the filesystem can not be labeled.
This is really for external programs, that might prefer not to allow a user
to specify a label if nothing can be done with it.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/formats/__init__.py | 5 +++++
blivet/formats/fs.py | 25 ++++++++++++++++++++++---
blivet/formats/fslabel.py | 4 ++--
blivet/formats/swap.py | 5 +++++
tests/formats_test/misc_test.py | 11 ++++++-----
5 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 67ac996..1de00a6 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -217,6 +217,11 @@ class DeviceFormat(object):
"resizable": self.resizable}
return d
+ @classmethod
+ def labeling(cls):
+ """Returns False by default since most formats are non-labeling."""
+ return False
+
def _setOptions(self, options):
self._options = options
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index a1da021..716f43b 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -152,18 +152,37 @@ class FS(DeviceFormat):
"mountable": self.mountable})
return d
+ @classmethod
+ def labeling(cls):
+ """Returns True if this filesystem uses labels, otherwise False.
+
+ :rtype: bool
+ """
+ return cls._labelfs is not None
+
def _setLabel(self, label):
"""Sets the label for this filesystem.
:param label: the label for this filesystem
:type label: str or None
- Raises a FSError if this label is unacceptably formatted for this
- filesystem.
-
Note that some filesystems do not possess a label, so this method
always accept the value None for label.
+ Note also that some filesystems, even though they do not have a
+ labeling application may be already labeled, so we allow to set
+ the label of a filesystem even if a labeling application does not
+ exist. This can happen with the install media, for example, where
+ the filesystem on the CD has a label, but there is no labeling
+ application for the Iso9660FS format.
+
+ However, if a labeling application does exist, we require that
+ the label have the correct format for that application.
+
+ It is unlikely, but may be possible, that a filesystem may have
+ a label that the accepted labeling application will not accept.
+ In this case, this method will raise a FSError.
+
This method is not intended to be overridden.
"""
if label is None:
diff --git a/blivet/formats/fslabel.py b/blivet/formats/fslabel.py
index 8c7aa4b..0291ba4 100644
--- a/blivet/formats/fslabel.py
+++ b/blivet/formats/fslabel.py
@@ -1,5 +1,5 @@
# fslabel.py
-# Filesystem labelling classes for anaconda's storage configuration module.
+# Filesystem labeling classes for anaconda's storage configuration module.
#
# Copyright (C) 2009 Red Hat, Inc.
#
@@ -56,7 +56,7 @@ class FSLabelApp(object):
@abc.abstractmethod
def labelFormatOK(self, label):
"""Returns True if this label is correctly formatted for this
- filesystem labelling application, otherwise False.
+ filesystem labeling application, otherwise False.
:param str label: the label for this filesystem
:rtype: bool
diff --git a/blivet/formats/swap.py b/blivet/formats/swap.py
index da8f4df..5bfa9db 100644
--- a/blivet/formats/swap.py
+++ b/blivet/formats/swap.py
@@ -78,6 +78,11 @@ class SwapSpace(DeviceFormat):
d.update({"priority": self.priority, "label": self.label})
return d
+ @classmethod
+ def labeling(cls):
+ """Returns True as mkswap can write a label to the swap space."""
+ return True
+
def _setPriority(self, priority):
if priority is None:
self._priority = None
diff --git a/tests/formats_test/misc_test.py b/tests/formats_test/misc_test.py
index be2c976..195a45b 100755
--- a/tests/formats_test/misc_test.py
+++ b/tests/formats_test/misc_test.py
@@ -66,7 +66,7 @@ class MethodsTestCase(unittest.TestCase):
def setUp(self):
self.fs = {}
for k, v in device_formats.items():
- if issubclass(v, fs.FS) and not issubclass(v, fs.NFS):
+ if issubclass(v, fs.FS) and v.labeling():
self.fs[k] = v(device="/dev", label="myfs")
@@ -88,10 +88,11 @@ class MethodsTestCase(unittest.TestCase):
for k, v in [(k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in noflag_classes)]:
self.assertEqual(v._labelfs.setLabelCommand(v), [v._labelfs.name, "/dev", "myfs"], msg=k)
- # all of the remaining should have no labelfsProg
- omit_classes = [ fs.ReiserFS ] + lflag_classes + noflag_classes
- for k, v in [(k, v) for k, v in self.fs.items() if not any(isinstance(v, c) for c in omit_classes)]:
- self.assertIsNone(v.labelfsProg)
+ # all of the remaining are non-labeling so will accept any label
+ label = "Houston, we have a problem!"
+ for k, v in device_formats.items():
+ if issubclass(v, fs.FS) and not v.labeling() and not issubclass(v, fs.NFS):
+ self.assertEqual(v(device="/dev", label=label).label, label)
class LabelingAsRootTestCase(baseclass.DevicelibsTestCase):
"""Tests for labeling a filesystem and reading its label.
--
1.8.3.1
More information about the anaconda-patches
mailing list