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: respect validation sets when refreshing and installing components with snaps #14783

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
32 changes: 31 additions & 1 deletion overlord/snapstate/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ type fakeStore struct {
snapResourcesFn func(*snap.Info) []store.SnapResourceResult

downloadCallback func()

namesToAssertedIDs map[string]string
idsToNames map[string]string

mutateSnapInfo func(*snap.Info) error
}

func (f *fakeStore) registerID(name, id string) {
f.namesToAssertedIDs[name] = id
f.idsToNames[id] = name
}

func (f *fakeStore) snapResources(info *snap.Info) []store.SnapResourceResult {
Expand Down Expand Up @@ -263,7 +273,12 @@ func (f *fakeStore) snap(spec snapSpec) (*snap.Info, error) {

typ := snap.TypeApp
epoch := snap.E("1*")

snapID := spec.Name + "-id"
if id, ok := f.namesToAssertedIDs[spec.Name]; ok {
snapID = id
}

switch spec.Name {
case "core", "core16", "ubuntu-core", "some-core":
typ = snap.TypeOS
Expand Down Expand Up @@ -422,6 +437,12 @@ func (f *fakeStore) snap(spec snapSpec) (*snap.Info, error) {
info.SnapProvenance = "prov"
}

if f.mutateSnapInfo != nil {
if err := f.mutateSnapInfo(info); err != nil {
return nil, err
}
}

return info, nil
}

Expand Down Expand Up @@ -535,7 +556,10 @@ func (f *fakeStore) lookupRefresh(cand refreshCand) (*snap.Info, error) {
name = "kernel-snap-with-components"
typ = snap.TypeKernel
default:
panic(fmt.Sprintf("refresh: unknown snap-id: %s", cand.snapID))
name = f.idsToNames[cand.snapID]
if name == "" {
panic(fmt.Sprintf("refresh: unknown snap-id: %s", cand.snapID))
}
}

revno := snap.R(11)
Expand Down Expand Up @@ -649,6 +673,12 @@ func (f *fakeStore) lookupRefresh(cand refreshCand) (*snap.Info, error) {
}
}

if f.mutateSnapInfo != nil {
if err := f.mutateSnapInfo(info); err != nil {
return nil, err
}
}

var hit snap.Revision
if cand.revision != revno {
hit = revno
Expand Down
18 changes: 18 additions & 0 deletions overlord/snapstate/snapmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,24 @@
return snap.InstanceName(cur.RealName, snapst.InstanceKey)
}

// SnapName returns the name of the snap. Implementation of naming.SnapRef.
func (snapst *SnapState) SnapName() string {
cur := snapst.CurrentSideInfo()
if cur == nil {
return ""
}

Check warning on line 707 in overlord/snapstate/snapmgr.go

View check run for this annotation

Codecov / codecov/patch

overlord/snapstate/snapmgr.go#L706-L707

Added lines #L706 - L707 were not covered by tests
return cur.RealName
}

// ID returns the ID of the snap. Implementation of naming.SnapRef.
func (snapst *SnapState) ID() string {
cur := snapst.CurrentSideInfo()
if cur == nil {
return ""
}

Check warning on line 716 in overlord/snapstate/snapmgr.go

View check run for this annotation

Codecov / codecov/patch

overlord/snapstate/snapmgr.go#L715-L716

Added lines #L715 - L716 were not covered by tests
return cur.SnapID
}

// RefreshInhibitProceedTime is the time after which a pending refresh is forced
// for a running snap in the next auto-refresh. Zero time indicates that there
// are no pending refreshes. st must be locked.
Expand Down
2 changes: 0 additions & 2 deletions overlord/snapstate/snapstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2167,8 +2167,6 @@ func doUpdate(st *state.State, requested []string, updates []update, opts Option
// re-refresh check
needsRerefreshCheck = true

// TODO:COMPS: we need to handle components here too

// Do not set any default restart boundaries, we do it when we have access to all
// the task-sets in preparation for single-reboot.
ts, err := doInstall(st, &up.SnapState, up.Setup, up.Components, noRestartBoundaries, opts.FromChange, inUseFor(opts.DeviceCtx))
Expand Down
Loading
Loading