Updated hardcoded /var/cache/yum to use appropriate cache value provided by platform, for example /var/cache/dnf

This commit is contained in:
David Murphy 2025-03-04 11:54:27 -07:00 committed by Daniel Wozniak
parent e98ecbc0d6
commit cd04e6f2f9
2 changed files with 18 additions and 14 deletions

View file

@ -1060,7 +1060,7 @@ def list_downloaded(**kwargs):
salt '*' pkg.list_downloaded
"""
CACHE_DIR = os.path.join("/var/cache/", _yum())
CACHE_DIR = os.path.join("/var/cache", _yum())
ret = {}
for root, dirnames, filenames in salt.utils.path.os_walk(CACHE_DIR):
@ -3360,10 +3360,7 @@ def download(*packages, **kwargs):
if not packages:
raise SaltInvocationError("No packages were specified")
## DGM CACHE_DIR = "/var/cache/yum/packages"
CACHE_DIR = os.path.join("/var/cache/", _yum(), "/packages")
print(f"DGM download CACHE_DIR, '{CACHE_DIR}'", flush=True)
CACHE_DIR = os.path.join("/var/cache", _yum(), "packages")
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
cached_pkgs = os.listdir(CACHE_DIR)

View file

@ -926,7 +926,7 @@ def test_list_downloaded():
mock_walk = MagicMock(
return_value=[
(
"/var/cache/yum",
os.path.join("/var/cache", yumpkg._yum()),
[],
["pkg1-3.1-16.1.x86_64.rpm", "pkg2-1.2-13.2.x86_64.rpm"],
)
@ -955,7 +955,9 @@ def test_list_downloaded():
"3.1": {
"creation_date_time": "2023-10-05T14:01:22",
"creation_date_time_t": 1696536082,
"path": "/var/cache/yum/pkg1-3.1-16.1.x86_64.rpm",
"path": os.path.join(
"/var/cache", yumpkg._yum(), "pkg1-3.1-16.1.x86_64.rpm"
),
"size": 75701688,
},
},
@ -963,7 +965,9 @@ def test_list_downloaded():
"1.2": {
"creation_date_time": "2023-10-05T14:01:22",
"creation_date_time_t": 1696536082,
"path": "/var/cache/yum/pkg2-1.2-13.2.x86_64.rpm",
"path": os.path.join(
"/var/cache", yumpkg._yum(), "pkg2-1.2-13.2.x86_64.rpm"
),
"size": 75701688,
},
},
@ -1150,11 +1154,12 @@ def test_download():
patch_salt = patch.dict(yumpkg.__salt__, dict_salt)
with patch_which, patch_exists, patch_makedirs, patch_listdir, patch_salt:
result = yumpkg.download("spongebob")
cmd = ["yumdownloader", "-q", "--destdir=/var/cache/yum/packages", "spongebob"]
cache_dir = os.path.join("/var/cache", yumpkg._yum(), "packages")
cmd = ["yumdownloader", "-q", f"--destdir={cache_dir}", "spongebob"]
mock_run.assert_called_once_with(
cmd, output_loglevel="trace", python_shell=False
)
expected = {"spongebob": "/var/cache/yum/packages/spongebob-1.2.rpm"}
expected = {"spongebob": f"{cache_dir}/spongebob-1.2.rpm"}
assert result == expected
@ -1171,10 +1176,11 @@ def test_download_failed():
patch_salt = patch.dict(yumpkg.__salt__, dict_salt)
with patch_which, patch_exists, patch_listdir, patch_unlink, patch_salt:
result = yumpkg.download("spongebob", "patrick")
cache_dir = os.path.join("/var/cache", yumpkg._yum(), "packages")
cmd = [
"yumdownloader",
"-q",
"--destdir=/var/cache/yum/packages",
f"--destdir={cache_dir}",
"spongebob",
"patrick",
]
@ -1183,7 +1189,7 @@ def test_download_failed():
)
expected = {
"_error": "The following package(s) failed to download: patrick",
"spongebob": "/var/cache/yum/packages/spongebob-1.2.rpm",
"spongebob": f"{cache_dir}/spongebob-1.2.rpm",
}
assert result == expected
@ -1207,11 +1213,12 @@ def test_download_to_purge():
patch_salt = patch.dict(yumpkg.__salt__, dict_salt)
with patch_which, patch_exists, patch_listdir, patch_unlink, patch_salt:
result = yumpkg.download("spongebob")
cmd = ["yumdownloader", "-q", "--destdir=/var/cache/yum/packages", "spongebob"]
cache_dir = os.path.join("/var/cache", yumpkg._yum(), "packages")
cmd = ["yumdownloader", "-q", f"--destdir={cache_dir}", "spongebob"]
mock_run.assert_called_once_with(
cmd, output_loglevel="trace", python_shell=False
)
expected = {"spongebob": "/var/cache/yum/packages/spongebob-1.2.rpm"}
expected = {"spongebob": f"{cache_dir}/spongebob-1.2.rpm"}
assert result == expected