Skip to content

Commit

Permalink
test: ensure prefetched SRPMs are included in source image for multi-…
Browse files Browse the repository at this point in the history
…arch builds

STONEBLD-2454

Signed-off-by: Chenxiong Qi <[email protected]>
  • Loading branch information
tkdchen committed Jun 27, 2024
1 parent 3953105 commit b149c55
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require (
golang.org/x/oauth2 v0.20.0
golang.org/x/tools v0.20.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.4
k8s.io/apimachinery v0.29.4
k8s.io/cli-runtime v0.29.4
Expand Down Expand Up @@ -302,7 +303,6 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.3 // indirect
k8s.io/apiserver v0.29.4 // indirect
k8s.io/component-base v0.29.4 // indirect
Expand Down
74 changes: 73 additions & 1 deletion tests/build/multi-platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"

"github.com/konflux-ci/e2e-tests/pkg/clients/has"
"github.com/konflux-ci/e2e-tests/pkg/utils/build"
"golang.org/x/crypto/ssh"
v1 "k8s.io/api/core/v1"

Expand All @@ -30,6 +32,8 @@ import (

"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/vpc-go-sdk/vpcv1"

"gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -59,6 +63,31 @@ var (
interval = 10 * time.Second
)

type RPMLockFile struct {
LockFileVersion int `yaml:"lockfileVersion"`
LockFileVendor string `yaml:"lockfileVendor"`
Arches []struct {
Arch string `yaml:"arch"`
Packages []struct {
Url string `yaml:"url"`
Repoid string `yaml:"repoid"`
Size int `yaml:"size"`
Checksum string `yaml:"checksum"`
Name string `yaml:"name"`
EVR string `yaml:"evr"`
SourceRPM string `yaml:"sourcerpm"`
}
Source []struct {
Url string `yaml:"url"`
Repoid string `yaml:"repoid"`
Size int `yaml:"size"`
Checksum string `yaml:"checksum"`
Name string `yaml:"name"`
EVR string `yaml:"evr"`
}
}
}

var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E tests", Pending, Label("multi-platform"), func() {
var f *framework.Framework
AfterEach(framework.ReportFailure(&f))
Expand All @@ -71,6 +100,9 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E
var testNamespace, applicationName, componentName, multiPlatformSecretName, host, userDir string
var component *appservice.Component

// TODO: move this repo into redhat-appstudio-qe Github organization
const testRepoUrl = "https://github.com/cqi-stonesoup-test/multi-arch-builds"

AfterAll(func() {
// Cleanup aws secet and host-config
Expect(f.AsKubeAdmin.CommonController.DeleteSecret(ControllerNamespace, AwsSecretName)).To(Succeed())
Expand Down Expand Up @@ -101,7 +133,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E
err = createSecretForHostPool(f)
Expect(err).ShouldNot(HaveOccurred())

component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "ARM64", "", "")
component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "ARM64", testRepoUrl, "main")
})

When("the Component with multi-platform-build is created", func() {
Expand Down Expand Up @@ -173,6 +205,46 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E
return nil
}, timeout, interval).Should(Succeed(), "timed out when verifying that the remote host was cleaned up correctly")
})

It("prefetched SRPMs are included", func() {
pr, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "")
Expect(err).Should(Succeed())
client := f.AsKubeAdmin.CommonController.KubeRest()
sourceImageUrl, err := f.AsKubeAdmin.TektonController.GetTaskRunResult(client, pr, "build-source-image", "IMAGE_URL")
Expect(err).Should(Succeed())

imageDir, err := build.ExtractImage(sourceImageUrl)
Expect(err).Should(Succeed())
defer os.RemoveAll(imageDir)

entries, err := os.ReadDir(filepath.Join(imageDir, "rpm_dir"))
Expect(err).Should(Succeed())

srpmSet := make(map[string]int)
for _, entry := range entries {
srpmSet[entry.Name()] = 1
}

content, err := build.ReadFileFromGitRepo(testRepoUrl, "rpm.lock.file", "main")
Expect(err).Should(Succeed())

rpmLockFile := RPMLockFile{}
Expect(yaml.Unmarshal([]byte(content), &rpmLockFile)).Should(Succeed())

// Ideally, this check should be in the CheckSourceImage function. However, it is
// not easy for multi-platform builds tests here to set hermetic parameter for the
// triggered PipelineRun, which causes the prefetched sources check for hermetic.
// So, before figuring out a good solution, make this check separate here.

for _, arch := range rpmLockFile.Arches {
for _, sourceInfo := range arch.Source {
srpmFilename := filepath.Base(sourceInfo.Url)
if _, exists := srpmSet[srpmFilename]; !exists {
Fail(fmt.Sprintf("SRPM %s is not included for arch %s", srpmFilename, arch.Arch))
}
}
}
})
})
})

Expand Down

0 comments on commit b149c55

Please sign in to comment.