overlord/snapstate: introduce tasks for aliases v2 semantics with temporary names for now (aliases v2) #3087

Merged
merged 18 commits into from Apr 13, 2017

Conversation

Projects
None yet
3 participants
Contributor

pedronis commented Mar 27, 2017

This introduces new tasks for the aliases v2 semantics. They are added with temporary "*-v2" names for now, they are not used in changes yet but can be tested this way.

Next couple of branches will do the switch over, migration and take care of most TODOs here except for implementing --prefer etc that will come after the basics are in place.

The old aliases could reuse the "alias" task "reset" mode to support changes to automatic aliases independent of a new revision of the snap on refresh, for the new world this introduces "refresh-aliases" and "drop-auto-aliases" for those situations.

This will be relatively large even after the prereqs are merged but much more than half of this are tests.

I'm not entirely happy about the logic handling "Pending" and AliasesStatus, open to suggestions there.

@pedronis pedronis added the Critical label Mar 27, 2017

Contributor

pedronis commented Mar 27, 2017

based on #3082

@pedronis pedronis changed the title from overlord/snapstate: introduce tasks for aliases v2 semantics with temporary names for now to overlord/snapstate: introduce tasks for aliases v2 semantics with temporary names for now (aliases v2) Mar 27, 2017

@pedronis pedronis closed this Apr 2, 2017

@pedronis pedronis reopened this Apr 3, 2017

overlord/snapstate/aliasesv2.go
+ EnabledAliases AliasesStatus = "enabled"
+ DisabledAliases AliasesStatus = "disabled"
+ PendingEnabledAliases AliasesStatus = "pending:enabled"
+ PendingDisabledAliases AliasesStatus = "pending:disabled"
@niemeyer

niemeyer Apr 7, 2017

Contributor

I think the bad smell you found here comes from us merging what are actually two statuses in a single one:

  • Do we want aliases enabled for this snap? (AliasesEnabled bool, maybe)
  • Is there work pending to put that desired status in place? (AliasesPending bool, maybe)

That removes the need for all these constants and all of the methods below, so seems like a clear win. As another minor benefit, AliasesPending will disappear in most cases due to omitempty.

Then, there's that fourth curious status which I don't yet see where it comes from. Reading on...

@pedronis

pedronis Apr 7, 2017

Contributor

We discussed to indeed switch this to AliasesPending and AutoAliasesDisabled (both bool flags)

overlord/snapstate/aliasesv2.go
+ return false
+}
+
+// NoAutoYet return whether the status indicates no automatic aliases were introduced yet for the snap.
@niemeyer

niemeyer Apr 7, 2017

Contributor

Do we really need that status? It feels like it should be something to compute dynamically just looking at the Enabled status plus the Aliases we currently have at hand. This would also make the logic slightly easier to read.

overlord/snapstate/aliasesv2.go
+ newAliases[alias] = &AliasTarget{Auto: curTarget.Auto}
+ }
+ }
+ return curStatus.ToDisabled(), newAliases
@niemeyer

niemeyer Apr 7, 2017

Contributor

Assuming suggestions above, that first bool might go since we can simply set Enabled to false.

overlord/snapstate/aliasesv2.go
+ return curStatus.ToDisabled(), newAliases
+}
+
+// pruneAutoAliases returns newAliases by dropping the automatic aliases autoAliases from curAliases, used as the task prune-auto-aliases to handle transfers of automatic aliases in a refresh.
@niemeyer

niemeyer Apr 7, 2017

Contributor

I wonder if we shouldn't drop the manual aliases in those cases as well. Not something to worry too much about right now, though. We can easily tune the behavior depending on experience and user reaction.

