Exemple #1
0
    def test_errors_on_process_execution_errors(self, m_exists, m_subp,
                                                m_unlink, exit_code, stderr,
                                                error_msg):
        """Raise the appropriate user facing error from apt-helper failure."""

        # Failure apt-helper response
        m_subp.side_effect = util.ProcessExecutionError(
            cmd="apt-helper ",
            exit_code=exit_code,
            stdout="Err:1...",
            stderr=stderr,
        )

        with pytest.raises(exceptions.UserFacingError) as excinfo:
            assert_valid_apt_credentials(repo_url="http://fakerepo",
                                         username="******",
                                         password="******")
        assert error_msg == str(excinfo.value)
        exists_calls = [
            mock.call("/usr/lib/apt/apt-helper"),
            mock.call("/tmp/uaclient-apt-test"),
        ]
        assert exists_calls == m_exists.call_args_list
        apt_helper_call = mock.call(
            [
                "/usr/lib/apt/apt-helper",
                "download-file",
                "http://*****:*****@fakerepo/ubuntu/pool/",
                "/tmp/uaclient-apt-test",
            ],
            timeout=20,
        )
        assert [apt_helper_call] == m_subp.call_args_list
        assert [mock.call("/tmp/uaclient-apt-test")] == m_unlink.call_args_list
    def test_valid_apt_credentials_returns_false_on_invalid_creds(
            self, m_exists, m_subp, m_unlink):
        """Return false when apt-helper fails in authentication to repo."""

        # Failure apt-helper response
        m_subp.side_effect = util.ProcessExecutionError(
            cmd='apt-helper died',
            exit_code=100,
            stdout='Err:1...',
            stderr='E: Failed to fetch .... 401 Unauthorized')

        assert False is valid_apt_credentials(
            repo_url='http://fakerepo', username='******', password='******')
        exists_calls = [
            mock.call('/usr/lib/apt/apt-helper'),
            mock.call('/tmp/uaclient-apt-test')
        ]
        assert exists_calls == m_exists.call_args_list
        apt_helper_call = mock.call([
            '/usr/lib/apt/apt-helper', 'download-file',
            'http://*****:*****@fakerepo/ubuntu/pool/', '/tmp/uaclient-apt-test'
        ],
                                    capture=False)
        assert [apt_helper_call] == m_subp.call_args_list
        assert [mock.call('/tmp/uaclient-apt-test')] == m_unlink.call_args_list
Exemple #3
0
 def fake_subp(cmd):
     if cmd[0] == "git":
         # Not matching tag on git-ubuntu pkg branches
         raise util.ProcessExecutionError(
             "fatal: No names found, cannot describe anything.")
     if cmd[0] == "dpkg-parsechangelog":
         return ("24.1\n", "")
     assert False, "Unexpected subp cmd {}".format(cmd)
Exemple #4
0
    def test_run_apt_command_with_invalid_repositories(
        self, m_subp, error_list, output_list
    ):
        error_msg = "\n".join(error_list)

        m_subp.side_effect = util.ProcessExecutionError(
            cmd="apt update", stderr=error_msg
        )

        with pytest.raises(exceptions.UserFacingError) as excinfo:
            run_apt_command(
                cmd=["apt", "update"],
                error_msg=status.MESSAGE_APT_UPDATE_FAILED,
            )

        expected_message = "\n".join(output_list)
        assert expected_message == excinfo.value.msg
Exemple #5
0
    def test_errors_on_process_execution_errors(
        self,
        m_exists,
        m_subp,
        m_temporary_directory,
        exit_code,
        stderr,
        error_msg,
    ):
        """Raise the appropriate user facing error from apt-helper failure."""
        m_temporary_directory.return_value.__enter__.return_value = (
            "/does/not/exist"
        )
        # Failure apt-helper response
        m_subp.side_effect = util.ProcessExecutionError(
            cmd="apt-helper ",
            exit_code=exit_code,
            stdout="Err:1...",
            stderr=stderr,
        )

        with pytest.raises(exceptions.UserFacingError) as excinfo:
            assert_valid_apt_credentials(
                repo_url="http://fakerepo", username="******", password="******"
            )
        assert error_msg == str(excinfo.value)
        exists_calls = [mock.call("/usr/lib/apt/apt-helper")]
        assert exists_calls == m_exists.call_args_list
        expected_path = os.path.join(
            m_temporary_directory.return_value.__enter__.return_value,
            "apt-helper-output",
        )
        apt_helper_call = mock.call(
            [
                "/usr/lib/apt/apt-helper",
                "download-file",
                "http://*****:*****@fakerepo/ubuntu/pool/",
                expected_path,
            ],
            timeout=20,
        )
        assert [apt_helper_call] == m_subp.call_args_list
Exemple #6
0
 def fake_subp(cmd, capture=None, retry_sleeps=None):
     if cmd == ["apt-get", "update"]:
         raise util.ProcessExecutionError(
             "Failure", stderr="Could not get lock /var/lib/dpkg/lock")
     return "", ""
 def fake_subp(cmd, *args, **kwargs):
     if "install" in cmd:
         raise util.ProcessExecutionError(cmd)
     return ("", "")
Exemple #8
0
 def fake_subp(args, *other_args, **kwargs):
     if "install" in args:
         raise util.ProcessExecutionError(args)