Skip to content

Commit

Permalink
payload/rpm-ostree: Include program output in exception
Browse files Browse the repository at this point in the history
The rpm-ostree container deployment path can fail for many reasons
from networking to details in mount setup.

What we really want is a proper API with progress out of bootc/ostree;
I will work on that at some point.

In the meantime though, just capture stderr on failure and include
it in the payload installation error so people don't have to
dig into `program.log` which is very obscure.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters authored and KKoukiou committed Jan 15, 2025
1 parent a54f83d commit 31dcdd0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 20 additions & 0 deletions pyanaconda/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ def execWithCapture(command, argv, stdin=None, root='/', env_prune=None, env_add
return _run_program(argv, stdin=stdin, root=root, log_output=log_output, env_prune=env_prune,
env_add=env_add, filter_stderr=filter_stderr, do_preexec=do_preexec)[1]

def execProgram(command, argv, stdin=None, root='/', env_prune=None, env_add=None,
log_output=True, filter_stderr=False, do_preexec=True):
""" Run an external program and capture standard out and err as well as the return code.
:param command: The command to run
:param argv: The argument list
:param stdin: The file object to read stdin from.
:param root: The directory to chroot to before running command.
:param env_prune: environment variable to remove before execution
:param env_add: environment variables added for the execution
:param log_output: Whether to log the output of command
:param filter_stderr: Whether stderr should be excluded from the returned output
:param do_preexec: whether to use the preexec function
:return: Tuple of the return code and the output of the command
"""
argv = [command] + argv

return _run_program(argv, stdin=stdin, root=root, log_output=log_output, env_prune=env_prune,
env_add=env_add, filter_stderr=filter_stderr, do_preexec=do_preexec)


def execWithCaptureAsLiveUser(command, argv, stdin=None, root='/', log_output=True,
filter_stderr=False, do_preexec=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pyanaconda.core.glib import GError, Variant, create_new_context, format_size_full
from pyanaconda.core.i18n import _
from pyanaconda.core.path import make_directories, set_system_root
from pyanaconda.core.util import execWithRedirect
from pyanaconda.core.util import execWithRedirect, execProgram
from pyanaconda.modules.common.constants.objects import BOOTLOADER, DEVICE_TREE
from pyanaconda.modules.common.constants.services import LOCALIZATION, STORAGE
from pyanaconda.modules.common.errors.installation import (
Expand All @@ -46,15 +46,16 @@


def safe_exec_with_redirect(cmd, argv, successful_return_codes=(0,), **kwargs):
"""Like util.execWithRedirect, but treat errors as fatal.
"""Like util.execProgram, but treat errors as fatal.
:raise: PayloadInstallationError if the call fails for any reason
"""
rc = execWithRedirect(cmd, argv, **kwargs)
rc, output = execProgram(cmd, argv, **kwargs)

if rc not in successful_return_codes:
raise PayloadInstallationError(
"The command '{}' exited with the code {}.".format(" ".join([cmd] + argv), rc)
"The command '{}' exited with the code {}:\n{}".format(" ".join([cmd] + argv), rc,
output)
)


Expand Down

0 comments on commit 31dcdd0

Please sign in to comment.