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
import (
"crypto/sha256"
"errors"
"fmt"
"sort"
"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/distroregistry"
"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/rpmmd"
)
@ -235,7 +238,7 @@ func (t *TestImageType) Manifest(b *blueprint.Blueprint, options distro.ImageOpt
bpPkgs = b.GetPackages()
}
var ostreeSources map[string][]ostree.SourceSpec
var ostreeSources []ostree.SourceSpec
if defaultRef := t.OSTreeRef(); defaultRef != "" {
// ostree image type
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.RHSM = options.OSTree.RHSM
}
ostreeSources = map[string][]ostree.SourceSpec{
osPkgsKey: {ostreeSource},
}
ostreeSources = []ostree.SourceSpec{ostreeSource}
}
ret := manifest.Manifest{
Content: manifest.Content{
OSTreeCommits: ostreeSources,
PackageSets: map[string][]rpmmd.PackageSet{
buildPkgsKey: {{
Include: []string{
"dep-package1",
"dep-package2",
"dep-package3",
},
Repositories: repos,
}},
blueprintPkgsKey: {{
Include: bpPkgs,
Repositories: repos,
}},
osPkgsKey: {{
Include: []string{
"dep-package1",
"dep-package2",
"dep-package3",
},
Repositories: repos,
}},
buildPackages := []rpmmd.PackageSet{{
Include: []string{
"dep-package1",
"dep-package2",
"dep-package3",
},
Repositories: repos,
}}
osPackages := []rpmmd.PackageSet{
{
Include: bpPkgs,
Repositories: repos,
},
{
Include: []string{
"dep-package1",
"dep-package2",
"dep-package3",
},
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
@ -385,3 +391,42 @@ func NewRegistry() *distroregistry.Registry {
func New2() *TestDistro {
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
}