-
Notifications
You must be signed in to change notification settings - Fork 595
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
client,cmd/snap: introduce --user, --system and --users switches for snap service operations #13368
client,cmd/snap: introduce --user, --system and --users switches for snap service operations #13368
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #13368 +/- ##
=======================================
Coverage 78.89% 78.90%
=======================================
Files 1040 1040
Lines 133862 133907 +45
=======================================
+ Hits 105610 105655 +45
Misses 21658 21658
Partials 6594 6594
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
f4f3727
to
248cd9b
Compare
dbbef85
to
371b5fc
Compare
@@ -183,13 +184,119 @@ func (client *Client) Logs(names []string, opts LogOptions) (<-chan Log, error) | |||
return ch, nil | |||
} | |||
|
|||
type UserSelection int |
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.
All of this has been moved from servicestate to share with client
for _, sc := range scs { | ||
id, err := cs.cli.Stop(sc.names, sc.opts) | ||
for _, sc := range tests { | ||
comment := check.Commentf("{%q; %q; %q; %#v}", sc.names, sc.scope, sc.users, sc.opts) |
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.
btw. you can also c.Logf("testing ... ")
, IIRC the logs are displayed if a test fails
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.
remark about aligning with pebble
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
85bcf3e
to
cbaada6
Compare
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.
couple of questions
cmd/snap/cmd_services.go
Outdated
type userAndScopeMixin struct { | ||
System bool `long:"system"` | ||
User bool `long:"user"` | ||
Users string `long:"users" optional:"yes" optional-value:"all"` |
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 remind me what optional-value:"all" does ?
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, it allows you to use --users
and the value will default to =all
. So doing --users
is equivalent to using --users=all
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 think we want this, as we discussed elsewhere --users and --user are a typo away, and pebble doesn't seem to do this for --users. We want to force to spell out the full --users=all
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 this to not allow --users
} | ||
|
||
func (um *userAndScopeMixin) validateScopes() error { | ||
switch { |
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.
does is make sense to set --system and --user/--users together?
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.
As maciej also pointed out, it probably makes sense to allow providing --system --users
which is equivalent to the default behaviour which is providing nothing.
I also allow --system --user
to allow restarting system services and only the current user's services, since they are allowed to use individually, it probably makes sense to just allow them in one go.
OTOH it's a bit confusing so I'm open to modifications on this
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 now I would not allow, --system and --user together. OTOH if we support --system --users we need to have a spread test for it as well that checks both kind of services
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 disabled --system --user
together for now, if we think it should be enabled we can add a case in the spread test for it later.
cmd/snap/cmd_services_test.go
Outdated
}) | ||
c.Check(checkInvocation(op, summaries[i], []string{"foo", "bar"}, []string{"user", "system"}), check.DeepEquals, map[string]interface{}{ | ||
"action": op, | ||
"names": []interface{}{"foo", "bar"}, |
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.
probably worth saying something about what happens with scope here, is system/users the default?
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 a comment revolving this
} | ||
|
||
func (um *userAndScopeMixin) validateScopes() error { | ||
switch { |
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 now I would not allow, --system and --user together. OTOH if we support --system --users we need to have a spread test for it as well that checks both kind of services
…snap service operations
cbaada6
to
98352c0
Compare
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.
question
…ce a value for it, add case for --system --users=all in spread test
2f78e1e
to
1a9a790
Compare
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, comment about the help string for --users
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
Introduces the new switches
--user
to select user services for the current user,--system
to select system services and--users
to select user services for all users for the following operations:snap start
,snap stop
andsnap restart