Skip to content

Commit

Permalink
Merge branch 'master' into snap-confine-tmpfs-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy committed Jun 29, 2022
2 parents 4ab853b + d431334 commit ee10e8a
Show file tree
Hide file tree
Showing 161 changed files with 5,802 additions and 1,018 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ jobs:
- debian-10-64
- debian-11-64
- debian-sid-64
- fedora-34-64
- fedora-35-64
- fedora-36-64
- opensuse-15.3-64
- opensuse-15.4-64
- opensuse-tumbleweed-64
- ubuntu-14.04-64
- ubuntu-16.04-64
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cmd/snap-mgmt/snap-mgmt
cmd/snap-seccomp/snap-seccomp
cmd/snap-update-ns/snap-update-ns
cmd/snap-update-ns/unit-tests
cmd/snapd-apparmor/snapd-apparmor
cmd/snapd-env-generator/snapd-env-generator
cmd/snapd-generator/snapd-generator
cmd/system-shutdown/system-shutdown
Expand Down
51 changes: 42 additions & 9 deletions asserts/snapasserts/validation_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func (e *ValidationSetsConflictError) Error() string {
// ValidationSetsValidationError describes an error arising
// from validation of snaps against ValidationSets.
type ValidationSetsValidationError struct {
// MissingSnaps maps missing snap names to the validation sets requiring them.
MissingSnaps map[string][]string
// MissingSnaps maps missing snap names to the expected revisions and respective validation sets requiring them.
// Revisions may be unset if no specific revision is required
MissingSnaps map[string]map[snap.Revision][]string
// InvalidSnaps maps snap names to the validation sets declaring them invalid.
InvalidSnaps map[string][]string
// WronRevisionSnaps maps snap names to the expected revisions and respective
Expand Down Expand Up @@ -94,9 +95,27 @@ func (e *ValidationSetsValidationError) Error() string {
}
}

printDetails("missing required snaps", e.MissingSnaps, func(snapName string, validationSetKeys []string) string {
return fmt.Sprintf("%s (required by sets %s)", snapName, strings.Join(validationSetKeys, ","))
})
if len(e.MissingSnaps) > 0 {
fmt.Fprintf(buf, "\n- missing required snaps:")
for snapName, revisions := range e.MissingSnaps {
revisionsSorted := make([]snap.Revision, 0, len(revisions))
for rev := range revisions {
revisionsSorted = append(revisionsSorted, rev)
}
sort.Sort(byRevision(revisionsSorted))
t := make([]string, 0, len(revisionsSorted))
for _, rev := range revisionsSorted {
keys := revisions[rev]
if rev.Unset() {
t = append(t, fmt.Sprintf("at any revision by sets %s", strings.Join(keys, ",")))
} else {
t = append(t, fmt.Sprintf("at revision %s by sets %s", rev, strings.Join(keys, ",")))
}
}
fmt.Fprintf(buf, "\n - %s (required %s)", snapName, strings.Join(t, ", "))
}
}

printDetails("invalid snaps", e.InvalidSnaps, func(snapName string, validationSetKeys []string) string {
return fmt.Sprintf("%s (invalid for sets %s)", snapName, strings.Join(validationSetKeys, ","))
})
Expand Down Expand Up @@ -367,7 +386,7 @@ func (v *ValidationSets) CheckInstalledSnaps(snaps []*InstalledSnap, ignoreValid

// snapName -> validationSet key -> validation set
invalid := make(map[string]map[string]bool)
missing := make(map[string]map[string]bool)
missing := make(map[string]map[snap.Revision]map[string]bool)
wrongrev := make(map[string]map[snap.Revision]map[string]bool)
sets := make(map[string]*asserts.ValidationSet)

Expand Down Expand Up @@ -411,9 +430,12 @@ func (v *ValidationSets) CheckInstalledSnaps(snaps []*InstalledSnap, ignoreValid
// is only possible to have it with a wrong revision, or installed while invalid, in both
// cases through --ignore-validation flag).
if missing[rc.Name] == nil {
missing[rc.Name] = make(map[string]bool)
missing[rc.Name] = make(map[snap.Revision]map[string]bool)
}
if missing[rc.Name][rev] == nil {
missing[rc.Name][rev] = make(map[string]bool)
}
missing[rc.Name][rc.validationSetKey] = true
missing[rc.Name][rev][rc.validationSetKey] = true
sets[rc.validationSetKey] = v.sets[rc.validationSetKey]
}
}
Expand All @@ -438,9 +460,20 @@ func (v *ValidationSets) CheckInstalledSnaps(snaps []*InstalledSnap, ignoreValid
if len(invalid) > 0 || len(missing) > 0 || len(wrongrev) > 0 {
verr := &ValidationSetsValidationError{
InvalidSnaps: setsToLists(invalid),
MissingSnaps: setsToLists(missing),
Sets: sets,
}
if len(missing) > 0 {
verr.MissingSnaps = make(map[string]map[snap.Revision][]string)
for snapName, revs := range missing {
verr.MissingSnaps[snapName] = make(map[snap.Revision][]string)
for rev, keys := range revs {
for key := range keys {
verr.MissingSnaps[snapName][rev] = append(verr.MissingSnaps[snapName][rev], key)
}
sort.Strings(verr.MissingSnaps[snapName][rev])
}
}
}
if len(wrongrev) > 0 {
verr.WrongRevisionSnaps = make(map[string]map[snap.Revision][]string)
for snapName, revs := range wrongrev {
Expand Down
Loading

0 comments on commit ee10e8a

Please sign in to comment.