-
Notifications
You must be signed in to change notification settings - Fork 601
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
mount-control: step 3 #10864
mount-control: step 3 #10864
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10864 +/- ##
==========================================
+ Coverage 78.37% 78.40% +0.02%
==========================================
Files 923 925 +2
Lines 105246 105409 +163
==========================================
+ Hits 82484 82643 +159
- Misses 17624 17627 +3
- Partials 5138 5139 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
f4d6bb6
to
e19b4d8
Compare
Yes, to me it makes sense. But I'll let @pedronis make the decision (this will also require a rule like |
e19b4d8
to
3807565
Compare
3807565
to
7ea0c54
Compare
@pedronis hi, do you have any concern about supporting |
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.
overall looks good, bunch of initial comments
overlord/hookstate/ctlcmd/mount.go
Outdated
var ( | ||
shortMountHelp = i18n.G("Create a temporary or permanent mount") | ||
longMountHelp = i18n.G(` | ||
The mount command mounts the given source onto the given destination 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.
the long help should mention mount-control
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.
Done
overlord/hookstate/ctlcmd/mount.go
Outdated
Where string `positional-arg-name:"<where>" required:"yes" description:"path to the destination mount point"` | ||
} `positional-args:"yes" required:"yes"` | ||
Persistent bool `long:"persistent" description:"make the mount persist across reboots"` | ||
Type string `long:"type" short:"t" description:"partition type"` |
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/partition/filesystem/
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.
Done
overlord/hookstate/ctlcmd/mount.go
Outdated
sysd := systemd.New(systemd.SystemMode, nil) | ||
name, err := m.createMountUnit(sysd) | ||
if err != nil { | ||
return fmt.Errorf("Failed to create mount unit: %v", 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.
error should be lowercase, s/Failed to/cannot/
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.
overlord/hookstate/ctlcmd/mount.go
Outdated
} | ||
|
||
if err := sysd.Start(name); err != nil { | ||
// TODO remove mount unit? |
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.
yes, that makes sense I think
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.
Done
overlord/hookstate/ctlcmd/mount.go
Outdated
|
||
if err := sysd.Start(name); err != nil { | ||
// TODO remove mount unit? | ||
return fmt.Errorf("Failed to start mount unit: %v", 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.
same about the error
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.
overlord/hookstate/ctlcmd/umount.go
Outdated
var ( | ||
shortUmountHelp = i18n.G("Undo a temporary or permanent mount") | ||
longUmountHelp = i18n.G(` | ||
The umount command unmounts the given mount point.`) |
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.
umount should mention that the mount point should have been created with snapctl mount
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.
overlord/hookstate/ctlcmd/mount.go
Outdated
} | ||
|
||
if m.Type != "" { | ||
// TODO: what should we do if the type is not given? |
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 should accept Type to be empty only if it's empty also in the attributes. In that case we also will omit from the unit.
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.
return false | ||
} | ||
|
||
expandedPattern := snapInfo.ExpandSnapVariables(pattern) |
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.
afaict the unit tests don't exercise this code, we need test for $SNAP_DATA and $SNAP_COMMON and the valid/invalid combinations with persistent
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.
Added more tests.
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 don't see them, forgot to push something?
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.
This code is now tested (it appears green in the coverage report), and the combinatio with persistent is tested here. You didn't mention $SNAP_COMMON
in your other comment, so I didn't treat it specially. Let me know if I should.
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.
coverage and tested are not the same thing. I haven't rechecked but if this line is removed no tests fail, so this is not tested.
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.
You are right, I added one test now. I wanted to mock snapInfo.ExpandSnapVariables()
but snap.Info
is not an interface, so I fell back on using the production code and just compose the "where" in such a way that it would replicate the logic of info.DataDir()
.
st.Lock() | ||
defer st.Unlock() | ||
|
||
conns, err := ifacestate.ConnectionStates(st) |
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.
for a follow up but now I think we have 2 or 3 places in ctlcmd doing matches against this, maybe they can share a helper? worth checking at least
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.
another pass, some feedback changes seems not pushed
overlord/hookstate/ctlcmd/mount.go
Outdated
@@ -37,7 +38,9 @@ import ( | |||
var ( | |||
shortMountHelp = i18n.G("Create a temporary or permanent mount") | |||
longMountHelp = i18n.G(` | |||
The mount command mounts the given source onto the given destination path.`) | |||
The mount command mounts the given source onto the given destination path, | |||
provided that the snap has a plug for the mount-control interface which allow |
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/allow/allows/
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.
Done
return false | ||
} | ||
|
||
expandedPattern := snapInfo.ExpandSnapVariables(pattern) |
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 don't see them, forgot to push something?
return false | ||
} | ||
} else { | ||
// The filesystem type was not given; we let it through only if the |
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 this scenario tested?
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.
Yes, one branch was tested by the existing tests, and this new else is tested with this small addition
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 don't see a test for the happy case where both the plug and the command don't have type
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.
The newly added TestHappyWithVariableExpansion()
incidentally tests that. Let me know if you'd rather have a separate test.
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.
thank you, one question about expanding the spread test
|
||
echo "Verify that a mount not matching the allowed FS type will fail" | ||
mkdir -p /media/somedir | ||
if "${SNAP_NAME}".cmd mount -t debugfs "/dev/sda" "/media/somedir"; then |
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.
would it be possible to add a happy/positive test using -t ?
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.
Ah! I tried it with tmpfs, just to realize that the interface does not really support it. I created #11190 to address the issue (and this also adds a positive test for the -t
option)
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
return err | ||
} | ||
|
||
if m.Positional.Where == "" { |
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.
Isn't this already guaranteed by the required:"yes"
in line 43?
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 doesn't seem so; at least, the unit test at https://github.com/mardy/snapd/blob/mount-control-3/overlord/hookstate/ctlcmd/umount_test.go#L108-L111 is able to trigger this condition.
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 doesn't seem so; at least, the unit test at https://github.com/mardy/snapd/blob/mount-control-3/overlord/hookstate/ctlcmd/umount_test.go#L108-L111 is able to trigger this condition.
The test isn't triggering the go-flags validation because of the empty string arg (I left a comment in the test). Fixing that means we can also remove this.
(I quoted your comment because even though I replied in the thread, it doesn't show in the new review's comment which makes this look like I'm talking to myself)
overlord/hookstate/ctlcmd/umount.go
Outdated
|
||
found := false | ||
for _, where := range mountPoints { | ||
if where == m.Positional.Where { |
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: you could invert the condition and continue
to remove a level of nesting but the code isn't contrived as it is so might not be worth it
overlord/hookstate/ctlcmd/mount.go
Outdated
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2021 Canonical Ltd |
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.
* Copyright (C) 2021 Canonical Ltd | |
* Copyright (C) 2022 Canonical Ltd |
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2021 Canonical Ltd |
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.
* Copyright (C) 2021 Canonical Ltd | |
* Copyright (C) 2022 Canonical Ltd |
overlord/hookstate/ctlcmd/umount.go
Outdated
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2021 Canonical Ltd |
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.
* Copyright (C) 2021 Canonical Ltd | |
* Copyright (C) 2022 Canonical Ltd |
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
||
/* | ||
* Copyright (C) 2021 Canonical Ltd |
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.
* Copyright (C) 2021 Canonical Ltd | |
* Copyright (C) 2022 Canonical Ltd |
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
overlord/hookstate/ctlcmd/umount.go
Outdated
) | ||
|
||
var ( | ||
shortUmountHelp = i18n.G("Undo a temporary or permanent mount") |
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^2, maybe "Remove a temporary.." or "Unmount a temporary.." ?
a4611cd
to
ff43166
Compare
_, _, err := ctlcmd.Run(s.mockContext, []string{"umount", ""}, 0) | ||
c.Check(err, ErrorMatches, `mount point cannot be empty`) |
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.
This test isn't triggering the go-flags validation because of the empty string arg. Removing it fixes it (which means we also don't need to do the manual validation in umount.go)
_, _, err := ctlcmd.Run(s.mockContext, []string{"umount", ""}, 0) | |
c.Check(err, ErrorMatches, `mount point cannot be empty`) | |
_, _, err := ctlcmd.Run(s.mockContext, []string{"umount"}, 0) | |
c.Check(err, ErrorMatches, "the required argument `<where>` was not provided") |
return err | ||
} | ||
|
||
if m.Positional.Where == "" { |
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 doesn't seem so; at least, the unit test at https://github.com/mardy/snapd/blob/mount-control-3/overlord/hookstate/ctlcmd/umount_test.go#L108-L111 is able to trigger this condition.
The test isn't triggering the go-flags validation because of the empty string arg (I left a comment in the test). Fixing that means we can also remove this.
(I quoted your comment because even though I replied in the thread, it doesn't show in the new review's comment which makes this look like I'm talking to myself)
This adds support for persistent mounts, via a
snapctl
subcommand.