diff --git a/go.mod b/go.mod index f3f857f887..330784e74f 100644 --- a/go.mod +++ b/go.mod @@ -53,6 +53,7 @@ require ( golang.org/x/crypto v0.22.0 golang.org/x/oauth2 v0.20.0 golang.org/x/tools v0.20.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.28.5 @@ -332,7 +333,6 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.29.2 // indirect k8s.io/apiserver v0.29.2 // indirect k8s.io/component-base v0.29.2 // indirect diff --git a/tests/build/multi-platform.go b/tests/build/multi-platform.go index 39dd09bcf2..9bbf8f62d0 100644 --- a/tests/build/multi-platform.go +++ b/tests/build/multi-platform.go @@ -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" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" "golang.org/x/crypto/ssh" v1 "k8s.io/api/core/v1" @@ -33,6 +35,8 @@ import ( "github.com/IBM/go-sdk-core/v5/core" "github.com/IBM/vpc-go-sdk/vpcv1" + + "gopkg.in/yaml.v3" ) const ( @@ -62,6 +66,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)) @@ -74,6 +103,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()) @@ -107,7 +139,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createBuildPipelineSelector(f, testNamespace, "ARM64") Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "", "") + component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, testRepoUrl, "main") }) When("the Component with multi-platform-build is created", func() { @@ -179,6 +211,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)) + } + } + } + }) }) })