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

o/snapstate: handle refreshing a snap that only has component revision changes #14486

Merged
merged 13 commits into from
Sep 13, 2024

Conversation

andrewphelpsj
Copy link
Member

@andrewphelpsj andrewphelpsj commented Sep 11, 2024

This handles the case where we go to refresh a snap and see that only components have been refreshed, rather than just the snap.

@@ -561,12 +565,6 @@ func (m *SnapManager) doUnlinkComponent(t *state.Task, _ *tomb.Tomb) (err error)
return err
}

// TODO:COMPS: test taking this branch when unlinking components during a
// refresh where we lose components
if err := saveCurrentKernelModuleComponents(t, snapSup, snapSt); err != nil {
Copy link
Member Author

@andrewphelpsj andrewphelpsj Sep 11, 2024

Choose a reason for hiding this comment

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

This was in the wrong place. We now do this in these 3 places:

link-component
unlink-current-component
link-snap

Previously we had it in unlink-component, rather than unlink-current-component. unlink-component isn't run during a snap refresh, that is only run when we are explicitly removing a snap (with its components)

Choose a reason for hiding this comment

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

are we sure we do not need to save the kernel-modules components here too? For instance, if we are removing one of these components, to get the state restored on rollback. I'm not sure if in that case we do an unlink current component.

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case we use "unlink-current-component", since we don't support removing components for anything but the current snap revision.

Copy link
Member Author

Choose a reason for hiding this comment

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

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 comments also I'm not sure I fully understand the change in handlers.go

compSetupTaskID string
beforeLink []*state.Task
linkTask *state.Task
postOpHookToDiscard []*state.Task
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does ToDiscard means here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The range of the tasks, [post-refresh/install hook -> discard). I'm happy to take suggestions on naming there.

Copy link
Collaborator

@pedronis pedronis Sep 12, 2024

Choose a reason for hiding this comment

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

maybe all *state.Task field should have a name ending in "Task", and all the []*state.Task ones, one ending in "Tasks" ?

overlord/snapstate/snapstate.go Outdated Show resolved Hide resolved
@@ -1881,12 +1885,32 @@ type update struct {
// revision of the snap.
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems the doc comment for this needs changes, also I wonder if turning this around and calling it revisionDiverged wouldn't be clear?

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 personally think that "satisfied" works better here as a method on update, since it reads as the update has already been satisfied. Using diverged implies something different to me, almost as if something has unexpectedly changed.

@@ -2714,7 +2714,7 @@ func (m *SnapManager) undoLinkSnap(t *state.Task, _ *tomb.Tomb) error {
return err
}

if len(snapst.Sequence.Revisions) == 1 {
if oldCurrent.Unset() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this mean doing this only on firstInstall ? maybe is a good idea to call the name the predicate like that and use the var? I'm not entirely sure I understand the need for this change

Copy link
Member Author

Choose a reason for hiding this comment

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

During a refresh where we only refresh components, we treat it a lot like snap refresh --revision=n snapname, where n is the current revision of the snap. In that case, this undo handler wouldn't do the right thing. We don't want to treat it as if the snap is completely removed, since it isn't.

Naming the predicate to firstInstall is a good idea, I'll do 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.

Added tests for this case here: 541066d

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 answered about the naming question

Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato 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 have a couple of questions

compSetupTaskID string
beforeLinkTasks []*state.Task
linkTask *state.Task
postOpHookToDiscardTasks []*state.Task

Choose a reason for hiding this comment

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

nitpick²: maybe postLinkHookToDiscardTasks now that you are changing names? The "Op" is not saying too much I think.

@@ -561,12 +565,6 @@ func (m *SnapManager) doUnlinkComponent(t *state.Task, _ *tomb.Tomb) (err error)
return err
}

// TODO:COMPS: test taking this branch when unlinking components during a
// refresh where we lose components
if err := saveCurrentKernelModuleComponents(t, snapSup, snapSt); err != nil {

Choose a reason for hiding this comment

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

are we sure we do not need to save the kernel-modules components here too? For instance, if we are removing one of these components, to get the state restored on rollback. I'm not sure if in that case we do an unlink current component.

overlord/snapstate/snapstate.go Show resolved Hide resolved
Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 73.68421% with 15 lines in your changes missing coverage. Please review.

Project coverage is 78.83%. Comparing base (f60b3de) to head (d838bc8).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
overlord/snapstate/snapstate.go 74.28% 6 Missing and 3 partials ⚠️
overlord/snapstate/handlers_components.go 25.00% 2 Missing and 1 partial ⚠️
overlord/snapstate/target.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #14486   +/-   ##
=======================================
  Coverage   78.83%   78.83%           
=======================================
  Files        1078     1078           
  Lines      145031   145096   +65     
=======================================
+ Hits       114332   114393   +61     
- Misses      23540    23543    +3     
- Partials     7159     7160    +1     
Flag Coverage Δ
unittests 78.83% <73.68%> (+<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.

@andrewphelpsj andrewphelpsj merged commit 3b2350f into canonical:master Sep 13, 2024
55 of 56 checks passed
@andrewphelpsj andrewphelpsj deleted the refresh-only-components branch September 13, 2024 13:02
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.

3 participants