Skip to content

Commit

Permalink
fix: Allow caret at the end of apt package (#5099)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon committed Mar 27, 2024
1 parent 1496720 commit 2a63bb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cloudinit/distros/package_management/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ def get_all_packages(self):
def get_unavailable_packages(self, pkglist: Iterable[str]):
# Packages ending with `-` signify to apt to not install a transitive
# dependency.
# Packages ending with '^' signify to apt to install a Task.
# Anything after "/" refers to a target release
# "=" allows specifying a specific version
# Strip all off when checking for availability
return [
pkg
for pkg in pkglist
if re.split("/|=", pkg)[0].rstrip("-")
if re.split("/|=", pkg)[0].rstrip("-^")
not in self.get_all_packages()
]

Expand Down
14 changes: 10 additions & 4 deletions tests/unittests/distros/package_management/test_apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,25 @@ def test_lock_exception_timeout(
apt._wait_for_apt_command("stub", {"args": "stub2"}, timeout=5)

def test_search_stem(self, m_subp, m_which, mocker):
"""Test that containing `-`, `/`, or `=` is handled correctly."""
"""Test that containing `-`, `^`, `/`, or `=` is handled correctly."""
mocker.patch(f"{M_PATH}update_package_sources")
mocker.patch(
f"{M_PATH}get_all_packages",
return_value=["cloud-init", "pkg2", "pkg3", "pkg4"],
return_value=["cloud-init", "pkg2", "pkg3", "pkg4", "pkg5"],
)
m_install = mocker.patch(f"{M_PATH}run_package_command")

apt = Apt(runner=mock.Mock())
apt.install_packages(
["cloud-init", "pkg2-", "pkg3/jammy-updates", "pkg4=1.2"]
["cloud-init", "pkg2-", "pkg3/jammy-updates", "pkg4=1.2", "pkg5^"]
)
m_install.assert_called_with(
"install",
pkgs=["cloud-init", "pkg2-", "pkg3/jammy-updates", "pkg4=1.2"],
pkgs=[
"cloud-init",
"pkg2-",
"pkg3/jammy-updates",
"pkg4=1.2",
"pkg5^",
],
)

0 comments on commit 2a63bb0

Please sign in to comment.