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 2, 2024
1 parent aa1b8ab commit 905260a
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 @@ -196,6 +196,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 @@ -262,7 +272,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 @@ -421,6 +436,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 @@ -534,7 +555,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 @@ -648,6 +672,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 905260a

Please sign in to comment.