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
seed/seedwriter: consider modes when checking for deps availability #9710
Merged
pedronis
merged 3 commits into
snapcore:master
from
pedronis:seedwriter-check-modes-for-deps
Nov 30, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,15 @@ type SeedSnap struct { | |
optionSnap *OptionsSnap | ||
} | ||
|
||
func (sn *SeedSnap) modes() []string { | ||
if sn.modelSnap == nil { | ||
// run is the assumed mode for extra snaps not listed | ||
// in the model | ||
return []string{"run"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
return sn.modelSnap.Modes | ||
} | ||
|
||
var _ naming.SnapRef = (*SeedSnap)(nil) | ||
|
||
/* Writer writes Core 16/18 and Core 20 seeds. | ||
|
@@ -172,7 +181,8 @@ type Writer struct { | |
localSnaps map[*OptionsSnap]*SeedSnap | ||
byRefLocalSnaps *naming.SnapSet | ||
|
||
availableSnaps *naming.SnapSet | ||
availableSnaps *naming.SnapSet | ||
availableByMode map[string]*naming.SnapSet | ||
|
||
// toDownload tracks which set of snaps SnapsToDownload should compute | ||
// next | ||
|
@@ -194,11 +204,13 @@ type policy interface { | |
modelSnapDefaultChannel() string | ||
extraSnapDefaultChannel() string | ||
|
||
checkBase(*snap.Info, *naming.SnapSet) error | ||
checkBase(s *snap.Info, modes []string, availableByMode map[string]*naming.SnapSet) error | ||
|
||
checkAvailable(snpRef naming.SnapRef, modes []string, availableByMode map[string]*naming.SnapSet) bool | ||
|
||
needsImplicitSnaps(*naming.SnapSet) (bool, error) | ||
implicitSnaps(*naming.SnapSet) []*asserts.ModelSnap | ||
implicitExtraSnaps(*naming.SnapSet) []*OptionsSnap | ||
needsImplicitSnaps(availableByMode map[string]*naming.SnapSet) (bool, error) | ||
implicitSnaps(availableByMode map[string]*naming.SnapSet) []*asserts.ModelSnap | ||
implicitExtraSnaps(availableByMode map[string]*naming.SnapSet) []*OptionsSnap | ||
} | ||
|
||
type tree interface { | ||
|
@@ -769,11 +781,11 @@ func (w *Writer) SnapsToDownload() (snaps []*SeedSnap, err error) { | |
} | ||
return toDownload, nil | ||
case toDownloadImplicit: | ||
return w.modelSnapsToDownload(w.policy.implicitSnaps(w.availableSnaps)) | ||
return w.modelSnapsToDownload(w.policy.implicitSnaps(w.availableByMode)) | ||
case toDownloadExtra: | ||
return w.extraSnapsToDownload(w.optExtraSnaps()) | ||
case toDownloadExtraImplicit: | ||
return w.extraSnapsToDownload(w.policy.implicitExtraSnaps(w.availableSnaps)) | ||
return w.extraSnapsToDownload(w.policy.implicitExtraSnaps(w.availableByMode)) | ||
default: | ||
panic(fmt.Sprintf("unknown to-download set: %d", w.toDownload)) | ||
} | ||
|
@@ -820,7 +832,7 @@ func (w *Writer) resolveChannel(whichSnap string, modSnap *asserts.ModelSnap, op | |
return resChannel, nil | ||
} | ||
|
||
func (w *Writer) checkBase(info *snap.Info) error { | ||
func (w *Writer) checkBase(info *snap.Info, modes []string) error { | ||
// Sanity check, note that we could support this case | ||
// if we have a use-case but it requires changes in the | ||
// devicestate/firstboot.go ordering code. | ||
|
@@ -833,19 +845,29 @@ func (w *Writer) checkBase(info *snap.Info) error { | |
return nil | ||
} | ||
|
||
return w.policy.checkBase(info, w.availableSnaps) | ||
return w.policy.checkBase(info, modes, w.availableByMode) | ||
} | ||
|
||
func (w *Writer) downloaded(seedSnaps []*SeedSnap) error { | ||
if w.availableSnaps == nil { | ||
w.availableSnaps = naming.NewSnapSet(nil) | ||
w.availableByMode = make(map[string]*naming.SnapSet) | ||
w.availableByMode["run"] = naming.NewSnapSet(nil) | ||
} | ||
|
||
for _, sn := range seedSnaps { | ||
if sn.Info == nil { | ||
return fmt.Errorf("internal error: before seedwriter.Writer.Downloaded snap %q Info should have been set", sn.SnapName()) | ||
} | ||
w.availableSnaps.Add(sn) | ||
for _, mode := range sn.modes() { | ||
byMode := w.availableByMode[mode] | ||
if byMode == nil { | ||
byMode = naming.NewSnapSet(nil) | ||
w.availableByMode[mode] = byMode | ||
} | ||
byMode.Add(sn) | ||
} | ||
} | ||
|
||
for _, sn := range seedSnaps { | ||
|
@@ -873,14 +895,16 @@ func (w *Writer) downloaded(seedSnaps []*SeedSnap) error { | |
return fmt.Errorf("cannot use classic snap %q in a core system", info.SnapName()) | ||
} | ||
|
||
if err := w.checkBase(info); err != nil { | ||
modes := sn.modes() | ||
|
||
if err := w.checkBase(info, modes); err != nil { | ||
return err | ||
} | ||
// error about missing default providers | ||
for dp := range snap.NeededDefaultProviders(info) { | ||
if !w.availableSnaps.Contains(naming.Snap(dp)) { | ||
if !w.policy.checkAvailable(naming.Snap(dp), modes, w.availableByMode) { | ||
// TODO: have a way to ignore this issue on a snap by snap basis? | ||
return fmt.Errorf("cannot use snap %q without its default content provider %q being added explicitly", info.SnapName(), dp) | ||
return fmt.Errorf("cannot use snap %q without its default content provider %q being added explicitly%s", info.SnapName(), dp, errorMsgForModesSuffix(modes)) | ||
} | ||
} | ||
|
||
|
@@ -925,7 +949,7 @@ func (w *Writer) Downloaded() (complete bool, err error) { | |
|
||
switch w.toDownload { | ||
case toDownloadModel: | ||
implicitNeeded, err := w.policy.needsImplicitSnaps(w.availableSnaps) | ||
implicitNeeded, err := w.policy.needsImplicitSnaps(w.availableByMode) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
@@ -942,7 +966,7 @@ func (w *Writer) Downloaded() (complete bool, err error) { | |
return false, nil | ||
} | ||
case toDownloadExtra: | ||
implicitNeeded, err := w.policy.needsImplicitSnaps(w.availableSnaps) | ||
implicitNeeded, err := w.policy.needsImplicitSnaps(w.availableByMode) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.