[blivet:rhel7/master 2/4] Changes to _getLabelArgs and fields on which it depends (#1038590)

mulhern amulhern at redhat.com
Tue Dec 17 23:13:33 UTC 2013


Related: rhbz#1038590

* Added comments to FS._getLabelArgs
* Removed _defaultLabelOptions field and defaultLabelOptions property. The
property is only used in this file, and it is only used by _getLabelArgs.
The property is set from the field.
* Added some _getLabelArgs methods in some classes where the missing methods
caused an incorrect value.
* Simplified the _getLabelArgs methods to one liners that do not rely on
_defaultLabelOptions at all.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/fs.py            | 33 +++++++++++++++------------------
 tests/formats_test/misc_test.py | 13 ++++---------
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 340a6e3..7796625 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -124,7 +124,6 @@ class FS(DeviceFormat):
     _infofs = ""                         # fs info utility
     _defaultFormatOptions = []           # default options passed to mkfs
     _defaultMountOptions = ["defaults"]  # default options passed to mount
-    _defaultLabelOptions = []
     _defaultCheckOptions = []
     _defaultInfoOptions = []
     _existingSizeFields = []
@@ -630,10 +629,14 @@ class FS(DeviceFormat):
         self._mountpoint = None
 
     def _getLabelArgs(self, label):
-        argv = []
-        argv.extend(self.defaultLabelOptions)
-        argv.extend([self.device, label])
-        return argv 
+        """Get the arguments to pass to the application which labels
+           filesystems for this device.
+
+           :param str label: the label for this device
+           :return: a list of arguments
+           :rtype: list of str
+        """
+        return [self.device, label]
 
     def writeLabel(self, label):
         """ Create a label for this filesystem. """
@@ -741,12 +744,6 @@ class FS(DeviceFormat):
         return self._defaultMountOptions[:]
 
     @property
-    def defaultLabelOptions(self):
-        """ Default options passed to labeler for this filesystem type. """
-        # return a copy to prevent modification
-        return self._defaultLabelOptions[:]
-
-    @property
     def defaultCheckOptions(self):
         """ Default options passed to checker for this filesystem type. """
         # return a copy to prevent modification
@@ -1116,7 +1113,6 @@ class JFS(FS):
     _modules = ["jfs"]
     _labelfs = "jfs_tune"
     _defaultFormatOptions = ["-q"]
-    _defaultLabelOptions = ["-L"]
     _maxLabelChars = 16
     _maxSize = 8 * 1024 * 1024
     _formattable = True
@@ -1129,6 +1125,9 @@ class JFS(FS):
     _existingSizeFields = ["Aggregate block size:", "Aggregate size:"]
     partedSystem = fileSystemType["jfs"]
 
+    def _getLabelArgs(self, label):
+        return ["-L", label, self.device]
+
     @property
     def supported(self):
         """ Is this filesystem a supported type? """
@@ -1149,7 +1148,6 @@ class ReiserFS(FS):
     _labelfs = "reiserfstune"
     _modules = ["reiserfs"]
     _defaultFormatOptions = ["-f", "-f"]
-    _defaultLabelOptions = ["-l"]
     _maxLabelChars = 16
     _maxSize = 16 * 1024 * 1024
     _formattable = True
@@ -1163,6 +1161,9 @@ class ReiserFS(FS):
     _existingSizeFields = ["Count of blocks on the device:", "Blocksize:"]
     partedSystem = fileSystemType["reiserfs"]
 
+    def _getLabelArgs(self, label):
+        return ["-l", label, self.device]
+
     @property
     def supported(self):
         """ Is this filesystem a supported type? """
@@ -1187,7 +1188,6 @@ class XFS(FS):
     _modules = ["xfs"]
     _labelfs = "xfs_admin"
     _defaultFormatOptions = ["-f"]
-    _defaultLabelOptions = ["-L"]
     _maxLabelChars = 16
     _maxSize = 16 * 1024 * 1024 * 1024 * 1024
     _formattable = True
@@ -1203,10 +1203,7 @@ class XFS(FS):
     partedSystem = fileSystemType["xfs"]
 
     def _getLabelArgs(self, label):
-        argv = []
-        argv.extend(self.defaultLabelOptions)
-        argv.extend([label, self.device])
-        return argv
+        return ["-L", label, self.device]
 
     def sync(self, root='/'):
         """ Ensure that data we've written is at least in the journal.
diff --git a/tests/formats_test/misc_test.py b/tests/formats_test/misc_test.py
index 816f756..bcad51f 100755
--- a/tests/formats_test/misc_test.py
+++ b/tests/formats_test/misc_test.py
@@ -17,19 +17,14 @@ class MethodsTestCase(unittest.TestCase):
     def testGetLabelArgs(self):
         self.longMessage = True
 
-        # ReiserFS is currently backwards, needs the label after the l flag
+        # ReiserFS uses a -l flag
         for k, v in [(k, v) for k, v in self.fs.items() if isinstance(v, fs.ReiserFS)]:
-            self.assertEqual(v._getLabelArgs("myfs"), ["-l", "/dev", "myfs"], msg=k)
+            self.assertEqual(v._getLabelArgs("myfs"), ["-l", "myfs", "/dev"], msg=k)
 
-        # JFS is backward as well
-        for k, v in [(k, v) for k, v in self.fs.items() if isinstance(v, fs.JFS)]:
-            self.assertEqual(v._getLabelArgs("myfs"), ["-L", "/dev", "myfs"], msg=k)
-
-        #XFS uses a -L label
-        for k, v in [(k, v) for k, v in self.fs.items() if isinstance(v, fs.XFS)]:
+        # JFS, XFS use a -L flag
+        for k, v in [(k, v) for k, v in self.fs.items() if isinstance(v, fs.JFS) or isinstance(v, fs.XFS)]:
             self.assertEqual(v._getLabelArgs("myfs"), ["-L", "myfs", "/dev"], msg=k)
 
-
         # All NoDeviceFSs ignore the device argument passed and set device
         # to the fs type
         for k, v in [(k, v) for k, v in self.fs.items() if isinstance(v, fs.NoDevFS)]:
-- 
1.8.3.1



More information about the anaconda-patches mailing list