-
Notifications
You must be signed in to change notification settings - Fork 573
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
snap: add support for snap advise-snap --from-apt
#5122
Conversation
This adds support for interacting with the new apt 1.6+ hooks. It implements the `org.debian.apt.hooks.install.fail` hook and will suggest a snap if there is one available with the given name. E.g.: ``` Reading package lists... Done Building dependency tree Reading state information... Done No apt package "aws-cli", but there is a snap with that name. Try "snap install aws-cli" E: Unable to locate package aws-cli ```
Hmm, that'd be interesting to have as a DNF hook too... |
@Conan-Kudo I would love to add one to dnf as well, do you have a pointer how to interact with dnf? |
@mvo5: Here's the DNF plugin API: http://dnf.readthedocs.io/en/latest/api_plugins.html |
@mvo5 And here are several examples of different plugins: |
It looks like the hook fails when snapd is being removed (or has been removed):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I added a few comments but that's all nitpicks I think.
cmd/snap/cmd_advise.go
Outdated
} | ||
|
||
func readRpc(r *bufio.Reader) (*jsonRPC, error) { | ||
line, _, err := r.ReadLine() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it guaranteed to be on a single line?
cmd/snap/cmd_advise.go
Outdated
} | ||
fd, err := strconv.Atoi(sockFd) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, errors from atoi were a bit horrible last time I looked and it would be even less clear what went wrong if this were to happen. How about:
return fmt.Errorf("expected APT_HOOK_SOCKET to be a decimal integer, found %q", sockFd)
cmd/snap/cmd_advise.go
Outdated
|
||
conn, err := net.FileConn(f) | ||
if err != nil { | ||
return fmt.Errorf("cannot connect to %q: %v", sockFd, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I'd probably use fd
rather than sockFd
here since we're "done" handling that layer (string vs int).
cmd/snap/cmd_advise.go
Outdated
func adviceViaAptHook() error { | ||
sockFd := os.Getenv("APT_HOOK_SOCKET") | ||
if sockFd == "" { | ||
return fmt.Errorf("cannot find APT_HOOK_SOCKET env") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just return nil here? Will this be the case when older apt is used and there's just no socket RPC to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apt added support for the new kind of hooks at the same time as the json rpc was added. So if there is no APT_HOOK_SOCKET env but the hook is called something is wrong (on the apt side).
@@ -18,6 +18,8 @@ data/udev/rules.d/66-snapd-autoimport.rules /lib/udev/rules.d | |||
data/info /usr/lib/snapd/ | |||
# polkit actions | |||
data/polkit/io.snapcraft.snapd.policy /usr/share/polkit-1/actions/ | |||
# apt hook | |||
data/apt/20snapd.conf /etc/apt/apt.conf.d/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish apt would pick hooks from /lib as this is yet another thing that needs to be in /etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a new feature, can we influence apt to do the reasonable thing?
As for the remove failure - I think we need a fix in apt for this or we need to make the shell code talk to the socket but that would be pretty hard because we cannot really depend on much when apt is in a minimal chroot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks, overall LGTM.
cmd/snap/cmd_advise.go
Outdated
Format string `long:"format" default:"pretty" choice:"pretty" choice:"json"` | ||
Command bool `long:"command"` | ||
Format string `long:"format" default:"pretty" choice:"pretty" choice:"json"` | ||
// Command makes advice try to find snaps that provide this command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/advice/advise/
cmd/snap/cmd_advise.go
Outdated
// Command makes advice try to find snaps that provide this command | ||
Command bool `long:"command"` | ||
|
||
// FromApt tells advice that it got started from an apt hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/advice/advise/
@Conan-Kudo I looked a bit at dnf plugins, but it's not clear how the functionality proposed in this patch could be utilized. i hoped we could use dnf.Plugin.resolved but as far as I understand after going through the documentation (haven't looked at dnf source code yet), the method is called when transaction is successfully resolved. At least, there does not appear to be a way to access the packages that could not be resolved. I'm open to any advice. Do you think we will need to have the dnf plugin API extended a bit? |
@bboozzoo I think it's possible if you file an RFE for it. |
@mvo5 this branch is failing and I don't see a clear way to undo that. Can you please comment about what you plan to do with it? |
@zyga We need a fix in apt for this. Once that has landed we can go forward with the PR. |
Setting to blocked because we need a fix in apt for this to work. |
Blocked because of https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1776218 |
Codecov Report
@@ Coverage Diff @@
## master #5122 +/- ##
==========================================
- Coverage 79.05% 79.01% -0.05%
==========================================
Files 514 514
Lines 38943 39001 +58
==========================================
+ Hits 30787 30816 +29
- Misses 5678 5692 +14
- Partials 2478 2493 +15
Continue to review full report at Codecov.
|
This is no longer blocked, the apt in the distro is fixed now. |
This adds support for interacting with the new apt 1.6+ hooks.
It implements the
org.debian.apt.hooks.install.fail
hook andwill suggest a snap if there is one available with the given
name.
E.g.:
This will also need a spread test for the end-to-end integration test.