-
Notifications
You must be signed in to change notification settings - Fork 562
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
cmd/snap: add 'debug paths' command #5459
Conversation
Add `snap debug paths` command that shows paths that have been detected for the system. Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
cmd/snap/cmd_paths.go
Outdated
w := tabWriter() | ||
defer w.Flush() | ||
|
||
// TODO: include paths reported by snap-confine |
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.
Can you be more specific?
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.
It'd be great to have a way to interrogate s-c
get back whatever was passed as --with-snap-mount-dir
, --libexecdir
and maybe --with-32bit-libdir
and include it in the output here.
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.
That is interesting, yes (for as long as there are hard-coded assumptions in snap-confine)
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.
It'd be better to fix it instead of interrogating it, though.
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.
No disagreements there :)
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.
+1 on the concept, this is very very nice IMO
Codecov Report
@@ Coverage Diff @@
## master #5459 +/- ##
==========================================
+ Coverage 79.01% 79.02% +0.01%
==========================================
Files 512 513 +1
Lines 38674 38701 +27
==========================================
+ Hits 30557 30584 +27
Misses 5664 5664
Partials 2453 2453
Continue to review full report at Codecov.
|
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.
Code looks fine - I'm curious what the use-case is? I also wonder if it should be part of sysinfo if its something that people expect to discover via the API (but that depends on the use-case of course).
@bboozzoo one last request, please add a simple spread test. |
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
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.
Seems okay to expose this. Some suggestions:
cmd/snap/cmd_paths.go
Outdated
w := tabWriter() | ||
defer w.Flush() | ||
|
||
// TODO: include paths reported by snap-confine |
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.
Per note above, let's please not do this and drop the TODO. For two reasons:
- The snap-confine bundled with snapd should use the same paths as the snapd and snap binary that shipped with it, so we can interrogate those instead for the same result (note we're not querying snapd either here).
- We should fix snap-confine to use paths dynamically if/when it needs to.
cmd/snap/cmd_paths.go
Outdated
{"snap-bin-dir", dirs.SnapBinariesDir}, | ||
{"distro-libexec", dirs.DistroLibExecDir}, | ||
} { | ||
fmt.Fprintf(w, "%s:\t%s\n", p.name, p.path) |
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.
A format like this might be better here:
SNAPD_MOUNT=...
SNAPD_BIN=...
SNAPD_LIBEXEC=...
This allows usage in shell for analysis, and it also uses the $SNAPD_ prefix, which is what we generally have for snapd-related content. We usually reserve the $SNAP_ prefix for things which are for a snap, with $SNAP being the path to the snap directory under /snap. We also don't use DIR for $SNAP*, so we don't need it here either.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
… output Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
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.
Looks great, on suggestion to kill the tabWriter, otherwise ready to go.
cmd/snap/cmd_paths.go
Outdated
return ErrExtraArgs | ||
} | ||
|
||
w := tabWriter() |
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.
We don't need a tabWriter anymore, do we? The new code is not writing tabs anymore AFAICT.
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.
Updated
} | ||
|
||
func (s *SnapSuite) TestPathsFedora(c *C) { | ||
restore := release.MockReleaseInfo(&release.OS{ID: "fedora"}) |
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.
Nice test(s)
snap debug paths | MATCH "^SNAPD_LIBEXEC=${LIBEXECDIR}/snapd$" | ||
|
||
# double check we can eval it as shell | ||
eval "$(snap debug paths)" |
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.
❤️
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Add
snap debug paths
command that shows paths that have been detected for thesystem. This currently includes: