-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: Option for apt lib to install not backports version package #113
Comments
I don't know enough about apt to know why it's choosing the backports version. I'm on Jammy (22.04), but I don't have the backports one showing up, so I can't reproduce this.
From this comment, it looks like when you run regular I notice from the apt.py code that it adds the argument Additionally, we're not actually capturing the error message here, I think because we're including |
You should able to reproduce this on focal.(maybe using multipass) As I know the version came from the function from_apt_cache, because the backport version is the first one show in command |
The behavior is different than command line |
|
You can do this by changing your import apt
repositories = apt.RepositoryMapping()
for repo in repositories:
if repo.release.endswith("-backports"):
repositories.disable(repo)
apt.add_package("freeipmi-tools", update_cache=False) I reproduced the original issue on focal and after adjusting as above, it successfully installed @jneo8 does this cover what you need? By the way, the default behaviour is that it'll run through the output of |
This change the # It's the apt-cache policy output on focal now
$ sudo apt-cache policy freeipmi-tools
freeipmi-tools:
Installed: (none)
Candidate: 1.6.4-3ubuntu1.1
Version table:
1.6.9-2~bpo20.04.1 100
100 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages
1.6.4-3ubuntu1.1 500
500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
1.6.4-3ubuntu1 500
500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages Below is my workaround to get the Candidate version first and pass to """Apt helper module for missing features in operator_libs_linux."""
import re
from subprocess import PIPE, CalledProcessError, check_output
from typing import Optional
from charms.operator_libs_linux.v0 import apt
def get_candidate_version(package: str) -> Optional[str]:
"""Get candiate version of package from apt-cache."""
try:
output = check_output(
["apt-cache", "policy", package], stderr=PIPE, universal_newlines=True
)
except CalledProcessError as e:
raise apt.PackageError(f"Could not list packages in apt-cache: {e.output}") from None
lines = [line.strip() for line in output.strip().split("\n")]
for line in lines:
candidate_matcher = re.compile(r"^Candidate:\s(?P<version>(.*))")
matches = candidate_matcher.search(line)
if matches:
return matches.groupdict().get("version")
raise apt.PackageError(f"Could not find candidate version package in apt-cache: {output}")
def add_pkg_with_candidate_version(pkg: str) -> None:
"""Install package with apt-cache candidate version."""
version = get_candidate_version(pkg)
apt.add_package(pkg, version=version, update_cache=False) I would like to contribute to apt lib to provide some similar feature like this. |
I think I would rather not - this looks quite convoluted. I'd suggest instead just specifying the exact version that you want to install, which I think the lib already supports? That way a given revision of the charm will be tied to a known good version in the archive. It does mean the charm will need bumping when the version changes in the archive, but that could be automated quite trivially 😀 |
Hi @jnsgruk , I believe there are two issues here:
|
I'm suggesting the latter, that you hard code the versions. This is relatively common in our product charms like MySQL/ PostgreSQL where we pin a given revision of a charm to a revision of the underlying snap to ensure compatibility. In reality if you have some automation to bump versions and release to charmhub, this is quite low overhead and will give you more confidence that the things going into production have been tested together. |
Shouldn't the apt lib Make sure they have the same behavior will decrease the difficulty for user to using this library. Without this then the |
While pinning a revision to a snap makes sense, pinning to a deb package not so much.
|
Yes, I agree that In any case, I think an immediate workaround for @jneo8 is to do what @jnsgruk suggested and pin the version. However, @nishant-dash has some good points about why that's probably not a good idea in general. I'd say we should make An alternative would be to rewrite this package with a v1 version, vastly simplifying it to basically just calling the apt commands and relying on their logic. |
This is a good idea. I was never a fan of the complexity this library introduced. I don't know how much work it'd be, but could be a possible "blue" or a job for next cycle if too much. |
freeipmi-tools
failed to install on focalRelate: canonical/hardware-observer-operator#128
Reproduce
install.py
The apt lib choose backports version to install instead of focal-updates
One way for us to resolve this issue is try to catch the target version from the command, but I feel more nice if apt lib can support it.
The text was updated successfully, but these errors were encountered: