Skip to content

Commit

Permalink
Add output of failed convert2rhel command to script report field (#29)
Browse files Browse the repository at this point in the history
* Add output of convert2rhel analyze command to output

Signed-off-by: Andrea Waltlova <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add output of failed commands to conversion script report field

Signed-off-by: Andrea Waltlova <[email protected]>

* Add absolute paths to yum in both scripts

Signed-off-by: Andrea Waltlova <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Andrea Waltlova <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
andywaltlova and pre-commit-ci[bot] authored Nov 21, 2023
1 parent f84fa17 commit 8b96685
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
19 changes: 11 additions & 8 deletions scripts/conversion_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def run_subprocess(cmd, print_cmd=True, env=None):
password in plain text.
The cmd is specified as a list starting with the command and followed by a
list of arguments. Example: ["yum", "install", "<package>"]
list of arguments. Example: ["/usr/bin/yum", "install", "<package>"]
"""
# This check is here because we passed in strings in the past and changed
# to a list for security hardening. Remove this once everyone is
Expand Down Expand Up @@ -242,7 +242,7 @@ def install_convert2rhel():
"""Install the convert2rhel tool to the system."""
print("Installing & updating Convert2RHEL package.")
output, returncode = run_subprocess(
["yum", "install", "convert2rhel", "-y"],
["/usr/bin/yum", "install", "convert2rhel", "-y"],
)
if returncode:
raise ProcessError(
Expand All @@ -251,7 +251,9 @@ def install_convert2rhel():
% (returncode, output.rstrip("\n")),
)

output, returncode = run_subprocess(["yum", "update", "convert2rhel", "-y"])
output, returncode = run_subprocess(
["/usr/bin/yum", "update", "convert2rhel", "-y"]
)
if returncode:
raise ProcessError(
message="Failed to update convert2rhel RPM.",
Expand All @@ -272,14 +274,15 @@ def run_convert2rhel():
"RHC_WORKER_CONVERT2RHEL_DISABLE_TELEMETRY"
]

_, returncode = run_subprocess(["/usr/bin/convert2rhel", "-y"], env=env)
output, returncode = run_subprocess(["/usr/bin/convert2rhel", "-y"], env=env)
if returncode:
raise ProcessError(
message=(
"An error occurred during the conversion execution. For details, refer to "
"the convert2rhel log file on the host at /var/log/convert2rhel/convert2rhel.log"
),
report="convert2rhel execution exited with code '%s'." % returncode,
report="convert2rhel execution exited with code '%s'and output: %s."
% (returncode, output.rstrip("\n")),
)


Expand Down Expand Up @@ -418,9 +421,9 @@ def update_insights_inventory():

if returncode:
raise ProcessError(
message="Failed to update Insights Inventory by registering the system again. See output the following output: %s"
% output,
report="insights-client execution exited with code '%s'." % returncode,
message="Failed to update Insights Inventory by registering the system again.",
report="insights-client execution exited with code '%s' and output: %s."
% (returncode, output.rstrip("\n")),
)

print("System registered with insights-client successfully.")
Expand Down
15 changes: 10 additions & 5 deletions scripts/preconversion_assessment_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def run_subprocess(cmd, print_cmd=True, env=None):
password in plain text.
The cmd is specified as a list starting with the command and followed by a
list of arguments. Example: ["yum", "install", "<package>"]
list of arguments. Example: ["/usr/bin/yum", "install", "<package>"]
"""
# This check is here because we passed in strings in the past and changed
# to a list for security hardening. Remove this once everyone is
Expand Down Expand Up @@ -239,7 +239,7 @@ def install_convert2rhel():
"""Install the convert2rhel tool to the system."""
print("Installing & updating Convert2RHEL package.")
output, returncode = run_subprocess(
["yum", "install", "convert2rhel", "-y"],
["/usr/bin/yum", "install", "convert2rhel", "-y"],
)
if returncode:
raise ProcessError(
Expand All @@ -248,7 +248,9 @@ def install_convert2rhel():
% (returncode, output.rstrip("\n")),
)

output, returncode = run_subprocess(["yum", "update", "convert2rhel", "-y"])
output, returncode = run_subprocess(
["/usr/bin/yum", "update", "convert2rhel", "-y"]
)
if returncode:
raise ProcessError(
message="Failed to update convert2rhel RPM.",
Expand All @@ -269,14 +271,17 @@ def run_convert2rhel():
"RHC_WORKER_CONVERT2RHEL_DISABLE_TELEMETRY"
]

_, returncode = run_subprocess(["/usr/bin/convert2rhel", "analyze", "-y"], env=env)
output, returncode = run_subprocess(
["/usr/bin/convert2rhel", "analyze", "-y"], env=env
)
if returncode:
raise ProcessError(
message=(
"An error occurred during the pre-conversion analysis. "
"For details, refer to the convert2rhel log file on the host at /var/log/convert2rhel/convert2rhel.log"
),
report="convert2rhel execution exited with code '%s'." % returncode,
report="convert2rhel execution exited with code '%s' and output: %s."
% (returncode, output.rstrip("\n")),
)


Expand Down
10 changes: 5 additions & 5 deletions tests/conversion_script/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def test_install_convert2rhel(subprocess_mock):
install_convert2rhel()

expected_calls = [
["yum", "install", "convert2rhel", "-y"],
["yum", "update", "convert2rhel", "-y"],
["/usr/bin/yum", "install", "convert2rhel", "-y"],
["/usr/bin/yum", "update", "convert2rhel", "-y"],
]

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]
Expand All @@ -34,7 +34,7 @@ def test_install_convert2rhel_raise_exception():
):
install_convert2rhel()

expected_calls = [["yum", "install", "convert2rhel", "-y"]]
expected_calls = [["/usr/bin/yum", "install", "convert2rhel", "-y"]]

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]

Expand All @@ -51,8 +51,8 @@ def test_update_convert2rhel_raise_exception():
install_convert2rhel()

expected_calls = [
["yum", "install", "convert2rhel", "-y"],
["yum", "update", "convert2rhel", "-y"],
["/usr/bin/yum", "install", "convert2rhel", "-y"],
["/usr/bin/yum", "update", "convert2rhel", "-y"],
]

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]
10 changes: 5 additions & 5 deletions tests/preconversion_assessment/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def test_install_convert2rhel(subprocess_mock):
install_convert2rhel()

expected_calls = [
["yum", "install", "convert2rhel", "-y"],
["yum", "update", "convert2rhel", "-y"],
["/usr/bin/yum", "install", "convert2rhel", "-y"],
["/usr/bin/yum", "update", "convert2rhel", "-y"],
]

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]
Expand All @@ -34,7 +34,7 @@ def test_install_convert2rhel_raise_exception():
):
install_convert2rhel()

expected_calls = [["yum", "install", "convert2rhel", "-y"]]
expected_calls = [["/usr/bin/yum", "install", "convert2rhel", "-y"]]

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]

Expand All @@ -51,8 +51,8 @@ def test_update_convert2rhel_raise_exception():
install_convert2rhel()

expected_calls = [
["yum", "install", "convert2rhel", "-y"],
["yum", "update", "convert2rhel", "-y"],
["/usr/bin/yum", "install", "convert2rhel", "-y"],
["/usr/bin/yum", "update", "convert2rhel", "-y"],
]

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]

0 comments on commit 8b96685

Please sign in to comment.