def test_exit_code_if_wal_dest_is_dir(self, isdir_mock, capsys):
        """Verifies exit status 3 when destination is a directory."""
        isdir_mock.return_value = True

        with pytest.raises(SystemExit) as exc:
            walrestore.main(["a.host", "a-server", "dummy_wal", "dummy_dest"])

        assert exc.value.code == 3
        out, err = capsys.readouterr()
        assert not out
        assert ("ERROR: WAL_DEST cannot be a directory: dummy_dest\n") in err
Esempio n. 2
0
    def test_connectivity_test_ok(self, popen_mock, capsys):

        popen_mock.return_value.communicate.return_value = ('Good test!', '')

        with pytest.raises(SystemExit) as exc:
            walrestore.main(
                ['a.host', 'a-server', '--test', 'dummy_wal', 'dummy_dest'])

        assert exc.value.code == 0
        out, err = capsys.readouterr()
        assert "Good test!" in out
        assert not err
    def test_ssh_connectivity_error(self, remote_get_wal_mock, capsys):
        """Verifies exit status is 2 when ssh connectivity fails."""
        mock_ssh_process = remote_get_wal_mock.return_value
        mock_ssh_process.returncode = 255

        with pytest.raises(SystemExit) as exc:
            walrestore.main(["a.host", "a-server", "dummy_wal", "dummy_dest"])

        assert exc.value.code == 2
        out, err = capsys.readouterr()
        assert not out
        assert ("ERROR: Connection problem with ssh\n") in err
Esempio n. 4
0
    def test_connectivity_test_ok(self, popen_mock, capsys):

        popen_mock.return_value.communicate.return_value = ("Good test!", "")
        popen_mock.return_value.returncode = 0

        with pytest.raises(SystemExit) as exc:
            walrestore.main(
                ["a.host", "a-server", "--test", "dummy_wal", "dummy_dest"])

        assert exc.value.code == 0
        out, err = capsys.readouterr()
        assert "Good test!" in out
        assert not err
    def test_ssh_exit_code_is_passed_through(self, remote_get_wal_mock,
                                             capsys):
        """Verifies non-255 SSH exit codes are passed through."""
        mock_ssh_process = remote_get_wal_mock.return_value
        mock_ssh_process.returncode = 1

        with pytest.raises(SystemExit) as exc:
            walrestore.main(["a.host", "a-server", "dummy_wal", "dummy_dest"])

        assert exc.value.code == 1
        out, err = capsys.readouterr()
        assert not out
        assert ("ERROR: Remote 'barman get-wal' command has failed!\n") in err
Esempio n. 6
0
    def test_connectivity_test_error(self, popen_mock, capsys):

        popen_mock.return_value.communicate.side_effect = subprocess.\
            CalledProcessError(255, "remote barman")

        with pytest.raises(SystemExit) as exc:
            walrestore.main(['a.host', 'a-server', '--test',
                             'dummy_wal', 'dummy_dest'])

        assert exc.value.code == 2
        out, err = capsys.readouterr()
        assert not out
        assert ("ERROR: Impossible to invoke remote get-wal: "
                "Command 'remote barman' returned non-zero "
                "exit status 255") in err
    def test_exit_code_if_wal_dest_not_writable(self, isdir_mock, open_mock,
                                                capsys):
        """Verifies exit status 3 when destination is not writable."""
        isdir_mock.return_value = False
        open_mock.side_effect = EnvironmentError("error")

        with pytest.raises(SystemExit) as exc:
            walrestore.main(["a.host", "a-server", "dummy_wal", "dummy_dest"])

        assert exc.value.code == 3
        out, err = capsys.readouterr()
        assert not out
        assert (
            "ERROR: Cannot open 'dummy_dest' (WAL_DEST) for writing: error\n"
        ) in err