overlord/snapstate/handlers.go
+ return err
+ }
+ if status.NoAutoYet() && nAuto != 0 {
+ status = PendingEnabledAliases
@niemeyer

niemeyer Apr 7, 2017

Contributor

Shouldn´t that be done every time there are new auto aliases, rather than just when going from zero to something?

In either case, per notes above I think we might build the above conditional just looking at the data, instead of requiring a stored state. But perhaps I'm missing something.

overlord/snapstate/handlers.go
+ if err != nil {
+ return err
+ }
+ if status.NoAutoYet() && nAuto != 0 {
@niemeyer

niemeyer Apr 7, 2017

Contributor

Similar case.

overlord/snapstate/handlers.go
+ snapst.Aliases = newAliases
+ Set(st, snapName, snapst)
+ return nil
+}
@niemeyer

niemeyer Apr 7, 2017

Contributor

These task handlers are super readable despite the complexity of the problem.

Thanks for pulling that off!

pedronis added some commits Mar 24, 2017

break the /aliases mutation API with a clean 400, this breaks indirec…
…tly the commands with errors... skip/comment out some tests that might be portable later, delete some that are unlikely to be relevant
we missed this do/undo symmetry the last time around, it's a good sim…
…plification and wil work also in the new world
introduce a pending concept for aliases status to track the removal f…
…rom disk of aliases during any install-like operation with a window not matching the Active flag one
Merge branch 'aliases-v2-simpler-status' into aliases-v2-wip-tasks
adapt&simplify to aliases status tracking through bool flags
daemon/api.go
- if len(a.Aliases) == 0 {
- return BadRequest("at least one alias name is required")
+ if len(a.Aliases) != 0 {
+ return BadRequest("cannot interpret request, snaps can no longer be expected to declare their aliases")
@niemeyer

niemeyer Apr 8, 2017

Contributor

Won't manual aliases still require it?

@pedronis

pedronis Apr 9, 2017

Contributor

yes, one of the next PRs needs to bring some form of this API back but probably we still need to use different fields or type, and be able to get a clean error for the previous usage

overlord/snapstate/aliasesv2.go
+ return newAliases
+}
+
+// pruneAutoAliases returns newAliases by dropping the automatic aliases autoAliases from curAliases, used as the task prune-auto-aliases to handle transfers of automatic aliases in a refresh.
@niemeyer

niemeyer Apr 8, 2017

Contributor

Per our call this week, I think it'd make sense to disable manual aliases in this case as well. It's not a big deal to move it forward like this if you'd prefer, since we can easily tune the behavior later as we learn more, but it feels slightly surprising to have only the auto ones disabled.

@pedronis

pedronis Apr 9, 2017

Contributor

I think there is a bit of confusion here, this is not for "prefer" and friends, "prefer" will indeed remove also manual aliases . This is for a corner case that we need to support though (in the old world we were using the task for snap alias --reset for this), this is about automatic aliases that go from being exposed from snap A to being exposed by another snap B (to be realistic this would probably involve related snaps or some snap being split for some reason)

@chipaca

chipaca Apr 13, 2017

Member

please wrap the comment

@@ -819,3 +819,194 @@ func (m *SnapManager) doDiscardSnap(t *state.Task, _ *tomb.Tomb) error {
Set(st, snapsup.Name(), snapst)
return nil
}
+
+// aliases v2
@niemeyer

niemeyer Apr 8, 2017

Contributor

It would be great to have here a comment explaining why we have the multi-step process below with multiple tasks, and why we need the pending flag, as this will definitely feel a bit surprising and confusing on a first read.

It's okay to do that on a follow up though.

@pedronis

pedronis Apr 9, 2017

Contributor

I can add that to the next one indeed

@pedronis pedronis added this to the 2.25 milestone Apr 11, 2017

pedronis added some commits Apr 12, 2017

overlord/snapstate/aliasesv2.go
+ return newAliases
+}
+
+// pruneAutoAliases returns newAliases by dropping the automatic aliases autoAliases from curAliases, used as the task prune-auto-aliases to handle transfers of automatic aliases in a refresh.
@niemeyer

niemeyer Apr 8, 2017

Contributor

Per our call this week, I think it'd make sense to disable manual aliases in this case as well. It's not a big deal to move it forward like this if you'd prefer, since we can easily tune the behavior later as we learn more, but it feels slightly surprising to have only the auto ones disabled.

@pedronis

pedronis Apr 9, 2017

Contributor

I think there is a bit of confusion here, this is not for "prefer" and friends, "prefer" will indeed remove also manual aliases . This is for a corner case that we need to support though (in the old world we were using the task for snap alias --reset for this), this is about automatic aliases that go from being exposed from snap A to being exposed by another snap B (to be realistic this would probably involve related snaps or some snap being split for some reason)

@chipaca

chipaca Apr 13, 2017

Member

please wrap the comment

@pedronis pedronis merged commit 7ae7698 into snapcore:master Apr 13, 2017

2 of 6 checks passed

xenial-amd64 autopkgtest running
Details
xenial-ppc64el autopkgtest running
Details
yakkety-amd64 autopkgtest running
Details
zesty-amd64 autopkgtest running
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-i386 autopkgtest finished (success)
Details

@pedronis pedronis deleted the pedronis:aliases-v2-wip-tasks branch Apr 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment