From 65bc635c30fbcdacc5d9e2b4a79b8db43d65aeca Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Tue, 2 Jun 2020 08:49:28 +0200 Subject: [PATCH] osbuild: change legacy type from bool to string This work is based on previous PRs, namely: https://github.com/osbuild/osbuild-composer/pull/501 and https://github.com/osbuild/osbuild/pull/327 The problem here is that we used to treat legacy as a boolean before we started introducing support for alternative architectures, but now we need to specify exact strings for the grub2 stage, for example for ppc64le the legacy parameter looks like this: ``` "legacy": "powerpc-ieee1275" ``` This patch will allow us to introduce support for ppc64le and fix associated issues: https://github.com/osbuild/osbuild-composer/issues/693 --- internal/distro/fedora31/distro.go | 9 ++++++++- internal/distro/fedora32/distro.go | 9 ++++++++- internal/distro/rhel8/distro.go | 9 ++++++++- internal/osbuild/grub2_stage.go | 2 +- internal/osbuild/stage_test.go | 6 +++--- test/cases/fedora_31-aarch64-ami-boot.json | 1 - test/cases/fedora_31-aarch64-openstack-boot.json | 1 - test/cases/fedora_31-aarch64-qcow2-boot.json | 1 - test/cases/fedora_31-x86_64-ami-boot.json | 4 ++-- test/cases/fedora_31-x86_64-openstack-boot.json | 4 ++-- test/cases/fedora_31-x86_64-qcow2-boot.json | 4 ++-- test/cases/fedora_31-x86_64-vhd-boot.json | 4 ++-- test/cases/fedora_31-x86_64-vmdk-boot.json | 4 ++-- test/cases/fedora_32-x86_64-ami-boot.json | 4 ++-- test/cases/fedora_32-x86_64-openstack-boot.json | 4 ++-- test/cases/fedora_32-x86_64-qcow2-boot.json | 4 ++-- test/cases/fedora_32-x86_64-vhd-boot.json | 4 ++-- test/cases/fedora_32-x86_64-vmdk-boot.json | 4 ++-- test/cases/rhel_8-x86_64-ami-boot.json | 4 ++-- test/cases/rhel_8-x86_64-openstack-boot.json | 4 ++-- test/cases/rhel_8-x86_64-qcow2-boot.json | 4 ++-- test/cases/rhel_8-x86_64-vhd-boot.json | 4 ++-- test/cases/rhel_8-x86_64-vmdk-boot.json | 4 ++-- 23 files changed, 58 insertions(+), 40 deletions(-) diff --git a/internal/distro/fedora31/distro.go b/internal/distro/fedora31/distro.go index d2af8e89b..f2e213cb7 100644 --- a/internal/distro/fedora31/distro.go +++ b/internal/distro/fedora31/distro.go @@ -44,6 +44,7 @@ type arch struct { name string bootloaderPackages []string buildPackages []string + legacy string uefi bool imageTypes map[string]imageType } @@ -356,6 +357,7 @@ func New() *Fedora31 { buildPackages: []string{ "grub2-pc", }, + legacy: "i386-pc", } x8664.setImageTypes( amiImgType, @@ -611,10 +613,15 @@ func (r *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.Ke } } + var legacy string + if !uefi { + legacy = r.arch.legacy + } + return &osbuild.GRUB2StageOptions{ RootFilesystemUUID: id, KernelOptions: kernelOptions, - Legacy: !uefi, + Legacy: legacy, UEFI: uefiOptions, } } diff --git a/internal/distro/fedora32/distro.go b/internal/distro/fedora32/distro.go index 692401f74..8921da0d7 100644 --- a/internal/distro/fedora32/distro.go +++ b/internal/distro/fedora32/distro.go @@ -31,6 +31,7 @@ type architecture struct { name string bootloaderPackages []string buildPackages []string + legacy string uefi bool imageTypes map[string]imageType } @@ -458,10 +459,15 @@ func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.Ke } } + var legacy string + if !uefi { + legacy = t.arch.legacy + } + return &osbuild.GRUB2StageOptions{ RootFilesystemUUID: id, KernelOptions: kernelOptions, - Legacy: !uefi, + Legacy: legacy, UEFI: uefiOptions, } } @@ -777,6 +783,7 @@ func New() distro.Distro { buildPackages: []string{ "grub2-pc", }, + legacy: "i386-pc", } x8664.setImageTypes( iotImgType, diff --git a/internal/distro/rhel8/distro.go b/internal/distro/rhel8/distro.go index 344914de4..1a4cdef78 100644 --- a/internal/distro/rhel8/distro.go +++ b/internal/distro/rhel8/distro.go @@ -30,6 +30,7 @@ type architecture struct { name string bootloaderPackages []string buildPackages []string + legacy string uefi bool imageTypes map[string]imageType } @@ -465,10 +466,15 @@ func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.Ke } } + var legacy string + if !uefi { + legacy = t.arch.legacy + } + return &osbuild.GRUB2StageOptions{ RootFilesystemUUID: id, KernelOptions: kernelOptions, - Legacy: !uefi, + Legacy: legacy, UEFI: uefiOptions, } } @@ -820,6 +826,7 @@ func New() distro.Distro { buildPackages: []string{ "grub2-pc", }, + legacy: "i386-pc", } x8664.setImageTypes( amiImgType, diff --git a/internal/osbuild/grub2_stage.go b/internal/osbuild/grub2_stage.go index 5c3cbf981..c52297381 100644 --- a/internal/osbuild/grub2_stage.go +++ b/internal/osbuild/grub2_stage.go @@ -14,7 +14,7 @@ type GRUB2StageOptions struct { RootFilesystemUUID uuid.UUID `json:"root_fs_uuid"` BootFilesystemUUID *uuid.UUID `json:"boot_fs_uuid,omitempty"` KernelOptions string `json:"kernel_opts,omitempty"` - Legacy bool `json:"legacy"` + Legacy string `json:"legacy,omitempty"` UEFI *GRUB2UEFI `json:"uefi,omitempty"` } diff --git a/internal/osbuild/stage_test.go b/internal/osbuild/stage_test.go index 8e3651ca4..44f0e8005 100644 --- a/internal/osbuild/stage_test.go +++ b/internal/osbuild/stage_test.go @@ -111,7 +111,7 @@ func TestStage_UnmarshalJSON(t *testing.T) { }, }, args: args{ - data: []byte(`{"name":"org.osbuild.grub2","options":{"root_fs_uuid":"00000000-0000-0000-0000-000000000000","legacy":false}}`), + data: []byte(`{"name":"org.osbuild.grub2","options":{"root_fs_uuid":"00000000-0000-0000-0000-000000000000"}}`), }, }, { @@ -126,7 +126,7 @@ func TestStage_UnmarshalJSON(t *testing.T) { }, }, args: args{ - data: []byte(`{"name":"org.osbuild.grub2","options":{"root_fs_uuid":"00000000-0000-0000-0000-000000000000","legacy":false,"uefi":{"vendor":"vendor"}}}`), + data: []byte(`{"name":"org.osbuild.grub2","options":{"root_fs_uuid":"00000000-0000-0000-0000-000000000000","uefi":{"vendor":"vendor"}}}`), }, }, { @@ -139,7 +139,7 @@ func TestStage_UnmarshalJSON(t *testing.T) { }, }, args: args{ - data: []byte(`{"name":"org.osbuild.grub2","options":{"root_fs_uuid":"00000000-0000-0000-0000-000000000000","boot_fs_uuid":"00000000-0000-0000-0000-000000000000","legacy":false}}`), + data: []byte(`{"name":"org.osbuild.grub2","options":{"root_fs_uuid":"00000000-0000-0000-0000-000000000000","boot_fs_uuid":"00000000-0000-0000-0000-000000000000"}}`), }, }, { diff --git a/test/cases/fedora_31-aarch64-ami-boot.json b/test/cases/fedora_31-aarch64-ami-boot.json index 14b3693a3..5c1234e3d 100644 --- a/test/cases/fedora_31-aarch64-ami-boot.json +++ b/test/cases/fedora_31-aarch64-ami-boot.json @@ -1992,7 +1992,6 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro no_timer_check console=ttyS0,115200n8 console=tty1 biosdevname=0 net.ifnames=0 console=ttyS0,115200", - "legacy": false, "uefi": { "vendor": "fedora" } diff --git a/test/cases/fedora_31-aarch64-openstack-boot.json b/test/cases/fedora_31-aarch64-openstack-boot.json index a74b12c4d..67db1e74c 100644 --- a/test/cases/fedora_31-aarch64-openstack-boot.json +++ b/test/cases/fedora_31-aarch64-openstack-boot.json @@ -2052,7 +2052,6 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": false, "uefi": { "vendor": "fedora" } diff --git a/test/cases/fedora_31-aarch64-qcow2-boot.json b/test/cases/fedora_31-aarch64-qcow2-boot.json index 38ac3a29e..a2fa9be4f 100644 --- a/test/cases/fedora_31-aarch64-qcow2-boot.json +++ b/test/cases/fedora_31-aarch64-qcow2-boot.json @@ -1988,7 +1988,6 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": false, "uefi": { "vendor": "fedora" } diff --git a/test/cases/fedora_31-x86_64-ami-boot.json b/test/cases/fedora_31-x86_64-ami-boot.json index da7c5cbc9..738c1a26d 100644 --- a/test/cases/fedora_31-x86_64-ami-boot.json +++ b/test/cases/fedora_31-x86_64-ami-boot.json @@ -1993,7 +1993,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro no_timer_check console=ttyS0,115200n8 console=tty1 biosdevname=0 net.ifnames=0 console=ttyS0,115200", - "legacy": true + "legacy": "i386-pc" } }, { @@ -10205,4 +10205,4 @@ "unbound-anchor.timer" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_31-x86_64-openstack-boot.json b/test/cases/fedora_31-x86_64-openstack-boot.json index 173705965..46bf1e082 100644 --- a/test/cases/fedora_31-x86_64-openstack-boot.json +++ b/test/cases/fedora_31-x86_64-openstack-boot.json @@ -2053,7 +2053,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -10368,4 +10368,4 @@ "unbound-anchor.timer" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_31-x86_64-qcow2-boot.json b/test/cases/fedora_31-x86_64-qcow2-boot.json index 37142b565..ba55be36d 100644 --- a/test/cases/fedora_31-x86_64-qcow2-boot.json +++ b/test/cases/fedora_31-x86_64-qcow2-boot.json @@ -2013,7 +2013,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -10203,4 +10203,4 @@ "unbound-anchor.timer" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_31-x86_64-vhd-boot.json b/test/cases/fedora_31-x86_64-vhd-boot.json index 64b1cabb4..0f1eb0a89 100644 --- a/test/cases/fedora_31-x86_64-vhd-boot.json +++ b/test/cases/fedora_31-x86_64-vhd-boot.json @@ -1910,7 +1910,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -9814,4 +9814,4 @@ "waagent.service" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_31-x86_64-vmdk-boot.json b/test/cases/fedora_31-x86_64-vmdk-boot.json index fb4692ab9..67e1bc541 100644 --- a/test/cases/fedora_31-x86_64-vmdk-boot.json +++ b/test/cases/fedora_31-x86_64-vmdk-boot.json @@ -1946,7 +1946,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -9946,4 +9946,4 @@ "vmtoolsd.service" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_32-x86_64-ami-boot.json b/test/cases/fedora_32-x86_64-ami-boot.json index e3135bfcb..71f8b5328 100644 --- a/test/cases/fedora_32-x86_64-ami-boot.json +++ b/test/cases/fedora_32-x86_64-ami-boot.json @@ -1704,7 +1704,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro no_timer_check console=ttyS0,115200n8 console=tty1 biosdevname=0 net.ifnames=0 console=ttyS0,115200", - "legacy": true + "legacy": "i386-pc" } }, { @@ -8528,4 +8528,4 @@ "unbound-anchor.timer" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_32-x86_64-openstack-boot.json b/test/cases/fedora_32-x86_64-openstack-boot.json index 8ae2bdf22..54adecb21 100644 --- a/test/cases/fedora_32-x86_64-openstack-boot.json +++ b/test/cases/fedora_32-x86_64-openstack-boot.json @@ -1804,7 +1804,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -8851,4 +8851,4 @@ "unbound-anchor.timer" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_32-x86_64-qcow2-boot.json b/test/cases/fedora_32-x86_64-qcow2-boot.json index 56940b26c..12d26d150 100644 --- a/test/cases/fedora_32-x86_64-qcow2-boot.json +++ b/test/cases/fedora_32-x86_64-qcow2-boot.json @@ -1712,7 +1712,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -8480,4 +8480,4 @@ "unbound-anchor.timer" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_32-x86_64-vhd-boot.json b/test/cases/fedora_32-x86_64-vhd-boot.json index 0150039b7..e0bb1c7a8 100644 --- a/test/cases/fedora_32-x86_64-vhd-boot.json +++ b/test/cases/fedora_32-x86_64-vhd-boot.json @@ -1625,7 +1625,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -8153,4 +8153,4 @@ "waagent.service" ] } -} \ No newline at end of file +} diff --git a/test/cases/fedora_32-x86_64-vmdk-boot.json b/test/cases/fedora_32-x86_64-vmdk-boot.json index 9a8886298..d5d04f039 100644 --- a/test/cases/fedora_32-x86_64-vmdk-boot.json +++ b/test/cases/fedora_32-x86_64-vmdk-boot.json @@ -1653,7 +1653,7 @@ "options": { "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac", "kernel_opts": "ro biosdevname=0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -8253,4 +8253,4 @@ "vmtoolsd.service" ] } -} \ No newline at end of file +} diff --git a/test/cases/rhel_8-x86_64-ami-boot.json b/test/cases/rhel_8-x86_64-ami-boot.json index 77a524d35..bb10bda60 100644 --- a/test/cases/rhel_8-x86_64-ami-boot.json +++ b/test/cases/rhel_8-x86_64-ami-boot.json @@ -1899,7 +1899,7 @@ "options": { "root_fs_uuid": "0bd700f8-090f-4556-b797-b340297ea1bd", "kernel_opts": "ro console=ttyS0,115200n8 console=tty0 net.ifnames=0 rd.blacklist=nouveau nvme_core.io_timeout=4294967295 crashkernel=auto", - "legacy": true + "legacy": "i386-pc" } }, { @@ -9255,4 +9255,4 @@ ], "timezone": "UTC" } -} \ No newline at end of file +} diff --git a/test/cases/rhel_8-x86_64-openstack-boot.json b/test/cases/rhel_8-x86_64-openstack-boot.json index 75651e026..07d769d3c 100644 --- a/test/cases/rhel_8-x86_64-openstack-boot.json +++ b/test/cases/rhel_8-x86_64-openstack-boot.json @@ -2072,7 +2072,7 @@ "options": { "root_fs_uuid": "0bd700f8-090f-4556-b797-b340297ea1bd", "kernel_opts": "ro net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -9916,4 +9916,4 @@ ], "timezone": "UTC" } -} \ No newline at end of file +} diff --git a/test/cases/rhel_8-x86_64-qcow2-boot.json b/test/cases/rhel_8-x86_64-qcow2-boot.json index 913622d30..a2e3d8e8d 100644 --- a/test/cases/rhel_8-x86_64-qcow2-boot.json +++ b/test/cases/rhel_8-x86_64-qcow2-boot.json @@ -2086,7 +2086,7 @@ "options": { "root_fs_uuid": "0bd700f8-090f-4556-b797-b340297ea1bd", "kernel_opts": "console=ttyS0 console=ttyS0,115200n8 no_timer_check crashkernel=auto net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -10003,4 +10003,4 @@ ], "timezone": "UTC" } -} \ No newline at end of file +} diff --git a/test/cases/rhel_8-x86_64-vhd-boot.json b/test/cases/rhel_8-x86_64-vhd-boot.json index c9c94a2cd..3da7d772d 100644 --- a/test/cases/rhel_8-x86_64-vhd-boot.json +++ b/test/cases/rhel_8-x86_64-vhd-boot.json @@ -2039,7 +2039,7 @@ "options": { "root_fs_uuid": "0bd700f8-090f-4556-b797-b340297ea1bd", "kernel_opts": "ro biosdevname=0 rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -9826,4 +9826,4 @@ ], "timezone": "UTC" } -} \ No newline at end of file +} diff --git a/test/cases/rhel_8-x86_64-vmdk-boot.json b/test/cases/rhel_8-x86_64-vmdk-boot.json index 9061707ea..e1218a74c 100644 --- a/test/cases/rhel_8-x86_64-vmdk-boot.json +++ b/test/cases/rhel_8-x86_64-vmdk-boot.json @@ -1973,7 +1973,7 @@ "options": { "root_fs_uuid": "0bd700f8-090f-4556-b797-b340297ea1bd", "kernel_opts": "ro net.ifnames=0", - "legacy": true + "legacy": "i386-pc" } }, { @@ -9530,4 +9530,4 @@ ], "timezone": "UTC" } -} \ No newline at end of file +}