distro/test: use the new ContentTest pipeline

Use the new ContentTest pipeline to define a manifest instead of
assigning content to the manifest directly.
This commit is contained in:
Achilleas Koutsou 2023-06-02 17:22:09 +02:00 committed by Ondřej Budai
parent 8638fe19d8
commit aa4fa91214

View file

@ -1,14 +1,17 @@
package test_distro package test_distro
import ( import (
"crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"sort" "sort"
"github.com/osbuild/osbuild-composer/internal/blueprint" "github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/osbuild/osbuild-composer/internal/container"
"github.com/osbuild/osbuild-composer/internal/distro" "github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distroregistry" "github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/manifest" "github.com/osbuild/osbuild-composer/internal/manifest"
dnfjson_mock "github.com/osbuild/osbuild-composer/internal/mocks/dnfjson"
"github.com/osbuild/osbuild-composer/internal/ostree" "github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/osbuild/osbuild-composer/internal/rpmmd"
) )
@ -235,7 +238,7 @@ func (t *TestImageType) Manifest(b *blueprint.Blueprint, options distro.ImageOpt
bpPkgs = b.GetPackages() bpPkgs = b.GetPackages()
} }
var ostreeSources map[string][]ostree.SourceSpec var ostreeSources []ostree.SourceSpec
if defaultRef := t.OSTreeRef(); defaultRef != "" { if defaultRef := t.OSTreeRef(); defaultRef != "" {
// ostree image type // ostree image type
ostreeSource := ostree.SourceSpec{ // init with default ostreeSource := ostree.SourceSpec{ // init with default
@ -250,39 +253,42 @@ func (t *TestImageType) Manifest(b *blueprint.Blueprint, options distro.ImageOpt
ostreeSource.Parent = options.OSTree.ParentRef ostreeSource.Parent = options.OSTree.ParentRef
ostreeSource.RHSM = options.OSTree.RHSM ostreeSource.RHSM = options.OSTree.RHSM
} }
ostreeSources = map[string][]ostree.SourceSpec{ ostreeSources = []ostree.SourceSpec{ostreeSource}
osPkgsKey: {ostreeSource},
}
} }
ret := manifest.Manifest{ buildPackages := []rpmmd.PackageSet{{
Content: manifest.Content{ Include: []string{
OSTreeCommits: ostreeSources, "dep-package1",
PackageSets: map[string][]rpmmd.PackageSet{ "dep-package2",
buildPkgsKey: {{ "dep-package3",
Include: []string{ },
"dep-package1", Repositories: repos,
"dep-package2", }}
"dep-package3", osPackages := []rpmmd.PackageSet{
}, {
Repositories: repos, Include: bpPkgs,
}}, Repositories: repos,
blueprintPkgsKey: {{ },
Include: bpPkgs, {
Repositories: repos, Include: []string{
}}, "dep-package1",
osPkgsKey: {{ "dep-package2",
Include: []string{ "dep-package3",
"dep-package1",
"dep-package2",
"dep-package3",
},
Repositories: repos,
}},
}, },
Repositories: repos,
}, },
} }
return &ret, nil, nil
m := &manifest.Manifest{}
manifest.NewContentTest(m, buildPkgsKey, buildPackages, nil, nil)
manifest.NewContentTest(m, osPkgsKey, osPackages, nil, ostreeSources)
m.Content.PackageSets = m.GetPackageSetChains()
m.Content.Containers = m.GetContainerSourceSpecs()
m.Content.OSTreeCommits = m.GetOSTreeSourceSpecs()
return m, nil, nil
} }
// newTestDistro returns a new instance of TestDistro with the // newTestDistro returns a new instance of TestDistro with the
@ -385,3 +391,42 @@ func NewRegistry() *distroregistry.Registry {
func New2() *TestDistro { func New2() *TestDistro {
return newTestDistro(TestDistro2Name, TestDistro2ModulePlatformID, TestDistro2Releasever) return newTestDistro(TestDistro2Name, TestDistro2ModulePlatformID, TestDistro2Releasever)
} }
// ResolveContent transforms content source specs into resolved specs for serialization.
// For packages, it uses the dnfjson_mock.BaseDeps() every time, but retains
// the map keys from the input.
// For ostree commits it hashes the URL+Ref to create a checksum.
func ResolveContent(pkgs map[string][]rpmmd.PackageSet, containers map[string][]container.SourceSpec, commits map[string][]ostree.SourceSpec) (map[string][]rpmmd.PackageSpec, map[string][]container.Spec, map[string][]ostree.CommitSpec) {
pkgSpecs := make(map[string][]rpmmd.PackageSpec, len(pkgs))
for name := range pkgs {
pkgSpecs[name] = dnfjson_mock.BaseDeps()
}
containerSpecs := make(map[string][]container.Spec, len(containers))
for name := range containers {
containerSpecs[name] = make([]container.Spec, len(containers[name]))
for idx := range containers[name] {
containerSpecs[name][idx] = container.Spec{
Source: containers[name][idx].Source,
TLSVerify: containers[name][idx].TLSVerify,
LocalName: containers[name][idx].Name,
}
}
}
commitSpecs := make(map[string][]ostree.CommitSpec, len(commits))
for name := range commits {
commitSpecs[name] = make([]ostree.CommitSpec, len(commits[name]))
for idx := range commits[name] {
commitSpecs[name][idx] = ostree.CommitSpec{
Ref: commits[name][idx].Ref,
URL: commits[name][idx].URL,
Checksum: fmt.Sprintf("%x", sha256.Sum256([]byte(commits[name][idx].URL+commits[name][idx].Ref))),
}
fmt.Printf("Test distro spec: %+v\n", commitSpecs[name][idx])
}
}
return pkgSpecs, containerSpecs, commitSpecs
}