示例#1
0
    def test_rsync_error(self):
        """Should raise CalledProcessError if rsync exits with non-zero."""
        self.mock_run_function.side_effect = snapshotter.CalledProcessError(
            "command", "output", 11)
        src = "/home/fred"
        dst = "/media/backup"

        try:
            snapshotter.snapshot(src, dst, debug=True)
            assert False, "snapshot() should have raised an exception"
        except snapshotter.CalledProcessError as err:
            assert err.output == "output 11"
示例#2
0
    def test_mv_command_fails(self):
        """snapshot() should raise if the mv command exits with non-zero."""
        src = "Mail"
        dst = "Mail.snapshots"

        self.mock_run_function.side_effect = snapshotter.CalledProcessError(
            "command", "output", 25)

        try:
            snapshotter.snapshot(src, dst)
            assert False, "snapshot() should have raised an exception"
        except snapshotter.CalledProcessError as err:
            assert err.output == "output 25"
示例#3
0
    def test_rsync_raises_CalledProcessError_other_exit_value(
            self, mock_run_function):
        """CalledProcessError should be raised for other rsync errors.

        If rsync exits with a non-zero status other than 11, _rsync() should
        raise CalledProcessError.

        """
        mock_run_function.side_effect = snapshotter.CalledProcessError(
            command="rsync ...",
            output="Some other rsync error",
            exit_value=13)

        nose.tools.assert_raises(snapshotter.CalledProcessError,
                                 snapshotter._rsync, "source", "dest")
示例#4
0
    def test_rsync_raises_CalledProcessError(self, mock_run_function):
        """CalledProcessError should be raised for other rsync errors.

        If rsync exits with any status 11 and something other than a
        "no space left on device" error, _rsync() should raise
        CalledProcessError.

        """
        mock_run_function.side_effect = snapshotter.CalledProcessError(
            command="rsync ...",
            output="Some other rsync error",
            exit_value=11)

        nose.tools.assert_raises(snapshotter.CalledProcessError,
                                 snapshotter._rsync, "source", "dest")
示例#5
0
    def test_rsync_raises_NoSpaceLeftOnDevice(self, mock_run_function):
        """NoSpaceLeftOnDeviceError should be raised for rsync no space error.

        If rsync exits with status 11 and a "No space left on device" error,
        _rsync() should raise NoSpaceLeftOnDeviceError.

        """
        mock_run_function.side_effect = snapshotter.CalledProcessError(
            command="rsync ...",
            output='rsync: write failed on "/media/seanh/foo/Hypothesis/Co-'
            'ment ~ Philippe Aigrain @ I Annotate 2014 (HD).mp4": No '
            'space left on device (28)\n'
            'rsync error: error in file IO (code 11) at receiver.c(389)'
            ' [receiver=3.1.0]',
            exit_value=11)

        nose.tools.assert_raises(snapshotter.NoSpaceLeftOnDeviceError,
                                 snapshotter._rsync, "source", "dest")
示例#6
0
    def test_other_rsync_error(self):
        snapshots = [
            "2015-03-05T16_23_12.snapshot",
            "2015-03-05T16_24_15.snapshot",
            "2015-03-05T16_25_09.snapshot",
            "2015-03-05T16_27_09.snapshot",
            "2015-03-05T16_28_09.snapshot",
        ]
        self.mock_ls_snapshots_function.return_value = snapshots

        self.mock_rsync_function.side_effect = snapshotter.CalledProcessError(
            "rsync ...", "error", 23)

        def rm(*args, **kwargs):
            snapshots.pop(0)

        self.mock_rm_function.side_effect = rm

        nose.tools.assert_raises(snapshotter.CalledProcessError,
                                 snapshotter.snapshot, "source", "destination")