From 4ac6a7a11d7e7f7545013453c02c88e96d02a39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Fri, 4 Aug 2023 17:32:07 +0200 Subject: [PATCH] Koji: expose boot mode in image extra metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also extend the Koji test case to verify that the boot mode information is in the build extra metadata and that it contains valid value. Signed-off-by: Tomáš Hozza --- cmd/osbuild-koji-tests/main_test.go | 4 +++- cmd/osbuild-koji/main.go | 4 +++- cmd/osbuild-worker/jobimpl-koji-finalize.go | 3 ++- internal/upload/koji/koji.go | 8 ++++++-- test/cases/koji.sh | 13 +++++++++++++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/osbuild-koji-tests/main_test.go b/cmd/osbuild-koji-tests/main_test.go index ed7120b0a..0045037ad 100644 --- a/cmd/osbuild-koji-tests/main_test.go +++ b/cmd/osbuild-koji-tests/main_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/osbuild/images/pkg/distro" "github.com/osbuild/images/pkg/rpmmd" "github.com/osbuild/osbuild-composer/internal/upload/koji" ) @@ -180,7 +181,8 @@ func TestKojiImport(t *testing.T) { RPMs: []rpmmd.RPM{}, Extra: koji.BuildOutputExtra{ Image: koji.ImageExtraInfo{ - Arch: "noarch", + Arch: "noarch", + BootMode: distro.BOOT_LEGACY.String(), }, }, }, diff --git a/cmd/osbuild-koji/main.go b/cmd/osbuild-koji/main.go index d84ecfb9e..a2f807f49 100644 --- a/cmd/osbuild-koji/main.go +++ b/cmd/osbuild-koji/main.go @@ -8,6 +8,7 @@ import ( "time" "github.com/google/uuid" + "github.com/osbuild/images/pkg/distro" "github.com/osbuild/images/pkg/rpmmd" "github.com/osbuild/osbuild-composer/internal/upload/koji" "github.com/sirupsen/logrus" @@ -99,7 +100,8 @@ func main() { RPMs: []rpmmd.RPM{}, Extra: koji.BuildOutputExtra{ Image: koji.ImageExtraInfo{ - Arch: arch, + Arch: arch, + BootMode: distro.BOOT_NONE.String(), // TODO: put the correct boot mode here }, }, }, diff --git a/cmd/osbuild-worker/jobimpl-koji-finalize.go b/cmd/osbuild-worker/jobimpl-koji-finalize.go index a2b503faf..61ea97a52 100644 --- a/cmd/osbuild-worker/jobimpl-koji-finalize.go +++ b/cmd/osbuild-worker/jobimpl-koji-finalize.go @@ -184,7 +184,8 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error { imageRPMs = rpmmd.DeduplicateRPMs(imageRPMs) imgOutputExtraInfo := koji.ImageExtraInfo{ - Arch: buildArgs.Arch, + Arch: buildArgs.Arch, + BootMode: buildArgs.ImageBootMode, } imgOutputsExtraInfo[args.KojiFilenames[i]] = imgOutputExtraInfo diff --git a/internal/upload/koji/koji.go b/internal/upload/koji/koji.go index d4a0b6e3a..b417cb8a4 100644 --- a/internal/upload/koji/koji.go +++ b/internal/upload/koji/koji.go @@ -110,8 +110,12 @@ type BuildRoot struct { // ImageExtraInfo holds extra metadata about the image. // This structure is shared for the Extra metadata of the output and the build. type ImageExtraInfo struct { - // TODO: Ideally this is where the pipeline would be passed. - Arch string `json:"arch"` // TODO: why? + // Koji docs say: "should contain IDs that allow tracking the output back to the system in which it was generated" + // TODO: we should probably add some ID here, probably the OSBuildJob UUID? + + Arch string `json:"arch"` + // Boot mode of the image + BootMode string `json:"boot_mode,omitempty"` } // BuildOutputExtra holds extra metadata associated with the build output. diff --git a/test/cases/koji.sh b/test/cases/koji.sh index c16b89eb7..2aac8db46 100755 --- a/test/cases/koji.sh +++ b/test/cases/koji.sh @@ -163,6 +163,19 @@ function verify_buildinfo() { echo "Unexpected arch for '${image}'. Expected '${ARCH}', but got '${image_arch}'" exit 1 fi + + local image_boot_mode + image_boot_mode="$(echo "${image_metadata}" | jq -r '.boot_mode')" + # for now, check just that the boot mode is a valid value + case "${image_boot_mode}" in + "uefi"|"legacy"|"hybrid") + ;; + "none"|*) + # for now, we don't upload any images that have 'none' as boot mode, although it is a valid value + echo "Unexpected boot mode for '${image}'. Expected 'uefi', 'legacy' or 'hybrid', but got '${image_boot_mode}'" + exit 1 + ;; + esac done }