Skip to content

Commit

Permalink
o/snapstate: consider validation sets when installing/refreshing comp…
Browse files Browse the repository at this point in the history
…onents with snaps
  • Loading branch information
andrewphelpsj committed Dec 3, 2024
1 parent 12915fe commit bc97387
Show file tree
Hide file tree
Showing 5 changed files with 560 additions and 22 deletions.
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
Loading

0 comments on commit bc97387

Please sign in to comment.