Skip to content
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

Merged
merged 9 commits into from
Mar 13, 2024

Conversation

Meulengracht
Copy link
Member

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 and snap restart

@github-actions github-actions bot added the Needs Documentation -auto- Label automatically added which indicates the change needs documentation label Nov 17, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2023

Codecov Report

Attention: Patch coverage is 92.30769% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 78.90%. Comparing base (81d3d51) to head (98352c0).

Files Patch % Lines
client/apps.go 87.14% 8 Missing and 1 partial ⚠️

❗ 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           
Flag Coverage Δ
unittests 78.90% <92.30%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Meulengracht Meulengracht force-pushed the feature/user-service-5 branch 2 times, most recently from f4f3727 to 248cd9b Compare February 23, 2024 13:33
@github-actions github-actions bot added Needs Documentation -auto- Label automatically added which indicates the change needs documentation and removed Needs Documentation -auto- Label automatically added which indicates the change needs documentation labels Feb 23, 2024
@Meulengracht Meulengracht force-pushed the feature/user-service-5 branch from dbbef85 to 371b5fc Compare February 23, 2024 13:45
@Meulengracht Meulengracht marked this pull request as ready for review February 23, 2024 13:46
@@ -183,13 +184,119 @@ func (client *Client) Logs(names []string, opts LogOptions) (<-chan Log, error)
return ch, nil
}

type UserSelection int
Copy link
Member Author

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

@Meulengracht Meulengracht added this to the 2.62 milestone Feb 29, 2024
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)
Copy link
Contributor

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

cmd/snap/cmd_services.go Outdated Show resolved Hide resolved
cmd/snap/cmd_services.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@pedronis pedronis left a 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

cmd/snap/cmd_services.go Outdated Show resolved Hide resolved
@Meulengracht
Copy link
Member Author

@bboozzoo @pedronis I updated the PR on switch names and allowed input.

bboozzoo
bboozzoo previously approved these changes Mar 7, 2024
Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

tests/main/services-user/task.yaml Show resolved Hide resolved
@Meulengracht Meulengracht force-pushed the feature/user-service-5 branch from 85bcf3e to cbaada6 Compare March 7, 2024 14:35
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of questions

type userAndScopeMixin struct {
System bool `long:"system"`
User bool `long:"user"`
Users string `long:"users" optional:"yes" optional-value:"all"`
Copy link
Collaborator

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 ?

Copy link
Member Author

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

Copy link
Collaborator

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

Copy link
Member Author

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 {
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Collaborator

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

Copy link
Member Author

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.

@Meulengracht Meulengracht requested a review from pedronis March 12, 2024 07:34
})
c.Check(checkInvocation(op, summaries[i], []string{"foo", "bar"}, []string{"user", "system"}), check.DeepEquals, map[string]interface{}{
"action": op,
"names": []interface{}{"foo", "bar"},
Copy link
Collaborator

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?

Copy link
Member Author

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 {
Copy link
Collaborator

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

@Meulengracht Meulengracht force-pushed the feature/user-service-5 branch from cbaada6 to 98352c0 Compare March 12, 2024 09:05
@Meulengracht Meulengracht requested a review from pedronis March 12, 2024 09:07
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

cmd/snap/cmd_services.go Outdated Show resolved Hide resolved
…ce a value for it, add case for --system --users=all in spread test
@Meulengracht Meulengracht force-pushed the feature/user-service-5 branch from 2f78e1e to 1a9a790 Compare March 13, 2024 08:45
Copy link
Collaborator

@pedronis pedronis left a 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

cmd/snap/cmd_services.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cmd/snap/cmd_services.go Outdated Show resolved Hide resolved
cmd/snap/cmd_services.go Show resolved Hide resolved
@Meulengracht Meulengracht merged commit 261d1c2 into canonical:master Mar 13, 2024
36 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Documentation -auto- Label automatically added which indicates the change needs documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants