Blame SOURCES/0001-PR-1645-test-image-fix-pipeline-exports-for-v2-manifests.patch

1ebfb4
From 85cc7687415a96db017acaf763d53abbc47d993f Mon Sep 17 00:00:00 2001
1ebfb4
From: =?UTF-8?q?Ond=C5=99ej=20Budai?= <ondrej@budai.cz>
1ebfb4
Date: Mon, 16 Aug 2021 12:56:55 +0200
1ebfb4
Subject: [PATCH] test/image: fix pipeline exports for v2 manifests
1ebfb4
MIME-Version: 1.0
1ebfb4
Content-Type: text/plain; charset=UTF-8
1ebfb4
Content-Transfer-Encoding: 8bit
1ebfb4
1ebfb4
Previously, we just assumed that all test manifests are of version 1, or we
1ebfb4
should export the pipeline named assembler. However, this is no longer true
1ebfb4
in RHEL 8.5 and 9 - they are only manifest v2 and they don't have a pipeline
1ebfb4
named assembler.
1ebfb4
1ebfb4
This commit introduces a new way to guess the export name - if the manifest
1ebfb4
is of version 1, we just export the assembler. In the case v2 manifest, the
1ebfb4
last pipeline is exported.
1ebfb4
1ebfb4
Signed-off-by: Ondřej Budai <ondrej@budai.cz>
1ebfb4
---
1ebfb4
 cmd/osbuild-image-tests/main_test.go | 32 +++++++++++++++++++++++++---
1ebfb4
 1 file changed, 29 insertions(+), 3 deletions(-)
1ebfb4
1ebfb4
diff --git a/cmd/osbuild-image-tests/main_test.go b/cmd/osbuild-image-tests/main_test.go
1ebfb4
index f6cbccc9..f73bab3d 100644
1ebfb4
--- a/cmd/osbuild-image-tests/main_test.go
1ebfb4
+++ b/cmd/osbuild-image-tests/main_test.go
1ebfb4
@@ -482,6 +482,34 @@ func testImage(t *testing.T, testcase testcaseStruct, imagePath string) {
1ebfb4
 	}
1ebfb4
 }
1ebfb4
 
1ebfb4
+// guessPipelineToExport return a best-effort guess about which
1ebfb4
+// pipeline should be exported when running osbuild for the testcase
1ebfb4
+//
1ebfb4
+// If this function detects that this is a version 1 manifest, it
1ebfb4
+// always returns "assembler"
1ebfb4
+//
1ebfb4
+// For manifests version 2, the name of the last pipeline is returned.
1ebfb4
+func guessPipelineToExport(rawManifest json.RawMessage) string {
1ebfb4
+	const v1ManifestExportName = "assembler"
1ebfb4
+	var v2Manifest struct {
1ebfb4
+		Version   string `json:"version"`
1ebfb4
+		Pipelines []struct {
1ebfb4
+			Name string `json:"name,omitempty"`
1ebfb4
+		} `json:"pipelines"`
1ebfb4
+	}
1ebfb4
+	err := json.Unmarshal(rawManifest, &v2Manifest)
1ebfb4
+	if err != nil {
1ebfb4
+		// if we cannot unmarshal, let's just assume that it's a version 1 manifest
1ebfb4
+		return v1ManifestExportName
1ebfb4
+	}
1ebfb4
+
1ebfb4
+	if v2Manifest.Version == "2" {
1ebfb4
+		return v2Manifest.Pipelines[len(v2Manifest.Pipelines)-1].Name
1ebfb4
+	}
1ebfb4
+
1ebfb4
+	return v1ManifestExportName
1ebfb4
+}
1ebfb4
+
1ebfb4
 // runTestcase builds the pipeline specified in the testcase and then it
1ebfb4
 // tests the result
1ebfb4
 func runTestcase(t *testing.T, testcase testcaseStruct, store string) {
1ebfb4
@@ -494,9 +522,7 @@ func runTestcase(t *testing.T, testcase testcaseStruct, store string) {
1ebfb4
 		require.NoError(t, err, "error removing temporary output directory")
1ebfb4
 	}()
1ebfb4
 
1ebfb4
-	// NOTE(akoutsou) 1to2t: new v2 manifests name their last pipeline
1ebfb4
-	// "assembler" for compatibility with v1
1ebfb4
-	exports := []string{"assembler"}
1ebfb4
+	exports := []string{guessPipelineToExport(testcase.Manifest)}
1ebfb4
 	err = runOsbuild(testcase.Manifest, store, outputDirectory, exports)
1ebfb4
 	require.NoError(t, err)
1ebfb4
 
1ebfb4
-- 
1ebfb4
2.31.1
1ebfb4