Skip to content

Commit

Permalink
fixup! Fixes #24238: Rudder-package should log the package scripts ou…
Browse files Browse the repository at this point in the history
…tputs and errors

Fixes #24238: Rudder-package should log the package scripts outputs and errors
  • Loading branch information
Félix Dallidet committed Feb 23, 2024
1 parent d1d4b18 commit 6cbddcd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
10 changes: 8 additions & 2 deletions relay/sources/rudder-pkg/lib/rudder-pkg/rudderPkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ def install_file(package_files, exact_version, exit_on_error=True):
script_dir = utils.extract_scripts(metadata, package_file)
preinst_retcode = utils.run_script('preinst', script_dir, exist)
if exit_on_error and preinst_retcode != 0:
utils.fail(package_file + " installation failed, the preinst package script exited with a non zero exit code.")
utils.fail(
package_file
+ ' installation failed, the preinst package script exited with a non zero exit code.'
)
utils.install(metadata, package_file, exist)
postinst_retcode = utils.run_script('postinst', script_dir, exist)
if exit_on_error and postinst_retcode != 0:
utils.fail(package_file + " installation failed, the postinst package script exited with a non zero exit code.")
utils.fail(
package_file
+ ' installation failed, the postinst package script exited with a non zero exit code.'
)
if metadata['type'] == 'plugin' and 'jar-files' in metadata:
for j in metadata['jar-files']:
utils.jar_status(j, True)
Expand Down
30 changes: 21 additions & 9 deletions relay/sources/rudder-pkg/lib/rudder-pkg/rudderPkgUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def run_script(name, script_dir, exist):
for the packaging scripts if needed.
"""
script = script_dir + '/' + name
logger.debug("Running " + name + " step")
logger.debug('Running ' + name + ' step')
if os.path.isfile(script):
if exist is None:
param = ''
Expand All @@ -587,18 +587,30 @@ def run_script(name, script_dir, exist):
# Use None everywhere to branch to stdin/err/out

(retcode, raw_output, raw_error) = run(
[script, param],
check=True,
stdin=None,
capture_output=True
[script, param], check=True, stdin=None, capture_output=True
)
with open(script + ".log", "w") as logfile:
logfile.write(json.dumps({"Exitcode": retcode, "Output": raw_output.decode("utf-8"), "Error": raw_error.decode("utf-8")}, indent=4))
with open(script + '.log', 'w') as logfile:
logfile.write(
json.dumps(
{
'Exitcode': retcode,
'Output': raw_output.decode('utf-8'),
'Error': raw_error.decode('utf-8'),
},
indent=4,
)
)
if retcode != 0:
logger.error(script + " execution exited with error code " + retcode + " see the detailed log execution in " + logfile)
logger.error(
script
+ ' execution exited with error code '
+ retcode
+ ' see the detailed log execution in '
+ logfile
)
return retcode
else:
logger.debug("Nothing to do as the script " + script + " does not exist")
logger.debug('Nothing to do as the script ' + script + ' does not exist')
return 0


Expand Down

0 comments on commit 6cbddcd

Please sign in to comment.