def test_mount_device_with_options(self, mount):
        """Test MountDevice with options specified."""
        self._add_device(StorageDevice("dev1", fmt=get_format("ext4")))

        with tempfile.TemporaryDirectory() as d:
            self.interface.MountDevice("dev1", d, "ro,auto")
            mount.assert_called_once_with(mountpoint=d, options="ro,auto")

        mount.side_effect = FSError("Fake error.")
        with pytest.raises(MountFilesystemError) as cm:
            self.interface.MountDevice("dev1", "/path", "ro,auto")

        assert str(cm.value) == "Failed to mount dev1 at /path: Fake error."
    def test_unmount_device(self, unmount):
        """Test UnmountDevice."""
        self._add_device(StorageDevice("dev1", fmt=get_format("ext4")))

        with tempfile.TemporaryDirectory() as d:
            self.interface.UnmountDevice("dev1", d)
            unmount.assert_called_once_with(mountpoint=d)

        unmount.side_effect = FSError("Fake error.")
        with pytest.raises(MountFilesystemError) as cm:
            self.interface.UnmountDevice("dev1", "/path")

        assert str(
            cm.value) == "Failed to unmount dev1 from /path: Fake error."
Example #3
0
    def mount_device_test(self, mount):
        """Test MountDevice."""
        self._add_device(StorageDevice("dev1", fmt=get_format("ext4")))

        with tempfile.TemporaryDirectory() as d:
            self.interface.MountDevice("dev1", d)
            mount.assert_called_once_with(mountpoint=d)

        mount.side_effect = FSError("Fake error.")
        with self.assertRaises(MountFilesystemError) as cm:
            self.interface.MountDevice("dev1", "/path")

        self.assertEqual(str(cm.exception),
                         "Failed to mount dev1 at /path: Fake error.")