From ae50b5890f0a8f00b3db96676b8b7db44fe78212 Mon Sep 17 00:00:00 2001 From: crozzy Date: Fri, 22 Nov 2024 07:42:10 -0800 Subject: [PATCH] periodic: account for differences with Konflux built images For the RPM test we check the index report against the pyxis manifest for that image. The format of this manifest has recently changed when they started producing builds from Konflux, this change accounts for those changes. Signed-off-by: crozzy --- test/periodic/rpm_test.go | 18 +++++++++++++----- test/rpmtest/manifest.go | 37 ++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/test/periodic/rpm_test.go b/test/periodic/rpm_test.go index 42f4fd1c6..755573d57 100644 --- a/test/periodic/rpm_test.go +++ b/test/periodic/rpm_test.go @@ -221,7 +221,7 @@ func (doc hydraDoc) Run(dir string) func(*testing.T) { defer logResponse(t, res.Request.URL.Path, buf)() s := &rpm.Scanner{} - var got []*claircore.Package + pkgMap := map[string]*claircore.Package{} var which claircore.Digest for _, ld := range image.Data[0].Parsed.Layers { // TODO(hank) Need a way to use the nicer API, but pass the @@ -242,15 +242,23 @@ func (doc hydraDoc) Run(dir string) func(*testing.T) { if err != nil { t.Error(err) } - if len(pkgs) >= len(want) { - got = pkgs - which = ld - break + for _, p := range pkgs { + pkgMap[p.Name] = p } } + // Newer images contain multiple layers with RPM DBs. We need to account for + // all packages but deduplicate across layers. + got := make([]*claircore.Package, 0, len(pkgMap)) + for _, p := range pkgMap { + got = append(got, p) + } + t.Logf("found %d packages in %v", len(got), which) t.Logf("comparing to %d packages in manifest %s", len(want), doc.ID) + if len(want) != len(got) { + t.Errorf("wanted %d packages but got %d", len(want), len(got)) + } if !cmp.Equal(got, want, rpmtest.Options) { t.Error(cmp.Diff(got, want, rpmtest.Options)) } diff --git a/test/rpmtest/manifest.go b/test/rpmtest/manifest.go index 087636dd6..742b176cd 100644 --- a/test/rpmtest/manifest.go +++ b/test/rpmtest/manifest.go @@ -17,13 +17,14 @@ type Manifest struct { RPM []ManifestRPM `json:"rpms"` } type ManifestRPM struct { - Name string `json:"name"` - Version string `json:"version"` - Release string `json:"release"` - Arch string `json:"architecture"` - Source string `json:"srpm_nevra"` - GPG string `json:"gpg"` - Module string `json:"module"` + Name string `json:"name"` + Version string `json:"version"` + Release string `json:"release"` + Arch string `json:"architecture"` + SourceNEVRA string `json:"srpm_nevra"` + SourceName string `json:"srpm_name"` + GPG string `json:"gpg"` + Module string `json:"module"` } func PackagesFromRPMManifest(t *testing.T, r io.Reader) []*claircore.Package { @@ -44,15 +45,28 @@ func PackagesFromRPMManifest(t *testing.T, r io.Reader) []*claircore.Package { RepositoryHint: "key:" + rpm.GPG, Module: rpm.Module, } - if s, ok := src[rpm.Source]; ok { + + // Newer images produced from Konflux shove all the source information + // into the SourceName and omit the SourceNEVRA. Try both. + var source string + switch { + case rpm.SourceNEVRA != "": + source = rpm.SourceNEVRA + case rpm.SourceName != "": + source = rpm.SourceName + default: + continue + } + + if s, ok := src[source]; ok { p.Source = s } else { - s := strings.TrimSuffix(rpm.Source, ".src") + s := strings.TrimSuffix(strings.TrimSuffix(source, ".rpm"), ".src") pos := len(s) for i := 0; i < 2; i++ { pos = strings.LastIndexByte(s[:pos], '-') if pos == -1 { - t.Fatalf("malformed NEVRA: %q", rpm.Source) + t.Fatalf("malformed NEVRA/NVRA: %q for %q", source, rpm.Name) } } idx := len(srcs) @@ -62,9 +76,10 @@ func PackagesFromRPMManifest(t *testing.T, r io.Reader) []*claircore.Package { Version: strings.TrimPrefix(s[pos+1:], "0:"), Module: rpm.Module, }) - src[rpm.Source] = &srcs[idx] + src[source] = &srcs[idx] p.Source = &srcs[idx] } + out = append(out, &p) } return out