distro: add new test for pipeline names on image types

Every image type defines a list of build pipeline names and a list of
payload pipeline names.  These should match the names of the pipelines
that will exist in the manifest when it's generated.  They should match
exactly, otherwise issues can occur when reading the metadata from an
osbuild result.  The cloud API needs to know the names of the pipelines
and specifically the name of the build pipeline and the payload pipeline
in order to differentiated between build and payload packages in the
metadata.

This new test generates every manifest, parses it into a minimal struct,
and compares the pipeline names with the ones reported statically on the
image type definition.
This commit is contained in:
Achilleas Koutsou 2023-01-17 20:42:37 +01:00 committed by Tomáš Hozza
parent 7f1a0a76b1
commit f102ae6b04

View file

@ -1,13 +1,16 @@
package distro_test
import (
"encoding/json"
"fmt"
"testing"
"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/distro_test_common"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -145,3 +148,96 @@ func TestImageType_PackageSetsChains(t *testing.T) {
}
}
}
// Ensure all image types report the correct names for their pipelines.
// Each image type contains a list of build and payload pipelines. They are
// needed for knowing the names of pipelines from the static object without
// having access to a manifest, which we need when parsing metadata from build
// results.
func TestImageTypePipelineNames(t *testing.T) {
// types for parsing the opaque manifest with just the fields we care about
type pipeline struct {
Name string `json:"name"`
}
type manifest struct {
Pipelines []pipeline `json:"pipelines"`
}
require := require.New(t)
distros := distroregistry.NewDefault()
for _, distroName := range distros.List() {
d := distros.GetDistro(distroName)
for _, archName := range d.ListArches() {
arch, err := d.GetArch(archName)
require.Nil(err)
for _, imageTypeName := range arch.ListImageTypes() {
t.Run(fmt.Sprintf("%s/%s/%s", distroName, archName, imageTypeName), func(t *testing.T) {
imageType, err := arch.GetImageType(imageTypeName)
require.Nil(err)
// set up bare minimum args for image type
customizations := &blueprint.Customizations{}
if imageType.Name() == "edge-simplified-installer" {
customizations = &blueprint.Customizations{
InstallationDevice: "/dev/null",
}
}
bp := blueprint.Blueprint{
Customizations: customizations,
}
options := distro.ImageOptions{}
repos := make([]rpmmd.RepoConfig, 0)
containers := make([]container.Spec, 0)
seed := int64(0)
// Add ostree options for image types that require them
options.OSTree = distro.OSTreeImageOptions{
ImageRef: imageType.OSTreeRef(),
URL: "https://example.com/repo",
FetchChecksum: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
}
// Pipelines that require package sets will fail if none
// are defined. OS pipelines require a kernel.
// Add kernel and filesystem to every pipeline so that the
// manifest creation doesn't fail.
allPipelines := append(imageType.BuildPipelines(), imageType.PayloadPipelines()...)
minimalPackageSet := []rpmmd.PackageSpec{
{Name: "kernel"},
{Name: "filesystem"},
}
packageSets := make(map[string][]rpmmd.PackageSpec, len(allPipelines))
for _, plName := range allPipelines {
packageSets[plName] = minimalPackageSet
}
if distroName == "rhel-7" {
// add one more under "packages" for rhel-7
// TODO: this will be removed with the RHEL 7 rewrite
packageSets["packages"] = minimalPackageSet
}
m, err := imageType.Manifest(bp.Customizations, options, repos, packageSets, containers, seed)
require.NoError(err)
pm := new(manifest)
err = json.Unmarshal(m, pm)
require.NoError(err)
require.Equal(len(allPipelines), len(pm.Pipelines))
for idx := range pm.Pipelines {
// manifest pipeline names should be identical to the ones
// defined in the image type and in the same order
require.Equal(allPipelines[idx], pm.Pipelines[idx].Name)
}
// The last pipeline should match the export pipeline.
// This might change in the future, but for now, let's make
// sure they match.
require.Equal(imageType.Exports()[0], pm.Pipelines[len(pm.Pipelines)-1].Name)
})
}
}
}
}