distro/ImageType: let PackageSets depend on ImageOptions
The package sets for an image can depend on the blueprint, and by the same logic there is no reason it should not be able to depend on the image options. This is so far a non-functional change, but makes a follow-up commit simpler (though still without actually depending on the image options to compute the package sets).
This commit is contained in:
parent
1cb2f0276d
commit
be5ea6a9b8
23 changed files with 141 additions and 72 deletions
|
|
@ -99,7 +99,7 @@ type ImageType interface {
|
|||
// Returns the sets of packages to include and exclude when building the image.
|
||||
// Indexed by a string label. How each set is labeled and used depends on the
|
||||
// image type.
|
||||
PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet
|
||||
PackageSets(bp blueprint.Blueprint, options ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet
|
||||
|
||||
// Returns the names of the pipelines that set up the build environment (buildroot).
|
||||
BuildPipelines() []string
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/distro_test_common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -116,7 +117,13 @@ func TestImageType_PackageSetsChains(t *testing.T) {
|
|||
imageType, err := arch.GetImageType(imageTypeName)
|
||||
require.Nil(t, err)
|
||||
|
||||
imagePkgSets := imageType.PackageSets(blueprint.Blueprint{}, nil)
|
||||
imagePkgSets := imageType.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
|
||||
OSTree: ostree.RequestParams{
|
||||
URL: "foo",
|
||||
Ref: "bar",
|
||||
Parent: "baz",
|
||||
},
|
||||
}, nil)
|
||||
for packageSetName := range imageType.PackageSetsChains() {
|
||||
_, ok := imagePkgSets[packageSetName]
|
||||
assert.Truef(t, ok, "package set %q defined in a package set chain is not present in the image package sets", packageSetName)
|
||||
|
|
|
|||
|
|
@ -96,6 +96,13 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis
|
|||
imgPackageSpecSets = getImageTypePkgSpecSets(
|
||||
imageType,
|
||||
*tt.ComposeRequest.Blueprint,
|
||||
distro.ImageOptions{
|
||||
OSTree: ostree.RequestParams{
|
||||
URL: "foo",
|
||||
Ref: "bar",
|
||||
Parent: "baz",
|
||||
},
|
||||
},
|
||||
repos,
|
||||
dnfCacheDir,
|
||||
dnfJsonPath,
|
||||
|
|
@ -138,8 +145,8 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis
|
|||
}
|
||||
}
|
||||
|
||||
func getImageTypePkgSpecSets(imageType distro.ImageType, bp blueprint.Blueprint, repos []rpmmd.RepoConfig, cacheDir, dnfJsonPath string) map[string][]rpmmd.PackageSpec {
|
||||
imgPackageSets := imageType.PackageSets(bp, repos)
|
||||
func getImageTypePkgSpecSets(imageType distro.ImageType, bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig, cacheDir, dnfJsonPath string) map[string][]rpmmd.PackageSpec {
|
||||
imgPackageSets := imageType.PackageSets(bp, options, repos)
|
||||
|
||||
solver := dnfjson.NewSolver(imageType.Arch().Distro().ModulePlatformID(), imageType.Arch().Distro().Releasever(), imageType.Arch().Name(), cacheDir)
|
||||
depsolvedSets := make(map[string][]rpmmd.PackageSpec)
|
||||
|
|
@ -155,7 +162,13 @@ func getImageTypePkgSpecSets(imageType distro.ImageType, bp blueprint.Blueprint,
|
|||
}
|
||||
|
||||
func isOSTree(imgType distro.ImageType) bool {
|
||||
packageSets := imgType.PackageSets(blueprint.Blueprint{}, nil)
|
||||
packageSets := imgType.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
|
||||
OSTree: ostree.RequestParams{
|
||||
URL: "foo",
|
||||
Ref: "bar",
|
||||
Parent: "baz",
|
||||
},
|
||||
}, nil)
|
||||
for _, set := range packageSets["build-packages"] {
|
||||
for _, pkg := range set.Include {
|
||||
if pkg == "rpm-ostree" {
|
||||
|
|
@ -170,7 +183,13 @@ var knownKernels = []string{"kernel", "kernel-debug", "kernel-rt"}
|
|||
|
||||
// Returns the number of known kernels in the package list
|
||||
func kernelCount(imgType distro.ImageType) int {
|
||||
sets := imgType.PackageSets(blueprint.Blueprint{}, nil)
|
||||
sets := imgType.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
|
||||
OSTree: ostree.RequestParams{
|
||||
URL: "foo",
|
||||
Ref: "bar",
|
||||
Parent: "baz",
|
||||
},
|
||||
}, nil)
|
||||
n := 0
|
||||
for _, pset := range sets["packages"] {
|
||||
for _, pkg := range pset.Include {
|
||||
|
|
@ -182,6 +201,7 @@ func kernelCount(imgType distro.ImageType) int {
|
|||
|
||||
}
|
||||
}
|
||||
// TODO: is this not included in the above?
|
||||
for _, bset := range sets["blueprint"] {
|
||||
for _, pkg := range bset.Include {
|
||||
for _, kernel := range knownKernels {
|
||||
|
|
@ -192,16 +212,23 @@ func kernelCount(imgType distro.ImageType) int {
|
|||
|
||||
}
|
||||
}
|
||||
m := 0
|
||||
for _, iset := range sets["installer"] {
|
||||
for _, pkg := range iset.Include {
|
||||
for _, kernel := range knownKernels {
|
||||
if kernel == pkg {
|
||||
n++
|
||||
m++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// TODO: fix this! some installers mistakenly include other
|
||||
// package sets. These are however not used in building the image
|
||||
// until this is fixed, count the installers separately.
|
||||
if m > 0 {
|
||||
return m
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
|
|
@ -260,8 +287,20 @@ func GetTestingPackageSpecSets(packageName, arch string, pkgSetNames []string) m
|
|||
// defined by the provided ImageType, which is useful for unit testing.
|
||||
func GetTestingImagePackageSpecSets(packageName string, i distro.ImageType) map[string][]rpmmd.PackageSpec {
|
||||
arch := i.Arch().Name()
|
||||
imagePackageSets := make([]string, 0, len(i.PackageSets(blueprint.Blueprint{}, nil)))
|
||||
for pkgSetName := range i.PackageSets(blueprint.Blueprint{}, nil) {
|
||||
imagePackageSets := make([]string, 0, len(i.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
|
||||
OSTree: ostree.RequestParams{
|
||||
URL: "foo",
|
||||
Ref: "bar",
|
||||
Parent: "baz",
|
||||
},
|
||||
}, nil)))
|
||||
for pkgSetName := range i.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{
|
||||
OSTree: ostree.RequestParams{
|
||||
URL: "foo",
|
||||
Ref: "bar",
|
||||
Parent: "baz",
|
||||
},
|
||||
}, nil) {
|
||||
imagePackageSets = append(imagePackageSets, pkgSetName)
|
||||
}
|
||||
return GetTestingPackageSpecSets(packageName, arch, imagePackageSets)
|
||||
|
|
|
|||
|
|
@ -567,7 +567,7 @@ func (t *imageType) getPackages(name string) rpmmd.PackageSet {
|
|||
return getter(t)
|
||||
}
|
||||
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
// merge package sets that appear in the image type with the package sets
|
||||
// of the same name from the distro and arch
|
||||
mergedSets := make(map[string]rpmmd.PackageSet)
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ func TestImageType_BuildPackages(t *testing.T) {
|
|||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, nil)["build"]
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{}, nil)["build"]
|
||||
assert.NotNil(t, buildPkgs)
|
||||
assert.Len(t, buildPkgs, 1)
|
||||
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs[0].Include)
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ func (t *imageType) getPackages(name string) rpmmd.PackageSet {
|
|||
return getter(t)
|
||||
}
|
||||
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
// merge package sets that appear in the image type with the package sets
|
||||
// of the same name from the distro and arch
|
||||
mergedSets := make(map[string]rpmmd.PackageSet)
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ func TestImageType_BuildPackages(t *testing.T) {
|
|||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, nil)["build"]
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{}, nil)["build"]
|
||||
assert.NotNil(t, buildPkgs)
|
||||
assert.Len(t, buildPkgs, 1)
|
||||
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs[0].Include)
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ func (t *imageType) getPackages(name string) rpmmd.PackageSet {
|
|||
return getter(t)
|
||||
}
|
||||
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
// merge package sets that appear in the image type with the package sets
|
||||
// of the same name from the distro and arch
|
||||
mergedSets := make(map[string]rpmmd.PackageSet)
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ func TestImageType_BuildPackages(t *testing.T) {
|
|||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, nil)["build"]
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{}, nil)["build"]
|
||||
assert.NotNil(t, buildPkgs)
|
||||
assert.Len(t, buildPkgs, 1)
|
||||
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs[0].Include)
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ func (t *imageType) BuildPackages() []string {
|
|||
return packages
|
||||
}
|
||||
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
includePackages, excludePackages := t.Packages(bp)
|
||||
return map[string][]rpmmd.PackageSet{
|
||||
"packages": {{
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ func TestImageType_BuildPackages(t *testing.T) {
|
|||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, nil)["build-packages"]
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{}, nil)["build-packages"]
|
||||
assert.NotNil(t, buildPkgs)
|
||||
assert.Len(t, buildPkgs, 1)
|
||||
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs[0].Include)
|
||||
|
|
@ -408,7 +408,7 @@ func TestImageType_BasePackages(t *testing.T) {
|
|||
for _, pkgMap := range pkgMaps {
|
||||
imgType, err := arch.GetImageType(pkgMap.name)
|
||||
assert.NoError(t, err)
|
||||
packages := imgType.PackageSets(blueprint.Blueprint{}, nil)["packages"]
|
||||
packages := imgType.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{}, nil)["packages"]
|
||||
assert.NotNil(t, packages)
|
||||
assert.Len(t, packages, 1)
|
||||
expectedPackages := append(pkgMap.basePackages, pkgMap.bootloaderPackages...)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func (t *imageTypeS2) BuildPackages() []string {
|
|||
return buildPackages
|
||||
}
|
||||
|
||||
func (t *imageTypeS2) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *imageTypeS2) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
sets := map[string][]rpmmd.PackageSet{
|
||||
"build-packages": {{
|
||||
Include: t.BuildPackages(),
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ func (t *imageType) getPackages(name string) rpmmd.PackageSet {
|
|||
return getter(t)
|
||||
}
|
||||
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
// merge package sets that appear in the image type with the package sets
|
||||
// of the same name from the distro and arch
|
||||
mergedSets := make(map[string]rpmmd.PackageSet)
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ func TestImageType_BuildPackages(t *testing.T) {
|
|||
if assert.NoErrorf(t, err, "d.GetArch(%v) returned err = %v; expected nil", archLabel, err) {
|
||||
continue
|
||||
}
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, nil)["build"]
|
||||
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{}, distro.ImageOptions{}, nil)["build"]
|
||||
assert.NotNil(t, buildPkgs)
|
||||
assert.Len(t, buildPkgs, 1)
|
||||
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs[0].Include)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ func (t *TestImageType) PartitionType() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (t *TestImageType) PackageSets(bp blueprint.Blueprint, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
func (t *TestImageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet {
|
||||
return map[string][]rpmmd.PackageSet{
|
||||
buildPkgsKey: {{
|
||||
Include: []string{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue