Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

periodic: account for differences with Konflux built images #1445

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions test/periodic/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
37 changes: 26 additions & 11 deletions test/rpmtest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Comment on lines +53 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible for both to be populated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, older manifests will have SourceNEVRA populated, newer ones won't but they have the same information in SourceName.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, ok

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)
Expand All @@ -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
Expand Down
Loading