Esempio n. 1
0
class Base(unittest.TestCase):
    """
    Common setUp/tearDown for partition tests
    """
    @unittest.skipIf(not os.path.isfile('/proc/mounts'),
                     'system does not have /proc/mounts')
    @unittest.skipIf(not process.can_sudo('mount'),
                     'current user must be allowed to run "mount" under sudo')
    @unittest.skipIf(not process.can_sudo('mkfs.ext2 -V'),
                     'current user must be allowed to run "mkfs.ext2" under '
                     'sudo')
    @unittest.skipUnless(utils_path.find_command('mkfs.ext2', False),
                         'mkfs.ext2 utility must be available')
    @unittest.skipUnless(process.has_capability("cap_sys_admin"),
                         "Capability to mount is required (cap_sys_admin)")
    @unittest.skipIf(
        os.getenv('TRAVIS')
        and os.getenv('TRAVIS_CPU_ARCH') in ['arm64', 'ppc64le', 's390x'],
        'TRAVIS Environment is unsuitable for these tests')
    def setUp(self):
        prefix = temp_dir_prefix(self)
        self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)
        self.mountpoint = os.path.join(self.tmpdir.name, "disk")
        os.mkdir(self.mountpoint)
        self.disk = partition.Partition(
            os.path.join(self.tmpdir.name, "block"), 1, self.mountpoint)

    def tearDown(self):
        self.disk.unmount()
        self.tmpdir.cleanup()
Esempio n. 2
0
class Base(unittest.TestCase):
    """
    Common setUp/tearDown for partition tests
    """
    @unittest.skipIf(not os.path.isfile("/proc/mounts"),
                     "system does not have /proc/mounts")
    @unittest.skipIf(
        not process.can_sudo("mount"),
        'current user must be allowed to run "mount" under sudo',
    )
    @unittest.skipIf(
        not process.can_sudo("mkfs.ext2 -V"),
        'current user must be allowed to run "mkfs.ext2" under '
        "sudo",
    )
    @unittest.skipUnless(
        utils_path.find_command("mkfs.ext2", False),
        "mkfs.ext2 utility must be available",
    )
    @unittest.skipUnless(
        process.has_capability("cap_sys_admin"),
        "Capability to mount is required (cap_sys_admin)",
    )
    def setUp(self):
        prefix = temp_dir_prefix(self)
        self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)
        self.mountpoint = os.path.join(self.tmpdir.name, "disk")
        os.mkdir(self.mountpoint)
        self.disk = partition.Partition(
            os.path.join(self.tmpdir.name, "block"), 1, self.mountpoint)

    def tearDown(self):
        self.disk.unmount()
        self.tmpdir.cleanup()
Esempio n. 3
0
class BaseIso9660:
    """
    Base class defining setup and tests for shared Iso9660 functionality
    """
    def setUp(self):
        self.iso_path = os.path.abspath(
            os.path.join(
                os.path.dirname(os.path.dirname(__file__)),
                os.path.pardir,
                ".data",
                "sample.iso",
            ))
        self.iso = None
        prefix = temp_dir_prefix(self)
        self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)

    def test_basic_workflow(self):
        """
        Check the basic Iso9660 workflow
        """
        self.assertEqual(self.iso.read("file"), b"file content\n")
        dst = os.path.join(self.tmpdir.name, "file")
        self.iso.copy(os.path.join("Dir", "in_dir_file"), dst)
        self.assertEqual(
            open(dst, encoding="utf-8").read(), "content of in-dir-file\n")
        self.iso.close()
        self.iso.close()  # check that double-close won't fail

    @unittest.skipIf(
        not process.can_sudo("mount"),
        "This test requires mount to run under sudo or root",
    )
    @unittest.skipUnless(
        process.has_capability("cap_sys_admin"),
        "Capability to mount is required (cap_sys_admin)",
    )
    def test_mnt_dir_workflow(self):
        """
        Check the mnt_dir functionality
        """
        base = self.iso.mnt_dir
        dir_path = os.path.join(base, "Dir")
        self.assertTrue(os.path.isdir(dir_path))
        self.assertEqual(bytes(open(os.path.join(base, "file"), "rb").read()),
                         b"file content\n")
        in_dir_file_path = os.path.join(base, "Dir", "in_dir_file")
        self.assertEqual(bytes(open(in_dir_file_path, "rb").read()),
                         b"content of in-dir-file\n")
        self.iso.close()
        self.assertFalse(
            os.path.exists(base),
            "the mnt_dir is suppose to be "
            "destroyed after iso.close()",
        )

    def tearDown(self):
        if self.iso is not None:
            self.iso.close()
        self.tmpdir.cleanup()
