Skip to content

Commit

Permalink
Add absolute paths to command calls
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Waltlova <[email protected]>
  • Loading branch information
andywaltlova committed Nov 16, 2023
1 parent b53b4f2 commit 6e53a72
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions scripts/leapp_preupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ def run_subprocess(cmd, print_cmd=True, env=None, wait=True):


def _check_if_package_installed(pkg_name):
_, return_code = run_subprocess(["rpm", "-q", pkg_name])
_, return_code = run_subprocess(["/usr/bin/rpm", "-q", pkg_name])
return return_code == 0


def _get_leapp_command_and_packages(version):
if version.startswith("7"):
leapp_install_command = [
"yum",
"/usr/bin/yum",
"install",
"leapp-upgrade",
"-y",
Expand Down Expand Up @@ -180,7 +180,7 @@ def _get_leapp_command_and_packages(version):
},
]
if version.startswith("8"):
leapp_install_command = ["dnf", "install", "leapp-upgrade", "-y"]
leapp_install_command = ["/usr/bin/dnf", "install", "leapp-upgrade", "-y"]
rhui_packages = [
{"src_pkg": "rh-amazon-rhui-client", "leapp_pkg": "leapp-rhui-aws"},
{
Expand Down Expand Up @@ -236,7 +236,7 @@ def should_use_no_rhsm_check(rhui_installed, command):
_, rhsm_installed_check = run_subprocess(["which", "subscription-manager"])
if rhsm_installed_check == 0:
rhsm_repo_check, _ = run_subprocess(
["subscription-manager", "repos", "--list-enabled"]
["/usr/sbin/subscription-manager", "repos", "--list-enabled"]
)
rhsm_repo_check_fail = (
"This system has no repositories available through subscriptions."
Expand All @@ -256,7 +256,7 @@ def install_leapp_pkg_corresponding_to_installed_rhui(rhui_pkgs):
for pkg in rhui_pkgs:
install_pkg = pkg["leapp_pkg"]
install_output, returncode = run_subprocess(
["yum", "install", "-y", install_pkg]
["/usr/bin/yum", "install", "-y", install_pkg]
)
if returncode:
raise ProcessError(
Expand Down Expand Up @@ -350,7 +350,7 @@ def parse_results(output):

def call_insights_client():
print("Calling insight-client in background for immediate data collection.")
run_subprocess(["insights-client"], wait=False)
run_subprocess(["/usr/bin/insights-client"], wait=False)
# NOTE: we do not care about returncode or output because we are not waiting for process to finish


Expand Down
2 changes: 1 addition & 1 deletion tests/preupgrade/test_check_pkg_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def test_check_if_package_installed(mock_run_subprocess):
pkg_name = "example-package"
mock_run_subprocess.return_value = ("", 0)
result = _check_if_package_installed(pkg_name)
expected_command = ["rpm", "-q", pkg_name]
expected_command = ["/usr/bin/rpm", "-q", pkg_name]
mock_run_subprocess.assert_called_once_with(expected_command)
assert result
2 changes: 1 addition & 1 deletion tests/preupgrade/test_insights_client_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
@patch("scripts.leapp_preupgrade.run_subprocess", return_value=(b"", 0))
def test_call_insights_client(mock_popen):
call_insights_client()
mock_popen.assert_called_once_with(["insights-client"], wait=False)
mock_popen.assert_called_once_with(["/usr/bin/insights-client"], wait=False)
4 changes: 2 additions & 2 deletions tests/preupgrade/test_install_rhui_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_install_leapp_pkg_to_installed_rhui(mock_run_subprocess):
install_leapp_pkg_corresponding_to_installed_rhui(rhui_pkgs)

for pkg in rhui_pkgs:
expected_command = ["yum", "install", "-y", pkg["leapp_pkg"]]
expected_command = ["/usr/bin/yum", "install", "-y", pkg["leapp_pkg"]]
assert call(expected_command) in mock_run_subprocess.call_args_list


Expand All @@ -29,7 +29,7 @@ def test_install_leapp_pkg_to_installed_rhui_error(
with pytest.raises(ProcessError) as exception:
install_leapp_pkg_corresponding_to_installed_rhui(rhui_pkgs)

expected_command = ["yum", "install", "-y", "pkg1"]
expected_command = ["/usr/bin/yum", "install", "-y", "pkg1"]
mock_run_subprocess.assert_called_once_with(expected_command)

assert (
Expand Down
8 changes: 4 additions & 4 deletions tests/preupgrade/test_setup_leapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def test_setup_leapp_success(mock_check_if_package_installed, mock_run_subproces
mock_check_if_package_installed.return_value = True

rhel7_command = [
"yum",
"/usr/bin/yum",
"install",
"leapp-upgrade",
"-y",
"--enablerepo=rhel-7-server-extras-rpms",
]
rhel8_command = ["dnf", "install", "leapp-upgrade", "-y"]
rhel8_command = ["/usr/bin/dnf", "install", "leapp-upgrade", "-y"]

for version, command in [("7", rhel7_command), ("8", rhel8_command)]:
result = setup_leapp(version)
Expand All @@ -31,13 +31,13 @@ def test_setup_leapp_failure(mock_check_if_package_installed, mock_run_subproces
mock_check_if_package_installed.return_value = True

rhel7_command = [
"yum",
"/usr/bin/yum",
"install",
"leapp-upgrade",
"-y",
"--enablerepo=rhel-7-server-extras-rpms",
]
rhel8_command = ["dnf", "install", "leapp-upgrade", "-y"]
rhel8_command = ["/usr/bin/dnf", "install", "leapp-upgrade", "-y"]

for version, command in [("7", rhel7_command), ("8", rhel8_command)]:
with pytest.raises(ProcessError) as e_info:
Expand Down

0 comments on commit 6e53a72

Please sign in to comment.