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

wrappers: refactor StopServices to account for sending --disable to the user-session agent #13921

Merged

Conversation

Meulengracht
Copy link
Member

@Meulengracht Meulengracht commented Apr 30, 2024

Refactor StopServices to make it easier to account for disabling user-services.

Changes from this refactor

  • Now has a more identical flow to StartService in terms of ordering of user and system services, except in reverse.
  • Correctly proxies the --disable request to the user-session agent.

}
// categorizeServices returns a list of system and user services
// ordered by the same order that 'app' is passed into.
func categorizeServices(apps []*snap.AppInfo, includeActivators bool) ([]string, []string) {
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 have a cleanup planned for StartServices that will use this function too, which is why the includeActivators part exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #13958 for details

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.

Thanks. I'm confused by the naming of the flag that is not quite used yet. Also this seems more than a refactor?

wrappers/services.go Outdated Show resolved Hide resolved
@Meulengracht Meulengracht requested a review from pedronis May 3, 2024 19:02
wrappers/services.go Show resolved Hide resolved
wrappers/services.go Outdated Show resolved Hide resolved
wrappers/services.go Show resolved Hide resolved
wrappers/services.go Show resolved Hide resolved
wrappers/services.go Show resolved Hide resolved
wrappers/services.go Show resolved Hide resolved
wrappers/services.go Show resolved Hide resolved
wrappers/services.go Show resolved Hide resolved
Copy link
Collaborator

@ernestl ernestl left a comment

Choose a reason for hiding this comment

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

Approved, after fixing minor issues, disregarding the non-ideal stopServices with --disable, with knowledge of followup cleanup PR.

wrappers/services.go Show resolved Hide resolved
@@ -195,7 +194,9 @@ func stopService(sysd systemd.Systemd, cli *userServiceClient, scope snap.Daemon
}

case snap.UserDaemon:
if err := cli.stopServices(svcs...); err != nil {
// Only called as a part of undoing in StartServices
const disable = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

To me its not obvious why we have to set disable to false, one might expect this as default behavior of a "stop" function, to stop and not disable. I would recommend an explanation.

Furthermore, to hardcode disable into function so that it is appropriate for use in a single context does not seem ideal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

After discussion this:

  • There is inherent undo logic in the user-session agent itself
  • So actually, what StartServices should not be doing, is handling undo logic for user-services

In a followup cleanup PR, stopService is removed and a cleaner solution implemented.

Will ignore this as a means to a followup improvement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

for clarity might still be a good idea for now to add a doc comment to the function explaing that it stops services without disabling them

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, added

wrappers/services.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

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

Project coverage is 78.76%. Comparing base (ab996a0) to head (25f40e9).
Report is 276 commits behind head on master.

Files Patch % Lines
wrappers/services.go 0.00% 71 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13921      +/-   ##
==========================================
- Coverage   78.86%   78.76%   -0.10%     
==========================================
  Files        1043     1046       +3     
  Lines      134595   136393    +1798     
==========================================
+ Hits       106144   107436    +1292     
- Misses      21837    22234     +397     
- Partials     6614     6723     +109     
Flag Coverage Δ
unittests 78.76% <0.00%> (-0.10%) ⬇️

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.

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.

thanks, some small comments

}
// categorizeServices returns a list of system and user services
// ordered by the same order that 'app' is passed into.
func categorizeServices(apps []*snap.AppInfo, includeActivatedServices bool) ([]string, []string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be good for the return value to have names as well so it's clearer what is what

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice suggestion

@@ -195,7 +194,9 @@ func stopService(sysd systemd.Systemd, cli *userServiceClient, scope snap.Daemon
}

case snap.UserDaemon:
if err := cli.stopServices(svcs...); err != nil {
// Only called as a part of undoing in StartServices
const disable = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

for clarity might still be a good idea for now to add a doc comment to the function explaing that it stops services without disabling them


disableServices := []string{}
func filterAppsForStop(apps []*snap.AppInfo, reason snap.ServiceStopReason, flags *StopServicesFlags) []*snap.AppInfo {
Copy link
Collaborator

Choose a reason for hiding this comment

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

now that this is a separate helper it might be worth adding a doc comment with a summary of what is does, how arguments affect that

Copy link
Member Author

Choose a reason for hiding this comment

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

Same, this is a great point and will add this for start as well

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 assuming comments from @pedronis are addressed

@Meulengracht Meulengracht merged commit a77998c into canonical:master Jun 7, 2024
43 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants