[master 5/30] Shuffle tasks into tasks directory.
mulkieran
installerbot-noreply at redhat.com
Thu Apr 16 20:41:19 UTC 2015
From: mulhern <amulhern at redhat.com>
Related: #12
Create a separate tasks test directory and shuffle some tests into that
directory.
---
blivet/formats/fs.py | 2 +-
blivet/formats/fslabel.py | 205 ------------------------------------
blivet/formats/fslabeling.py | 148 --------------------------
blivet/tasks/fslabel.py | 205 ++++++++++++++++++++++++++++++++++++
blivet/tasks/fslabeling.py | 148 ++++++++++++++++++++++++++
setup.py | 2 +-
tests/formats_test/fslabeling.py | 160 ----------------------------
tests/formats_test/labeling_test.py | 142 -------------------------
tests/tasks_test/__init__.py | 0
tests/tasks_test/fslabeling.py | 160 ++++++++++++++++++++++++++++
tests/tasks_test/labeling_test.py | 142 +++++++++++++++++++++++++
11 files changed, 657 insertions(+), 657 deletions(-)
delete mode 100644 blivet/formats/fslabel.py
delete mode 100644 blivet/formats/fslabeling.py
create mode 100644 blivet/tasks/fslabel.py
create mode 100644 blivet/tasks/fslabeling.py
delete mode 100644 tests/formats_test/fslabeling.py
delete mode 100755 tests/formats_test/labeling_test.py
create mode 100644 tests/tasks_test/__init__.py
create mode 100644 tests/tasks_test/fslabeling.py
create mode 100755 tests/tasks_test/labeling_test.py
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 3bb0ebe..289ff8b 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -26,7 +26,7 @@
import os
import tempfile
-from . import fslabeling
+from ..tasks import fslabeling
from ..errors import FormatCreateError, FSError, FSResizeError
from . import DeviceFormat, register_device_format
from .. import util
diff --git a/blivet/formats/fslabel.py b/blivet/formats/fslabel.py
deleted file mode 100644
index 81c18e6..0000000
--- a/blivet/formats/fslabel.py
+++ /dev/null
@@ -1,205 +0,0 @@
-# fslabel.py
-# Filesystem labeling classes for anaconda's storage configuration module.
-#
-# Copyright (C) 2013 Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use,
-# modify, copy, or redistribute it subject to the terms and conditions of
-# the GNU General Public License v.2, or (at your option) any later version.
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY expressed or implied, including the implied warranties of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-# Public License for more details. You should have received a copy of the
-# GNU General Public License along with this program; if not, write to the
-# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
-# source code or documentation are not subject to the GNU General Public
-# License and may only be used or replicated with the express permission of
-# Red Hat, Inc.
-#
-# Red Hat Author(s): Anne Mulhern <amulhern at redhat.com>
-
-import abc
-import re
-
-from six import add_metaclass
-
-from .. import errors
-
- at add_metaclass(abc.ABCMeta)
-class FSLabelApp(object):
- """An abstract class that represents actions associated with a
- filesystem's labeling application.
- """
-
- name = abc.abstractproperty(
- doc="The name of the filesystem labeling application.")
-
- reads = abc.abstractproperty(
- doc="Whether this application can read a label as well as write one.")
-
- _label_regex = abc.abstractproperty(
- doc="Matches the string output by the label reading application.")
-
- @abc.abstractmethod
- def _writeLabelArgs(self, fs):
- """Returns a list of the arguments for writing a label.
-
- :param FS fs: a filesystem object
-
- :return: the arguments
- :rtype: list of str
-
- It can be assumed in this function that fs.label is a str.
- """
- raise NotImplementedError
-
- def setLabelCommand(self, fs):
- """Get the command to label the filesystem.
-
- :param FS fs: a filesystem object
- :return: the command
- :rtype: list of str
-
- Raises an exception if fs.label is None.
- """
- if fs.label is None:
- raise errors.FSError("makes no sense to write a label when accepting default label")
- return [self.name] + self._writeLabelArgs(fs)
-
- @abc.abstractmethod
- def _readLabelArgs(self, fs):
- """Returns a list of arguments for reading a label.
-
- :param FS fs: a filesystem object
- :return: the arguments
- :rtype: list of str
- """
- raise NotImplementedError
-
- def readLabelCommand(self, fs):
- """Get the command to read the filesystem label.
-
- :param FS fs: a filesystem object
- :return: the command
- :rtype: list of str
-
- Raises an FSError if this application can not read the label.
- """
- if not self.reads:
- raise errors.FSError("Application %s can not read the filesystem label." % self.name)
- return [self.name] + self._readLabelArgs(fs)
-
- def extractLabel(self, labelstr):
- """Extract the label from an output string.
-
- :param str labelstr: the string containing the label information
-
- :return: the label
- :rtype: str
-
- Raises an FSError if the label can not be extracted.
- """
- if not self.reads or self._label_regex is None:
- raise errors.FSError("Unknown format for application %s" % self.name)
- match = re.match(self._label_regex, labelstr)
- if match is None:
- raise errors.FSError("Unknown format for application %s" % self.name)
- return match.group('label')
-
-
-class E2Label(FSLabelApp):
- """Application used by ext2 and its descendants."""
-
- name = "e2label"
- reads = True
-
- _label_regex = r'(?P<label>.*)'
-
- def _writeLabelArgs(self, fs):
- return [fs.device, fs.label]
-
- def _readLabelArgs(self, fs):
- return [fs.device]
-
-E2Label = E2Label()
-
-class DosFsLabel(FSLabelApp):
- """Application used by FATFS."""
-
- name = "dosfslabel"
- reads = True
-
- _label_regex = r'(?P<label>.*)'
-
- def _writeLabelArgs(self, fs):
- return [fs.device, fs.label]
-
- def _readLabelArgs(self, fs):
- return [fs.device]
-
-DosFsLabel = DosFsLabel()
-
-class JFSTune(FSLabelApp):
- """Application used by JFS."""
-
- name = "jfs_tune"
- reads = False
-
- _label_regex = property(lambda s: None)
-
- def _writeLabelArgs(self, fs):
- return ["-L", fs.label, fs.device]
-
- def _readLabelArgs(self, fs):
- raise NotImplementedError
-
-JFSTune = JFSTune()
-
-class ReiserFSTune(FSLabelApp):
- """Application used by ReiserFS."""
-
- name = "reiserfstune"
- reads = False
-
- _label_regex = None
-
- def _writeLabelArgs(self, fs):
- return ["-l", fs.label, fs.device]
-
- def _readLabelArgs(self, fs):
- raise NotImplementedError
-
-ReiserFSTune = ReiserFSTune()
-
-class XFSAdmin(FSLabelApp):
- """Application used by XFS."""
-
- name = "xfs_admin"
- reads = True
-
- _label_regex = r'label = "(?P<label>.*)"'
-
- def _writeLabelArgs(self, fs):
- return ["-L", fs.label if fs.label != "" else "--", fs.device]
-
- def _readLabelArgs(self, fs):
- return ["-l", fs.device]
-
-XFSAdmin = XFSAdmin()
-
-class NTFSLabel(FSLabelApp):
- """Application used by NTFS."""
-
- name = "ntfslabel"
- reads = True
-
- _label_regex = r'(?P<label>.*)'
-
- def _writeLabelArgs(self, fs):
- return [fs.device, fs.label]
-
- def _readLabelArgs(self, fs):
- return [fs.device]
-
-NTFSLabel = NTFSLabel()
diff --git a/blivet/formats/fslabeling.py b/blivet/formats/fslabeling.py
deleted file mode 100644
index 0abeaf7..0000000
--- a/blivet/formats/fslabeling.py
+++ /dev/null
@@ -1,148 +0,0 @@
-# fslabeling.py
-# Filesystem labeling classes for anaconda's storage configuration module.
-#
-# Copyright (C) 2014 Red Hat, Inc.
-#
-# This copyrighted material is made available to anyone wishing to use,
-# modify, copy, or redistribute it subject to the terms and conditions of
-# the GNU General Public License v.2, or (at your option) any later version.
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY expressed or implied, including the implied warranties of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-# Public License for more details. You should have received a copy of the
-# GNU General Public License along with this program; if not, write to the
-# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
-# source code or documentation are not subject to the GNU General Public
-# License and may only be used or replicated with the express permission of
-# Red Hat, Inc.
-#
-# Red Hat Author(s): Anne Mulhern <amulhern at redhat.com>
-
-import abc
-
-from six import add_metaclass
-
-from . import fslabel
-
- at add_metaclass(abc.ABCMeta)
-class FSLabeling(object):
- """An abstract class that represents filesystem labeling actions.
- """
-
- default_label = abc.abstractproperty(
- doc="Default label set on this filesystem at creation.")
-
- label_app = abc.abstractproperty(
- doc="Post creation filesystem labeling application.")
-
- @abc.abstractmethod
- def labelFormatOK(self, label):
- """Returns True if this label is correctly formatted for this
- filesystem, otherwise False.
-
- :param str label: the label for this filesystem
- :rtype: bool
- """
- raise NotImplementedError
-
- @abc.abstractmethod
- def labelingArgs(self, label):
- """Returns the arguments for writing the label during filesystem
- creation. These arguments are intended to be passed to the
- appropriate mkfs application.
-
- :param str label: the label to use
- :return: the arguments
- :rtype: list of str
- """
- raise NotImplementedError
-
-
-class Ext2FSLabeling(FSLabeling):
-
- default_label = ""
- label_app = fslabel.E2Label
-
- def labelFormatOK(self, label):
- return len(label) < 17
-
- def labelingArgs(self, label):
- return ["-L", label]
-
-class FATFSLabeling(FSLabeling):
-
- default_label = "NO NAME"
- label_app = fslabel.DosFsLabel
-
- def labelFormatOK(self, label):
- return len(label) < 12
-
- def labelingArgs(self, label):
- return ["-n", label]
-
-class JFSLabeling(FSLabeling):
-
- default_label = ""
- label_app = fslabel.JFSTune
-
- def labelFormatOK(self, label):
- return len(label) < 17
-
- def labelingArgs(self, label):
- return ["-L", label]
-
-class ReiserFSLabeling(FSLabeling):
-
- default_label = ""
- label_app = fslabel.ReiserFSTune
-
- def labelFormatOK(self, label):
- return len(label) < 17
-
- def labelingArgs(self, label):
- return ["-l", label]
-
-class XFSLabeling(FSLabeling):
-
- default_label = ""
- label_app = fslabel.XFSAdmin
-
- def labelFormatOK(self, label):
- return ' ' not in label and len(label) < 13
-
- def labelingArgs(self, label):
- return ["-L", label]
-
-class HFSLabeling(FSLabeling):
-
- default_label = "Untitled"
- label_app = None
-
- def labelFormatOK(self, label):
- return ':' not in label and len(label) < 28 and len(label) > 0
-
- def labelingArgs(self, label):
- return ["-l", label]
-
-class HFSPlusLabeling(FSLabeling):
-
- default_label = "Untitled"
- label_app = None
-
- def labelFormatOK(self, label):
- return ':' not in label and 0 < len(label) < 129
-
- def labelingArgs(self, label):
- return ["-v", label]
-
-class NTFSLabeling(FSLabeling):
-
- default_label = ""
- label_app = fslabel.NTFSLabel
-
- def labelFormatOK(self, label):
- return len(label) < 129
-
- def labelingArgs(self, label):
- return ["-L", label]
diff --git a/blivet/tasks/fslabel.py b/blivet/tasks/fslabel.py
new file mode 100644
index 0000000..81c18e6
--- /dev/null
+++ b/blivet/tasks/fslabel.py
@@ -0,0 +1,205 @@
+# fslabel.py
+# Filesystem labeling classes for anaconda's storage configuration module.
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Anne Mulhern <amulhern at redhat.com>
+
+import abc
+import re
+
+from six import add_metaclass
+
+from .. import errors
+
+ at add_metaclass(abc.ABCMeta)
+class FSLabelApp(object):
+ """An abstract class that represents actions associated with a
+ filesystem's labeling application.
+ """
+
+ name = abc.abstractproperty(
+ doc="The name of the filesystem labeling application.")
+
+ reads = abc.abstractproperty(
+ doc="Whether this application can read a label as well as write one.")
+
+ _label_regex = abc.abstractproperty(
+ doc="Matches the string output by the label reading application.")
+
+ @abc.abstractmethod
+ def _writeLabelArgs(self, fs):
+ """Returns a list of the arguments for writing a label.
+
+ :param FS fs: a filesystem object
+
+ :return: the arguments
+ :rtype: list of str
+
+ It can be assumed in this function that fs.label is a str.
+ """
+ raise NotImplementedError
+
+ def setLabelCommand(self, fs):
+ """Get the command to label the filesystem.
+
+ :param FS fs: a filesystem object
+ :return: the command
+ :rtype: list of str
+
+ Raises an exception if fs.label is None.
+ """
+ if fs.label is None:
+ raise errors.FSError("makes no sense to write a label when accepting default label")
+ return [self.name] + self._writeLabelArgs(fs)
+
+ @abc.abstractmethod
+ def _readLabelArgs(self, fs):
+ """Returns a list of arguments for reading a label.
+
+ :param FS fs: a filesystem object
+ :return: the arguments
+ :rtype: list of str
+ """
+ raise NotImplementedError
+
+ def readLabelCommand(self, fs):
+ """Get the command to read the filesystem label.
+
+ :param FS fs: a filesystem object
+ :return: the command
+ :rtype: list of str
+
+ Raises an FSError if this application can not read the label.
+ """
+ if not self.reads:
+ raise errors.FSError("Application %s can not read the filesystem label." % self.name)
+ return [self.name] + self._readLabelArgs(fs)
+
+ def extractLabel(self, labelstr):
+ """Extract the label from an output string.
+
+ :param str labelstr: the string containing the label information
+
+ :return: the label
+ :rtype: str
+
+ Raises an FSError if the label can not be extracted.
+ """
+ if not self.reads or self._label_regex is None:
+ raise errors.FSError("Unknown format for application %s" % self.name)
+ match = re.match(self._label_regex, labelstr)
+ if match is None:
+ raise errors.FSError("Unknown format for application %s" % self.name)
+ return match.group('label')
+
+
+class E2Label(FSLabelApp):
+ """Application used by ext2 and its descendants."""
+
+ name = "e2label"
+ reads = True
+
+ _label_regex = r'(?P<label>.*)'
+
+ def _writeLabelArgs(self, fs):
+ return [fs.device, fs.label]
+
+ def _readLabelArgs(self, fs):
+ return [fs.device]
+
+E2Label = E2Label()
+
+class DosFsLabel(FSLabelApp):
+ """Application used by FATFS."""
+
+ name = "dosfslabel"
+ reads = True
+
+ _label_regex = r'(?P<label>.*)'
+
+ def _writeLabelArgs(self, fs):
+ return [fs.device, fs.label]
+
+ def _readLabelArgs(self, fs):
+ return [fs.device]
+
+DosFsLabel = DosFsLabel()
+
+class JFSTune(FSLabelApp):
+ """Application used by JFS."""
+
+ name = "jfs_tune"
+ reads = False
+
+ _label_regex = property(lambda s: None)
+
+ def _writeLabelArgs(self, fs):
+ return ["-L", fs.label, fs.device]
+
+ def _readLabelArgs(self, fs):
+ raise NotImplementedError
+
+JFSTune = JFSTune()
+
+class ReiserFSTune(FSLabelApp):
+ """Application used by ReiserFS."""
+
+ name = "reiserfstune"
+ reads = False
+
+ _label_regex = None
+
+ def _writeLabelArgs(self, fs):
+ return ["-l", fs.label, fs.device]
+
+ def _readLabelArgs(self, fs):
+ raise NotImplementedError
+
+ReiserFSTune = ReiserFSTune()
+
+class XFSAdmin(FSLabelApp):
+ """Application used by XFS."""
+
+ name = "xfs_admin"
+ reads = True
+
+ _label_regex = r'label = "(?P<label>.*)"'
+
+ def _writeLabelArgs(self, fs):
+ return ["-L", fs.label if fs.label != "" else "--", fs.device]
+
+ def _readLabelArgs(self, fs):
+ return ["-l", fs.device]
+
+XFSAdmin = XFSAdmin()
+
+class NTFSLabel(FSLabelApp):
+ """Application used by NTFS."""
+
+ name = "ntfslabel"
+ reads = True
+
+ _label_regex = r'(?P<label>.*)'
+
+ def _writeLabelArgs(self, fs):
+ return [fs.device, fs.label]
+
+ def _readLabelArgs(self, fs):
+ return [fs.device]
+
+NTFSLabel = NTFSLabel()
diff --git a/blivet/tasks/fslabeling.py b/blivet/tasks/fslabeling.py
new file mode 100644
index 0000000..0abeaf7
--- /dev/null
+++ b/blivet/tasks/fslabeling.py
@@ -0,0 +1,148 @@
+# fslabeling.py
+# Filesystem labeling classes for anaconda's storage configuration module.
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): Anne Mulhern <amulhern at redhat.com>
+
+import abc
+
+from six import add_metaclass
+
+from . import fslabel
+
+ at add_metaclass(abc.ABCMeta)
+class FSLabeling(object):
+ """An abstract class that represents filesystem labeling actions.
+ """
+
+ default_label = abc.abstractproperty(
+ doc="Default label set on this filesystem at creation.")
+
+ label_app = abc.abstractproperty(
+ doc="Post creation filesystem labeling application.")
+
+ @abc.abstractmethod
+ def labelFormatOK(self, label):
+ """Returns True if this label is correctly formatted for this
+ filesystem, otherwise False.
+
+ :param str label: the label for this filesystem
+ :rtype: bool
+ """
+ raise NotImplementedError
+
+ @abc.abstractmethod
+ def labelingArgs(self, label):
+ """Returns the arguments for writing the label during filesystem
+ creation. These arguments are intended to be passed to the
+ appropriate mkfs application.
+
+ :param str label: the label to use
+ :return: the arguments
+ :rtype: list of str
+ """
+ raise NotImplementedError
+
+
+class Ext2FSLabeling(FSLabeling):
+
+ default_label = ""
+ label_app = fslabel.E2Label
+
+ def labelFormatOK(self, label):
+ return len(label) < 17
+
+ def labelingArgs(self, label):
+ return ["-L", label]
+
+class FATFSLabeling(FSLabeling):
+
+ default_label = "NO NAME"
+ label_app = fslabel.DosFsLabel
+
+ def labelFormatOK(self, label):
+ return len(label) < 12
+
+ def labelingArgs(self, label):
+ return ["-n", label]
+
+class JFSLabeling(FSLabeling):
+
+ default_label = ""
+ label_app = fslabel.JFSTune
+
+ def labelFormatOK(self, label):
+ return len(label) < 17
+
+ def labelingArgs(self, label):
+ return ["-L", label]
+
+class ReiserFSLabeling(FSLabeling):
+
+ default_label = ""
+ label_app = fslabel.ReiserFSTune
+
+ def labelFormatOK(self, label):
+ return len(label) < 17
+
+ def labelingArgs(self, label):
+ return ["-l", label]
+
+class XFSLabeling(FSLabeling):
+
+ default_label = ""
+ label_app = fslabel.XFSAdmin
+
+ def labelFormatOK(self, label):
+ return ' ' not in label and len(label) < 13
+
+ def labelingArgs(self, label):
+ return ["-L", label]
+
+class HFSLabeling(FSLabeling):
+
+ default_label = "Untitled"
+ label_app = None
+
+ def labelFormatOK(self, label):
+ return ':' not in label and len(label) < 28 and len(label) > 0
+
+ def labelingArgs(self, label):
+ return ["-l", label]
+
+class HFSPlusLabeling(FSLabeling):
+
+ default_label = "Untitled"
+ label_app = None
+
+ def labelFormatOK(self, label):
+ return ':' not in label and 0 < len(label) < 129
+
+ def labelingArgs(self, label):
+ return ["-v", label]
+
+class NTFSLabeling(FSLabeling):
+
+ default_label = ""
+ label_app = fslabel.NTFSLabel
+
+ def labelFormatOK(self, label):
+ return len(label) < 129
+
+ def labelingArgs(self, label):
+ return ["-L", label]
diff --git a/setup.py b/setup.py
index 83a23ff..e7ac91c 100644
--- a/setup.py
+++ b/setup.py
@@ -36,4 +36,4 @@ def add_member_order_option(files):
author='David Lehman', author_email='dlehman at redhat.com',
url='http://fedoraproject.org/wiki/blivet',
data_files=data_files,
- packages=['blivet', 'blivet.devices', 'blivet.devicelibs', 'blivet.formats'])
+ packages=['blivet', 'blivet.devices', 'blivet.devicelibs', 'blivet.formats', 'blivet.tasks'])
diff --git a/tests/formats_test/fslabeling.py b/tests/formats_test/fslabeling.py
deleted file mode 100644
index 9c6dabb..0000000
--- a/tests/formats_test/fslabeling.py
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/python
-
-import abc
-from six import add_metaclass
-
-from tests import loopbackedtestcase
-from blivet.errors import FSError
-from blivet.size import Size
-
- at add_metaclass(abc.ABCMeta)
-class LabelingAsRoot(loopbackedtestcase.LoopBackedTestCase):
- """Tests various aspects of labeling a filesystem where there
- is no easy way to read the filesystem's label once it has been
- set and where the filesystem can not be relabeled.
- """
-
-
- _fs_class = abc.abstractproperty(
- doc="The class of the filesystem being tested on.")
-
- _invalid_label = abc.abstractproperty(
- doc="A label which is invalid for this filesystem.")
-
- def __init__(self, methodName='runTest'):
- super(LabelingAsRoot, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB")])
-
- def setUp(self):
- an_fs = self._fs_class()
- if not an_fs.utilsAvailable:
- self.skipTest("utilities unavailable for filesystem %s" % an_fs.name)
- super(LabelingAsRoot, self).setUp()
-
- def testLabeling(self):
- """A sequence of tests of filesystem labeling.
-
- * create the filesystem when passing an invalid label
- * raise an exception when reading the filesystem
- * raise an exception when relabeling the filesystem
- """
- 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"):
- an_fs.readLabel()
-
- an_fs.label = "an fs"
- with self.assertRaisesRegexp(FSError, "no application to set label for filesystem"):
- an_fs.writeLabel()
-
- def testCreating(self):
- """Create the filesystem when passing a valid label """
- an_fs = self._fs_class(device=self.loopDevices[0], label="start")
- self.assertIsNone(an_fs.create())
-
- def testCreatingNone(self):
- """Create the filesystem when passing None
- (indicates filesystem default)
- """
- an_fs = self._fs_class(device=self.loopDevices[0], label=None)
- self.assertIsNone(an_fs.create())
-
- def testCreatingEmpty(self):
- """Create the filesystem when passing the empty label."""
- an_fs = self._fs_class(device=self.loopDevices[0], label="")
- self.assertIsNone(an_fs.create())
-
-class LabelingWithRelabeling(LabelingAsRoot):
- """Tests labeling where it is possible to relabel.
- """
-
- def testLabeling(self):
- """A sequence of tests of filesystem labeling.
-
- * create the filesystem when passing an invalid label
- * raise an exception when reading the filesystem
- * relabel the filesystem with a valid label
- * relabel the filesystem with an empty label
- * raise an exception when relabeling when None is specified
- * raise an exception when relabeling with an invalid label
- """
- 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"):
- an_fs.readLabel()
-
- an_fs.label = "an fs"
- self.assertIsNone(an_fs.writeLabel())
-
- an_fs.label = ""
- self.assertIsNone(an_fs.writeLabel())
-
- an_fs.label = None
- with self.assertRaisesRegexp(FSError, "default label"):
- an_fs.writeLabel()
-
- an_fs.label = self._invalid_label
- with self.assertRaisesRegexp(FSError, "bad label format"):
- an_fs.writeLabel()
-
-class CompleteLabelingAsRoot(LabelingAsRoot):
- """Tests where it is possible to read the label and to relabel
- an existing filesystem.
- """
-
- def testLabeling(self):
- """A sequence of tests of filesystem labeling.
-
- * create the filesystem when passing an invalid label
- and verify that the filesystem has the default label
- * relabel the filesystem with a valid label
- and verify that the filesystem has that label
- * relabel the filesystem with an empty label
- and verify that the filesystem has that label
- * raise an exception when relabeling when None is specified
- * raise an exception when relabeling with an invalid label
- """
- an_fs = self._fs_class(device=self.loopDevices[0], label=self._invalid_label)
- self.assertIsNone(an_fs.create())
- self.assertEqual(an_fs.readLabel(), an_fs._labelfs.default_label)
-
- an_fs.label = "an_fs"
- self.assertIsNone(an_fs.writeLabel())
- self.assertEqual(an_fs.readLabel(), an_fs.label)
-
- an_fs.label = ""
- self.assertIsNone(an_fs.writeLabel())
- self.assertEqual(an_fs.readLabel(), an_fs.label)
-
- an_fs.label = None
- with self.assertRaisesRegexp(FSError, "default label"):
- an_fs.writeLabel()
-
- an_fs.label = "n" * 129
- with self.assertRaisesRegexp(FSError, "bad label format"):
- an_fs.writeLabel()
-
- def testCreating(self):
- """Create the filesystem when passing a valid label.
- Verify that the filesystem has that label.
- """
- an_fs = self._fs_class(device=self.loopDevices[0], label="start")
- self.assertIsNone(an_fs.create())
- self.assertEqual(an_fs.readLabel(), "start")
-
- def testCreatingNone(self):
- """Create a filesystem with the label None.
- Verify that the filesystem has the default label.
- """
- an_fs = self._fs_class(device=self.loopDevices[0], label=None)
- self.assertIsNone(an_fs.create())
- self.assertEqual(an_fs.readLabel(), an_fs._labelfs.default_label)
-
- def testCreatingEmpty(self):
- """Create a filesystem with an empty label.
- Verify that the filesystem has the empty label.
- """
- an_fs = self._fs_class(device=self.loopDevices[0], label="")
- self.assertIsNone(an_fs.create())
- self.assertEqual(an_fs.readLabel(), "")
diff --git a/tests/formats_test/labeling_test.py b/tests/formats_test/labeling_test.py
deleted file mode 100755
index dfa6e79..0000000
--- a/tests/formats_test/labeling_test.py
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/usr/bin/python
-import unittest
-
-from tests import loopbackedtestcase
-from blivet.formats import device_formats
-import blivet.formats.fs as fs
-import blivet.formats.swap as swap
-
-from . import fslabeling
-
-class InitializationTestCase(unittest.TestCase):
- """Test FS object initialization."""
-
- def testLabels(self):
- """Initialize some filesystems with valid and invalid labels."""
-
- # Ext2FS has a maximum length of 16
- self.assertFalse(fs.Ext2FS().labelFormatOK("root___filesystem"))
- self.assertTrue(fs.Ext2FS().labelFormatOK("root__filesystem"))
-
- # FATFS has a maximum length of 11
- self.assertFalse(fs.FATFS().labelFormatOK("rtfilesystem"))
- self.assertTrue(fs.FATFS().labelFormatOK("rfilesystem"))
-
- # JFS has a maximum length of 16
- self.assertFalse(fs.JFS().labelFormatOK("root___filesystem"))
- self.assertTrue(fs.JFS().labelFormatOK("root__filesystem"))
-
- # ReiserFS has a maximum length of 16
- self.assertFalse(fs.ReiserFS().labelFormatOK("root___filesystem"))
- self.assertTrue(fs.ReiserFS().labelFormatOK("root__filesystem"))
-
- #XFS has a maximum length 12 and does not allow spaces
- self.assertFalse(fs.XFS().labelFormatOK("root_filesyst"))
- self.assertFalse(fs.XFS().labelFormatOK("root file"))
- self.assertTrue(fs.XFS().labelFormatOK("root_filesys"))
-
- #HFS has a maximum length of 27, minimum length of 1, and does not allow colons
- self.assertFalse(fs.HFS().labelFormatOK("n" * 28))
- self.assertFalse(fs.HFS().labelFormatOK("root:file"))
- self.assertFalse(fs.HFS().labelFormatOK(""))
- self.assertTrue(fs.HFS().labelFormatOK("n" * 27))
-
- #HFSPlus has a maximum length of 128, minimum length of 1, and does not allow colons
- self.assertFalse(fs.HFSPlus().labelFormatOK("n" * 129))
- self.assertFalse(fs.HFSPlus().labelFormatOK("root:file"))
- self.assertFalse(fs.HFSPlus().labelFormatOK(""))
- self.assertTrue(fs.HFSPlus().labelFormatOK("n" * 128))
-
- # NTFS has a maximum length of 128
- self.assertFalse(fs.NTFS().labelFormatOK("n" * 129))
- self.assertTrue(fs.NTFS().labelFormatOK("n" * 128))
-
- # all devices are permitted to be passed a label argument of None
- # some will ignore it completely
- for _k, v in device_formats.items():
- self.assertIsNotNone(v(label=None))
-
-class MethodsTestCase(unittest.TestCase):
- """Test some methods that do not require actual images."""
-
- def setUp(self):
- self.fs = {}
- for k, v in device_formats.items():
- if issubclass(v, fs.FS) and v().labeling():
- self.fs[k] = v(device="/dev", label="myfs")
-
-
- def testGetLabelArgs(self):
- self.longMessage = True
-
- # ReiserFS uses a -l flag
- reiserfs = self.fs["reiserfs"]
- self.assertEqual(reiserfs._labelfs.label_app.setLabelCommand(reiserfs),
- ["reiserfstune", "-l", "myfs", "/dev"], msg="reiserfs")
-
- # JFS, XFS use a -L flag
- lflag_classes = [fs.JFS, fs.XFS]
- for name, klass in ((k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in lflag_classes)):
- self.assertEqual(klass._labelfs.label_app.setLabelCommand(klass), [klass._labelfs.label_app.name, "-L", "myfs", "/dev"], msg=name)
-
- # Ext2FS and descendants and FATFS do not use a flag
- noflag_classes = [fs.Ext2FS, fs.FATFS]
- for name, klass in ((k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in noflag_classes)):
- self.assertEqual(klass._labelfs.label_app.setLabelCommand(klass), [klass._labelfs.label_app.name, "/dev", "myfs"], msg=name)
-
- # all of the remaining are non-labeling so will accept any label
- label = "Houston, we have a problem!"
- for name, klass in device_formats.items():
- if issubclass(klass, fs.FS) and not klass().labeling() and not issubclass(klass, fs.NFS):
- self.assertEqual(klass(device="/dev", label=label).label, label, msg=name)
-
-class XFSTestCase(fslabeling.CompleteLabelingAsRoot):
- _fs_class = fs.XFS
- _invalid_label = "root filesystem"
-
-class FATFSTestCase(fslabeling.CompleteLabelingAsRoot):
- _fs_class = fs.FATFS
- _invalid_label = "root___filesystem"
-
-class Ext2FSTestCase(fslabeling.CompleteLabelingAsRoot):
- _fs_class = fs.Ext2FS
- _invalid_label = "root___filesystem"
-
-class JFSTestCase(fslabeling.LabelingWithRelabeling):
- _fs_class = fs.JFS
- _invalid_label = "root___filesystem"
-
-class ReiserFSTestCase(fslabeling.LabelingWithRelabeling):
- _fs_class = fs.ReiserFS
- _invalid_label = "root___filesystem"
-
-class HFSTestCase(fslabeling.LabelingAsRoot):
- _fs_class = fs.HFS
- _invalid_label = "n" * 28
-
-class HFSPlusTestCase(fslabeling.LabelingAsRoot):
- _fs_class = fs.HFSPlus
- _invalid_label = "n" * 129
-
- at unittest.skip("Unable to create NTFS filesystem.")
-class NTFSTestCase(fslabeling.CompleteLabelingAsRoot):
- _fs_class = fs.NTFS
- _invalid_label = "n" * 129
-
-class LabelingSwapSpaceTestCase(loopbackedtestcase.LoopBackedTestCase):
-
- def testLabeling(self):
- swp = swap.SwapSpace(device=self.loopDevices[0])
- swp.label = "mkswap is really pretty permissive about labels"
- self.assertIsNone(swp.create())
-
- def testCreatingSwapSpaceNone(self):
- swp = swap.SwapSpace(device=self.loopDevices[0], label=None)
- self.assertIsNone(swp.create())
-
- def testCreatingSwapSpaceEmpty(self):
- swp = swap.SwapSpace(device=self.loopDevices[0], label="")
- self.assertIsNone(swp.create())
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/tests/tasks_test/__init__.py b/tests/tasks_test/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/tasks_test/fslabeling.py b/tests/tasks_test/fslabeling.py
new file mode 100644
index 0000000..9c6dabb
--- /dev/null
+++ b/tests/tasks_test/fslabeling.py
@@ -0,0 +1,160 @@
+#!/usr/bin/python
+
+import abc
+from six import add_metaclass
+
+from tests import loopbackedtestcase
+from blivet.errors import FSError
+from blivet.size import Size
+
+ at add_metaclass(abc.ABCMeta)
+class LabelingAsRoot(loopbackedtestcase.LoopBackedTestCase):
+ """Tests various aspects of labeling a filesystem where there
+ is no easy way to read the filesystem's label once it has been
+ set and where the filesystem can not be relabeled.
+ """
+
+
+ _fs_class = abc.abstractproperty(
+ doc="The class of the filesystem being tested on.")
+
+ _invalid_label = abc.abstractproperty(
+ doc="A label which is invalid for this filesystem.")
+
+ def __init__(self, methodName='runTest'):
+ super(LabelingAsRoot, self).__init__(methodName=methodName, deviceSpec=[Size("100 MiB")])
+
+ def setUp(self):
+ an_fs = self._fs_class()
+ if not an_fs.utilsAvailable:
+ self.skipTest("utilities unavailable for filesystem %s" % an_fs.name)
+ super(LabelingAsRoot, self).setUp()
+
+ def testLabeling(self):
+ """A sequence of tests of filesystem labeling.
+
+ * create the filesystem when passing an invalid label
+ * raise an exception when reading the filesystem
+ * raise an exception when relabeling the filesystem
+ """
+ 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"):
+ an_fs.readLabel()
+
+ an_fs.label = "an fs"
+ with self.assertRaisesRegexp(FSError, "no application to set label for filesystem"):
+ an_fs.writeLabel()
+
+ def testCreating(self):
+ """Create the filesystem when passing a valid label """
+ an_fs = self._fs_class(device=self.loopDevices[0], label="start")
+ self.assertIsNone(an_fs.create())
+
+ def testCreatingNone(self):
+ """Create the filesystem when passing None
+ (indicates filesystem default)
+ """
+ an_fs = self._fs_class(device=self.loopDevices[0], label=None)
+ self.assertIsNone(an_fs.create())
+
+ def testCreatingEmpty(self):
+ """Create the filesystem when passing the empty label."""
+ an_fs = self._fs_class(device=self.loopDevices[0], label="")
+ self.assertIsNone(an_fs.create())
+
+class LabelingWithRelabeling(LabelingAsRoot):
+ """Tests labeling where it is possible to relabel.
+ """
+
+ def testLabeling(self):
+ """A sequence of tests of filesystem labeling.
+
+ * create the filesystem when passing an invalid label
+ * raise an exception when reading the filesystem
+ * relabel the filesystem with a valid label
+ * relabel the filesystem with an empty label
+ * raise an exception when relabeling when None is specified
+ * raise an exception when relabeling with an invalid label
+ """
+ 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"):
+ an_fs.readLabel()
+
+ an_fs.label = "an fs"
+ self.assertIsNone(an_fs.writeLabel())
+
+ an_fs.label = ""
+ self.assertIsNone(an_fs.writeLabel())
+
+ an_fs.label = None
+ with self.assertRaisesRegexp(FSError, "default label"):
+ an_fs.writeLabel()
+
+ an_fs.label = self._invalid_label
+ with self.assertRaisesRegexp(FSError, "bad label format"):
+ an_fs.writeLabel()
+
+class CompleteLabelingAsRoot(LabelingAsRoot):
+ """Tests where it is possible to read the label and to relabel
+ an existing filesystem.
+ """
+
+ def testLabeling(self):
+ """A sequence of tests of filesystem labeling.
+
+ * create the filesystem when passing an invalid label
+ and verify that the filesystem has the default label
+ * relabel the filesystem with a valid label
+ and verify that the filesystem has that label
+ * relabel the filesystem with an empty label
+ and verify that the filesystem has that label
+ * raise an exception when relabeling when None is specified
+ * raise an exception when relabeling with an invalid label
+ """
+ an_fs = self._fs_class(device=self.loopDevices[0], label=self._invalid_label)
+ self.assertIsNone(an_fs.create())
+ self.assertEqual(an_fs.readLabel(), an_fs._labelfs.default_label)
+
+ an_fs.label = "an_fs"
+ self.assertIsNone(an_fs.writeLabel())
+ self.assertEqual(an_fs.readLabel(), an_fs.label)
+
+ an_fs.label = ""
+ self.assertIsNone(an_fs.writeLabel())
+ self.assertEqual(an_fs.readLabel(), an_fs.label)
+
+ an_fs.label = None
+ with self.assertRaisesRegexp(FSError, "default label"):
+ an_fs.writeLabel()
+
+ an_fs.label = "n" * 129
+ with self.assertRaisesRegexp(FSError, "bad label format"):
+ an_fs.writeLabel()
+
+ def testCreating(self):
+ """Create the filesystem when passing a valid label.
+ Verify that the filesystem has that label.
+ """
+ an_fs = self._fs_class(device=self.loopDevices[0], label="start")
+ self.assertIsNone(an_fs.create())
+ self.assertEqual(an_fs.readLabel(), "start")
+
+ def testCreatingNone(self):
+ """Create a filesystem with the label None.
+ Verify that the filesystem has the default label.
+ """
+ an_fs = self._fs_class(device=self.loopDevices[0], label=None)
+ self.assertIsNone(an_fs.create())
+ self.assertEqual(an_fs.readLabel(), an_fs._labelfs.default_label)
+
+ def testCreatingEmpty(self):
+ """Create a filesystem with an empty label.
+ Verify that the filesystem has the empty label.
+ """
+ an_fs = self._fs_class(device=self.loopDevices[0], label="")
+ self.assertIsNone(an_fs.create())
+ self.assertEqual(an_fs.readLabel(), "")
diff --git a/tests/tasks_test/labeling_test.py b/tests/tasks_test/labeling_test.py
new file mode 100755
index 0000000..dfa6e79
--- /dev/null
+++ b/tests/tasks_test/labeling_test.py
@@ -0,0 +1,142 @@
+#!/usr/bin/python
+import unittest
+
+from tests import loopbackedtestcase
+from blivet.formats import device_formats
+import blivet.formats.fs as fs
+import blivet.formats.swap as swap
+
+from . import fslabeling
+
+class InitializationTestCase(unittest.TestCase):
+ """Test FS object initialization."""
+
+ def testLabels(self):
+ """Initialize some filesystems with valid and invalid labels."""
+
+ # Ext2FS has a maximum length of 16
+ self.assertFalse(fs.Ext2FS().labelFormatOK("root___filesystem"))
+ self.assertTrue(fs.Ext2FS().labelFormatOK("root__filesystem"))
+
+ # FATFS has a maximum length of 11
+ self.assertFalse(fs.FATFS().labelFormatOK("rtfilesystem"))
+ self.assertTrue(fs.FATFS().labelFormatOK("rfilesystem"))
+
+ # JFS has a maximum length of 16
+ self.assertFalse(fs.JFS().labelFormatOK("root___filesystem"))
+ self.assertTrue(fs.JFS().labelFormatOK("root__filesystem"))
+
+ # ReiserFS has a maximum length of 16
+ self.assertFalse(fs.ReiserFS().labelFormatOK("root___filesystem"))
+ self.assertTrue(fs.ReiserFS().labelFormatOK("root__filesystem"))
+
+ #XFS has a maximum length 12 and does not allow spaces
+ self.assertFalse(fs.XFS().labelFormatOK("root_filesyst"))
+ self.assertFalse(fs.XFS().labelFormatOK("root file"))
+ self.assertTrue(fs.XFS().labelFormatOK("root_filesys"))
+
+ #HFS has a maximum length of 27, minimum length of 1, and does not allow colons
+ self.assertFalse(fs.HFS().labelFormatOK("n" * 28))
+ self.assertFalse(fs.HFS().labelFormatOK("root:file"))
+ self.assertFalse(fs.HFS().labelFormatOK(""))
+ self.assertTrue(fs.HFS().labelFormatOK("n" * 27))
+
+ #HFSPlus has a maximum length of 128, minimum length of 1, and does not allow colons
+ self.assertFalse(fs.HFSPlus().labelFormatOK("n" * 129))
+ self.assertFalse(fs.HFSPlus().labelFormatOK("root:file"))
+ self.assertFalse(fs.HFSPlus().labelFormatOK(""))
+ self.assertTrue(fs.HFSPlus().labelFormatOK("n" * 128))
+
+ # NTFS has a maximum length of 128
+ self.assertFalse(fs.NTFS().labelFormatOK("n" * 129))
+ self.assertTrue(fs.NTFS().labelFormatOK("n" * 128))
+
+ # all devices are permitted to be passed a label argument of None
+ # some will ignore it completely
+ for _k, v in device_formats.items():
+ self.assertIsNotNone(v(label=None))
+
+class MethodsTestCase(unittest.TestCase):
+ """Test some methods that do not require actual images."""
+
+ def setUp(self):
+ self.fs = {}
+ for k, v in device_formats.items():
+ if issubclass(v, fs.FS) and v().labeling():
+ self.fs[k] = v(device="/dev", label="myfs")
+
+
+ def testGetLabelArgs(self):
+ self.longMessage = True
+
+ # ReiserFS uses a -l flag
+ reiserfs = self.fs["reiserfs"]
+ self.assertEqual(reiserfs._labelfs.label_app.setLabelCommand(reiserfs),
+ ["reiserfstune", "-l", "myfs", "/dev"], msg="reiserfs")
+
+ # JFS, XFS use a -L flag
+ lflag_classes = [fs.JFS, fs.XFS]
+ for name, klass in ((k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in lflag_classes)):
+ self.assertEqual(klass._labelfs.label_app.setLabelCommand(klass), [klass._labelfs.label_app.name, "-L", "myfs", "/dev"], msg=name)
+
+ # Ext2FS and descendants and FATFS do not use a flag
+ noflag_classes = [fs.Ext2FS, fs.FATFS]
+ for name, klass in ((k, v) for k, v in self.fs.items() if any(isinstance(v, c) for c in noflag_classes)):
+ self.assertEqual(klass._labelfs.label_app.setLabelCommand(klass), [klass._labelfs.label_app.name, "/dev", "myfs"], msg=name)
+
+ # all of the remaining are non-labeling so will accept any label
+ label = "Houston, we have a problem!"
+ for name, klass in device_formats.items():
+ if issubclass(klass, fs.FS) and not klass().labeling() and not issubclass(klass, fs.NFS):
+ self.assertEqual(klass(device="/dev", label=label).label, label, msg=name)
+
+class XFSTestCase(fslabeling.CompleteLabelingAsRoot):
+ _fs_class = fs.XFS
+ _invalid_label = "root filesystem"
+
+class FATFSTestCase(fslabeling.CompleteLabelingAsRoot):
+ _fs_class = fs.FATFS
+ _invalid_label = "root___filesystem"
+
+class Ext2FSTestCase(fslabeling.CompleteLabelingAsRoot):
+ _fs_class = fs.Ext2FS
+ _invalid_label = "root___filesystem"
+
+class JFSTestCase(fslabeling.LabelingWithRelabeling):
+ _fs_class = fs.JFS
+ _invalid_label = "root___filesystem"
+
+class ReiserFSTestCase(fslabeling.LabelingWithRelabeling):
+ _fs_class = fs.ReiserFS
+ _invalid_label = "root___filesystem"
+
+class HFSTestCase(fslabeling.LabelingAsRoot):
+ _fs_class = fs.HFS
+ _invalid_label = "n" * 28
+
+class HFSPlusTestCase(fslabeling.LabelingAsRoot):
+ _fs_class = fs.HFSPlus
+ _invalid_label = "n" * 129
+
+ at unittest.skip("Unable to create NTFS filesystem.")
+class NTFSTestCase(fslabeling.CompleteLabelingAsRoot):
+ _fs_class = fs.NTFS
+ _invalid_label = "n" * 129
+
+class LabelingSwapSpaceTestCase(loopbackedtestcase.LoopBackedTestCase):
+
+ def testLabeling(self):
+ swp = swap.SwapSpace(device=self.loopDevices[0])
+ swp.label = "mkswap is really pretty permissive about labels"
+ self.assertIsNone(swp.create())
+
+ def testCreatingSwapSpaceNone(self):
+ swp = swap.SwapSpace(device=self.loopDevices[0], label=None)
+ self.assertIsNone(swp.create())
+
+ def testCreatingSwapSpaceEmpty(self):
+ swp = swap.SwapSpace(device=self.loopDevices[0], label="")
+ self.assertIsNone(swp.create())
+
+if __name__ == "__main__":
+ unittest.main()
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/d5d33d7625aa6c62bed19bf85a41a2ce92f30c65
More information about the anaconda-patches
mailing list