Esempio n. 4
0
class BaseIso9660:
    """
    Base class defining setup and tests for shared Iso9660 functionality
    """
    def setUp(self):
        self.iso_path = os.path.abspath(
            os.path.join(os.path.dirname(os.path.dirname(__file__)),
                         os.path.pardir, ".data", "sample.iso"))
        self.iso = None
        prefix = temp_dir_prefix(self)
        self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)

    @unittest.skipIf(os.uname()[4] == 's390x',
                     ('Endianess issues on pycdlib, see '
                      'https://github.com/clalancette/pycdlib/issues/39'))
    def test_basic_workflow(self):
        """
        Check the basic Iso9660 workflow
        """
        self.assertEqual(self.iso.read("file"), b"file content\n")
        dst = os.path.join(self.tmpdir.name, "file")
        self.iso.copy(os.path.join("Dir", "in_dir_file"), dst)
        self.assertEqual(
            open(dst, encoding='utf-8').read(), "content of in-dir-file\n")
        self.iso.close()
        self.iso.close()  # check that double-close won't fail

    @unittest.skipIf(not process.can_sudo("mount"),
                     "This test requires mount to run under sudo or root")
    @unittest.skipUnless(process.has_capability("cap_sys_admin"),
                         "Capability to mount is required (cap_sys_admin)")
    @unittest.skipIf(
        os.getenv('TRAVIS')
        and os.getenv('TRAVIS_CPU_ARCH') in ['arm64', 'ppc64le', 's390x'],
        'TRAVIS Environment is unsuitable for these tests')
    def test_mnt_dir_workflow(self):
        """
        Check the mnt_dir functionality
        """
        base = self.iso.mnt_dir
        dir_path = os.path.join(base, "Dir")
        self.assertTrue(os.path.isdir(dir_path))
        self.assertEqual(bytes(open(os.path.join(base, "file"), 'rb').read()),
                         b"file content\n")
        in_dir_file_path = os.path.join(base, "Dir", "in_dir_file")
        self.assertEqual(bytes(open(in_dir_file_path, 'rb').read()),
                         b"content of in-dir-file\n")
        self.iso.close()
        self.assertFalse(
            os.path.exists(base), "the mnt_dir is suppose to be "
            "destroyed after iso.close()")

    def tearDown(self):
        if self.iso is not None:
            self.iso.close()
        self.tmpdir.cleanup()
Esempio n. 5
0
class IsoMount(BaseIso9660, unittest.TestCase):
    """
    Mount-based check
    """
    @unittest.skipIf(not process.can_sudo("mount"),
                     "This test requires sudo or root")
    @unittest.skipUnless(
        process.has_capability("cap_sys_admin"),
        "Capability to mount is required (cap_sys_admin)",
    )
    def setUp(self):
        super().setUp()
        self.iso = iso9660.Iso9660Mount(self.iso_path)
Esempio n. 6
0
class IsoMount(BaseIso9660, unittest.TestCase):
    """
    Mount-based check
    """
    @unittest.skipIf(not process.can_sudo("mount"),
                     "This test requires sudo or root")
    @unittest.skipUnless(process.has_capability("cap_sys_admin"),
                         "Capability to mount is required (cap_sys_admin)")
    @unittest.skipIf(
        os.getenv('TRAVIS')
        and os.getenv('TRAVIS_CPU_ARCH') in ['arm64', 'ppc64le', 's390x'],
        'TRAVIS Environment is unsuitable for these tests')
    def setUp(self):
        super(IsoMount, self).setUp()
        self.iso = iso9660.Iso9660Mount(self.iso_path)