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
devicestate/firstboot: check for missing bases early #7219
devicestate/firstboot: check for missing bases early #7219
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7219 +/- ##
==========================================
- Coverage 80.44% 80.43% -0.01%
==========================================
Files 636 636
Lines 49788 49800 +12
==========================================
+ Hits 40050 40056 +6
- Misses 6631 6635 +4
- Partials 3107 3109 +2
Continue to review full report at Codecov.
|
overlord/devicestate/firstboot.go
Outdated
@@ -76,6 +76,24 @@ func installSeedSnap(st *state.State, sn *snap.SeedSnap, flags snapstate.Flags, | |||
return snapstate.InstallPath(st, &sideInfo, path, "", sn.Channel, flags) | |||
} | |||
|
|||
func checkSeedBases(snaps []*snap.Info) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good if some of the checks that snap debug validate-seed
does would share code with this (or vice versa). See https://github.com/mvo5/snappy/blob/master/image/image.go#L792 and #7105
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks
image/image.go
Outdated
} | ||
} | ||
// ensure core is available | ||
if info.Base == "" && info.SnapType == snap.TypeApp && info.InstanceName() != "snapd" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split this out into info.EffectiveBase()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as long as we find at least a couple other places that can use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a suggestion about a particular line that can be done in a follow up.
errs := image.CheckBasesAndProviders(allSnapInfos) | ||
if errs != nil { | ||
// only report the first error encountered | ||
return nil, errs[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should do something similar to https://github.com/snapcore/snapd/pull/7219/files#diff-da07f373046a0a24e67b18699dc15a70L845 here, i.e. build an error that contains all the individual issues? Maybe we can make the result from "CheckBaseAndProviders" something like:
type MultiErr struct {
Header string
errs []errors
}
func (e MultiErr) Add(errs []error) { ... }
func (e MultiErr) Error() string {
var buf bytes.Buffer
for _, err := range e.errs {
fmt.Fprintf(&buf, "\n- %s", err)
}
return fmt.Sprintf("%s:%s", e.Header, buf.Bytes())
}
but looking at it it (after I typed it out) it seems like this should probably a separate PR and get a 👍 from @pedrons first :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I was considering this and I'm happy to reconsider. The reason I did it this way is prepare-image
validates all aspects of the image and reports all errors at once and this is useful summary for the user when assembling an image. However, when the image is already booted I thought it's fine to report just one error which is in-line with error reporting we normally do in snapd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I don't think it's worth the complexity in seeding code itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misread the issue, I'm fine either way given this will end up in snap/ code.
overlord/devicestate/firstboot.go
Outdated
@@ -31,6 +31,7 @@ import ( | |||
"github.com/snapcore/snapd/asserts/snapasserts" | |||
"github.com/snapcore/snapd/dirs" | |||
"github.com/snapcore/snapd/i18n" | |||
"github.com/snapcore/snapd/image" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to import in this direction though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved CheckBasesAndProviders to snap package (and renamed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want snapd to import image
…enamed to ValidateBasesAndProviders.
… into firsboot-early-basecheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, a comment about unit tests for ValidateBasesAndProviders
} | ||
|
||
// ValidateBasesAndProviders checks that all bases/default-providers are part of the seed | ||
func ValidateBasesAndProviders(snapInfos map[string]*Info) []error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that it's here, this probably needs some unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added (+ we have the existing tests in image/validate_seed_test.go).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, please ask one of the reviewers to give a final look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one question about the snapd snap check, but otherwise LGTM
442374e
to
7feb293
Compare
Check for missing bases and error out early in firstboot seeding.