Skip to content

Commit ec0d70d

Browse files
committed
iso_bootloaders: Set MenuTimeout from InstallerCustomizations
Also adds tests. Related: HMS-10627
1 parent 6c1c58f commit ec0d70d

2 files changed

Lines changed: 72 additions & 23 deletions

File tree

pkg/image/iso_bootloaders.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (img *ISOBootloaders) Bootloaders(buildPipeline manifest.Build, platform pl
3737
grub2.ISOLabel = img.ISOCustomizations.Label
3838
grub2.KernelOpts = kernelOpts
3939
grub2.DefaultMenu = img.InstallerCustomizations.DefaultMenu
40+
grub2.MenuTimeout = img.InstallerCustomizations.MenuTimeout
4041

4142
for _, entry := range img.Custom {
4243
grub2.Custom = append(grub2.Custom, manifest.ISOGrub2MenuEntry{
@@ -55,6 +56,7 @@ func (img *ISOBootloaders) Bootloaders(buildPipeline manifest.Build, platform pl
5556
grub2ppc64.ISOLabel = img.ISOCustomizations.Label
5657
grub2ppc64.KernelOpts = kernelOpts
5758
grub2ppc64.DefaultMenu = img.InstallerCustomizations.DefaultMenu
59+
grub2ppc64.MenuTimeout = img.InstallerCustomizations.MenuTimeout
5860

5961
for _, entry := range img.Custom {
6062
grub2ppc64.Custom = append(grub2ppc64.Custom, manifest.ISOGrub2MenuEntry{
@@ -80,6 +82,9 @@ func (img *ISOBootloaders) Bootloaders(buildPipeline manifest.Build, platform pl
8082
efiPipeline.UEFIVendor = platform.GetUEFIVendor()
8183
efiPipeline.ISOLabel = img.ISOCustomizations.Label
8284
efiPipeline.DefaultMenu = img.InstallerCustomizations.DefaultMenu
85+
if img.InstallerCustomizations.MenuTimeout > 0 {
86+
efiPipeline.MenuTimeout = &img.InstallerCustomizations.MenuTimeout
87+
}
8388
efiPipeline.KernelOpts = kernelOpts
8489

8590
for _, entry := range img.Custom {

pkg/image/iso_bootloaders_test.go

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ import (
55
"math/rand"
66
"testing"
77

8+
"github.com/osbuild/image-builder/internal/common"
89
"github.com/osbuild/image-builder/pkg/customizations/fsnode"
910
"github.com/osbuild/image-builder/pkg/disk"
1011
"github.com/osbuild/image-builder/pkg/image"
1112
"github.com/osbuild/image-builder/pkg/manifest"
1213
"github.com/osbuild/image-builder/pkg/osbuild"
1314
"github.com/osbuild/image-builder/pkg/runner"
15+
1416
"github.com/stretchr/testify/assert"
1517
"github.com/stretchr/testify/require"
1618
)
1719

1820
func TestBootType(t *testing.T) {
19-
ibl := image.ISOBootloaders{
20-
InstallerCustomizations: &manifest.InstallerCustomizations{Product: "Fedora", OSVersion: "44"},
21-
ISOCustomizations: &manifest.ISOCustomizations{Label: "Fedora-44-test"},
22-
}
23-
2421
source := rand.NewSource(int64(0))
2522
// math/rand is good enough in this case
2623
/* #nosec G404 */
@@ -35,9 +32,11 @@ func TestBootType(t *testing.T) {
3532
}
3633

3734
type testCase struct {
38-
bootType manifest.ISOBootType
39-
custom []manifest.ISOGrub2MenuEntry
40-
expected []results
35+
bootType manifest.ISOBootType
36+
custom []manifest.ISOGrub2MenuEntry
37+
defaultMenu *int
38+
menuTimeout *int
39+
expected []results
4140
}
4241

4342
var noCustomMenus []manifest.ISOGrub2MenuEntry
@@ -52,24 +51,38 @@ func TestBootType(t *testing.T) {
5251

5352
// Check the stages and files for each bootloader type
5453
tests := []testCase{
55-
testCase{manifest.Grub2UEFIOnlyISOBoot, noCustomMenus, []results{{
56-
stages: []string{
57-
"org.osbuild.truncate",
58-
"org.osbuild.mkfs.fat",
59-
"org.osbuild.copy",
60-
"org.osbuild.copy"},
61-
paths: []string{}},
62-
}},
63-
testCase{manifest.SyslinuxISOBoot, noCustomMenus, []results{
64-
{stages: []string{"org.osbuild.isolinux"}, paths: []string{}}, {
54+
testCase{manifest.Grub2UEFIOnlyISOBoot, noCustomMenus, nil, nil,
55+
[]results{{
6556
stages: []string{
6657
"org.osbuild.truncate",
6758
"org.osbuild.mkfs.fat",
6859
"org.osbuild.copy",
6960
"org.osbuild.copy"},
7061
paths: []string{}},
62+
}},
63+
testCase{manifest.SyslinuxISOBoot, noCustomMenus, nil, nil,
64+
[]results{
65+
{stages: []string{"org.osbuild.isolinux"}, paths: []string{}}, {
66+
stages: []string{
67+
"org.osbuild.truncate",
68+
"org.osbuild.mkfs.fat",
69+
"org.osbuild.copy",
70+
"org.osbuild.copy"},
71+
paths: []string{}},
72+
}},
73+
testCase{manifest.Grub2ISOBoot, noCustomMenus, nil, nil, []results{{
74+
stages: []string{
75+
"org.osbuild.grub2.iso.legacy",
76+
"org.osbuild.grub2.inst"},
77+
paths: []string{}}, {
78+
stages: []string{
79+
"org.osbuild.truncate",
80+
"org.osbuild.mkfs.fat",
81+
"org.osbuild.copy",
82+
"org.osbuild.copy"},
83+
paths: []string{}},
7184
}},
72-
testCase{manifest.Grub2ISOBoot, noCustomMenus, []results{{
85+
testCase{manifest.Grub2ISOBoot, customMenus, nil, nil, []results{{
7386
stages: []string{
7487
"org.osbuild.grub2.iso.legacy",
7588
"org.osbuild.grub2.inst"},
@@ -81,7 +94,7 @@ func TestBootType(t *testing.T) {
8194
"org.osbuild.copy"},
8295
paths: []string{}},
8396
}},
84-
testCase{manifest.Grub2ISOBoot, customMenus, []results{{
97+
testCase{manifest.Grub2ISOBoot, customMenus, common.ToPtr(1), common.ToPtr(5), []results{{
8598
stages: []string{
8699
"org.osbuild.grub2.iso.legacy",
87100
"org.osbuild.grub2.inst"},
@@ -93,21 +106,29 @@ func TestBootType(t *testing.T) {
93106
"org.osbuild.copy"},
94107
paths: []string{}},
95108
}},
96-
testCase{manifest.Grub2PPCISOBoot, noCustomMenus, []results{{
109+
testCase{manifest.Grub2PPCISOBoot, noCustomMenus, nil, nil,
110+
[]results{{
111+
stages: []string{
112+
"org.osbuild.grub2.iso.legacy",
113+
"org.osbuild.mkdir",
114+
"org.osbuild.copy"},
115+
paths: []string{"/ppc/bootinfo.txt"}},
116+
}},
117+
testCase{manifest.Grub2PPCISOBoot, customMenus, nil, nil, []results{{
97118
stages: []string{
98119
"org.osbuild.grub2.iso.legacy",
99120
"org.osbuild.mkdir",
100121
"org.osbuild.copy"},
101122
paths: []string{"/ppc/bootinfo.txt"}},
102123
}},
103-
testCase{manifest.Grub2PPCISOBoot, customMenus, []results{{
124+
testCase{manifest.Grub2PPCISOBoot, customMenus, common.ToPtr(3), common.ToPtr(15), []results{{
104125
stages: []string{
105126
"org.osbuild.grub2.iso.legacy",
106127
"org.osbuild.mkdir",
107128
"org.osbuild.copy"},
108129
paths: []string{"/ppc/bootinfo.txt"}},
109130
}},
110-
testCase{manifest.S390ISOBoot, noCustomMenus, []results{{
131+
testCase{manifest.S390ISOBoot, noCustomMenus, nil, nil, []results{{
111132
stages: []string{
112133
"org.osbuild.copy",
113134
"org.osbuild.copy",
@@ -128,8 +149,19 @@ func TestBootType(t *testing.T) {
128149
for _, tc := range tests {
129150
mf := manifest.New()
130151
buildPipeline := image.AddBuildBootstrapPipelines(&mf, runner, nil, nil)
152+
153+
ibl := image.ISOBootloaders{
154+
InstallerCustomizations: &manifest.InstallerCustomizations{Product: "Fedora", OSVersion: "44"},
155+
ISOCustomizations: &manifest.ISOCustomizations{Label: "Fedora-44-test"},
156+
}
131157
ibl.ISOCustomizations.BootType = tc.bootType
132158
ibl.Custom = tc.custom
159+
if tc.defaultMenu != nil {
160+
ibl.InstallerCustomizations.DefaultMenu = *tc.defaultMenu
161+
}
162+
if tc.menuTimeout != nil {
163+
ibl.InstallerCustomizations.MenuTimeout = *tc.menuTimeout
164+
}
133165
bootloaders := ibl.Bootloaders(buildPipeline, testPlatform, []string{})
134166
require.Len(t, bootloaders, len(tc.expected))
135167

@@ -149,6 +181,18 @@ func TestBootType(t *testing.T) {
149181
options := grub2Stage.Options.(*osbuild.Grub2ISOLegacyStageOptions)
150182
require.NotNil(t, options)
151183
checkCustomMenus(t, tc.custom, options.Custom)
184+
if tc.defaultMenu != nil {
185+
require.NotNil(t, options.Config)
186+
assert.Equal(t, *tc.defaultMenu, options.Config.Default)
187+
} else {
188+
assert.Nil(t, options.Config)
189+
}
190+
if tc.menuTimeout != nil {
191+
require.NotNil(t, options.Config)
192+
assert.Equal(t, *tc.menuTimeout, options.Config.Timeout)
193+
} else {
194+
assert.Nil(t, options.Config)
195+
}
152196
}
153197
}
154198
}

0 commit comments

Comments
 (0)