diff --git a/avocado/utils/partition.py b/avocado/utils/partition.py index 5c3073335d96a42841e7682fcd5ea75168b10420..8ea5dd5de7a6a6728ccb234ea6888bd11bc5c1db 100644 --- a/avocado/utils/partition.py +++ b/avocado/utils/partition.py @@ -159,7 +159,8 @@ class Partition(object): """ Format a partition to filesystem type - :param fstype: the filesystem type, e.g.. "ext3", "ext2" + :param fstype: the filesystem type, such as "ext3", "ext2". Defaults + to previously set type or "ext2" if none has set. :param args: arguments to be passed to mkfs command. """ diff --git a/selftests/unit/test_utils_partition.py b/selftests/unit/test_utils_partition.py index 30adbbde264309913c5864187ac3b46cfe5fb408..7668045799a7d6c66b26247abaf1253651f5e357 100644 --- a/selftests/unit/test_utils_partition.py +++ b/selftests/unit/test_utils_partition.py @@ -13,6 +13,7 @@ import time from flexmock import flexmock, flexmock_teardown from avocado.utils import partition, process +from avocado.utils import path as utils_path if sys.version_info[:2] == (2, 6): import unittest2 as unittest # pylint: disable=E0401 @@ -20,19 +21,37 @@ else: import unittest # pylint: disable=C0411 +def missing_binary(binary): + try: + utils_path.find_command(binary) + return False + except utils_path.CmdNotFoundError: + return True + + +def cannot_sudo(command): + try: + process.run(command, sudo=True) + False + except process.CmdError: + return True + + class TestPartition(unittest.TestCase): """ Unit tests for avocado.utils.partition """ - @unittest.skipIf(process.system("which mkfs.ext3", ignore_status=True), - "mkfs.ext3 is required for these tests to run.") + @unittest.skipIf(missing_binary('mkfs.ext2'), + "mkfs.ext2 is required for these tests to run.") + @unittest.skipIf(missing_binary('sudo'), + "sudo is required for these tests to run.") + @unittest.skipIf(cannot_sudo('mount'), + 'current user must be allowed to run "mount" under sudo') + @unittest.skipIf(cannot_sudo('mkfs.ext2 -V'), + 'current user must be allowed to run "mkfs.ext2" under sudo') def setUp(self): - try: - process.system("/bin/true", sudo=True) - except process.CmdError: - self.skipTest("Sudo not available") self.tmpdir = tempfile.mkdtemp(prefix="avocado_" + __name__) self.mountpoint = os.path.join(self.tmpdir, "disk") os.mkdir(self.mountpoint) @@ -63,7 +82,7 @@ class TestPartition(unittest.TestCase): def test_double_mount(self): """ Check the attempt for second mount fails """ - self.disk.mkfs("ext2") + self.disk.mkfs() self.disk.mount() self.assertIn(self.mountpoint, open("/proc/mounts").read()) self.assertRaises(partition.PartitionError, self.disk.mount)