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

devicestate/firstboot: check for missing bases early #7219

Merged
merged 12 commits into from Aug 24, 2019

Conversation

stolowski
Copy link
Contributor

Check for missing bases and error out early in firstboot seeding.

@stolowski stolowski requested a review from pedronis August 7, 2019 10:56
@stolowski stolowski added the Needs Samuele review Needs a review from Samuele before it can land label Aug 7, 2019
@codecov-io
Copy link

codecov-io commented Aug 7, 2019

Codecov Report

Merging #7219 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
overlord/devicestate/firstboot.go 81.81% <100%> (+1.17%) ⬆️
httputil/useragent.go 77.14% <0%> (-5.72%) ⬇️
overlord/patch/patch6_2.go 74.28% <0%> (-2.86%) ⬇️
overlord/hookstate/hookmgr.go 72.85% <0%> (-0.96%) ⬇️
cmd/snap-seccomp/main.go 66.66% <0%> (-0.46%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe49b1c...6b9b686. Read the comment docs.

@@ -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 {
Copy link
Member

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

Copy link
Member

@anonymouse64 anonymouse64 left a 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" {
Copy link
Collaborator

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()

Copy link
Collaborator

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

Copy link
Collaborator

@zyga zyga left a 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]
Copy link
Contributor

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 :)

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

@@ -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"
Copy link
Collaborator

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

Copy link
Contributor Author

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).

Copy link
Collaborator

@pedronis pedronis left a 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

@pedronis pedronis self-requested a review August 20, 2019 07:10
Copy link
Collaborator

@pedronis pedronis left a 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 {
Copy link
Collaborator

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

Copy link
Contributor Author

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).

Copy link
Collaborator

@pedronis pedronis left a 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

@pedronis pedronis dismissed their stale review August 22, 2019 12:32

my issue was addressed

@pedronis pedronis removed the Needs Samuele review Needs a review from Samuele before it can land label Aug 22, 2019
Copy link
Member

@anonymouse64 anonymouse64 left a 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

snap/validate.go Show resolved Hide resolved
@pedronis pedronis merged commit 6ac9141 into snapcore:master Aug 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants