blob: de8e4c283b4f1c2d4925bdc60b3894e853a4fd15 [file] [log] [blame]
Klaus Heinrich Kiwid1cd8c52020-02-27 12:43:47 -03001From dd5c8ee1440bde77c6829a084c0116d059949720 Mon Sep 17 00:00:00 2001
2From: Jeremy Kerr <jk@ozlabs.org>
3Date: Thu, 14 Nov 2019 15:08:21 +0800
4Subject: [PATCH 16/18] test/parser: Add test for recent RHCOS grub2 config
5
6Add a test for a RHCOS grub2 boot config, using the ignition firstboot
7facility.
8
9Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
10(cherry picked from commit 1ef95c2606eb6c9fcf3530504317f3a0b1a1ba34)
11Signed-off-by: Klaus Heinrich Kiwi <klaus@linux.vnet.ibm.com>
12---
13 test/parser/Makefile.am | 1 +
14 test/parser/data/grub2-rhcos-ootpa.conf | 194 ++++++++++++++++++++++++
15 test/parser/test-grub2-rhcos-ootpa.c | 38 +++++
16 3 files changed, 233 insertions(+)
17 create mode 100644 test/parser/data/grub2-rhcos-ootpa.conf
18 create mode 100644 test/parser/test-grub2-rhcos-ootpa.c
19
20diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am
21index 5f1a93b..5f7922c 100644
22--- a/test/parser/Makefile.am
23+++ b/test/parser/Makefile.am
24@@ -43,6 +43,7 @@ parser_TESTS = \
25 test/parser/test-grub2-f20-ppc64 \
26 test/parser/test-grub2-ubuntu-13_04-x86 \
27 test/parser/test-grub2-sles-btrfs-snapshot \
28+ test/parser/test-grub2-rhcos-ootpa \
29 test/parser/test-grub2-lexer-error \
30 test/parser/test-grub2-parser-error \
31 test/parser/test-grub2-test-file-ops \
32diff --git a/test/parser/data/grub2-rhcos-ootpa.conf b/test/parser/data/grub2-rhcos-ootpa.conf
33new file mode 100644
34index 0000000..329980e
35--- /dev/null
36+++ b/test/parser/data/grub2-rhcos-ootpa.conf
37@@ -0,0 +1,194 @@
38+#
39+# DO NOT EDIT THIS FILE
40+#
41+# It is automatically generated by grub2-mkconfig using templates
42+# from /etc/grub.d and settings from /etc/default/grub
43+#
44+
45+### BEGIN /etc/grub.d/00_header ###
46+set pager=1
47+
48+if [ -f ${config_directory}/grubenv ]; then
49+ load_env -f ${config_directory}/grubenv
50+elif [ -s $prefix/grubenv ]; then
51+ load_env
52+fi
53+if [ "${next_entry}" ] ; then
54+ set default="${next_entry}"
55+ set next_entry=
56+ save_env next_entry
57+ set boot_once=true
58+else
59+ set default="${saved_entry}"
60+fi
61+
62+if [ x"${feature_menuentry_id}" = xy ]; then
63+ menuentry_id_option="--id"
64+else
65+ menuentry_id_option=""
66+fi
67+
68+export menuentry_id_option
69+
70+if [ "${prev_saved_entry}" ]; then
71+ set saved_entry="${prev_saved_entry}"
72+ save_env saved_entry
73+ set prev_saved_entry=
74+ save_env prev_saved_entry
75+ set boot_once=true
76+fi
77+
78+function savedefault {
79+ if [ -z "${boot_once}" ]; then
80+ saved_entry="${chosen}"
81+ save_env saved_entry
82+ fi
83+}
84+
85+function load_video {
86+ if [ x$feature_all_video_module = xy ]; then
87+ insmod all_video
88+ else
89+ insmod efi_gop
90+ insmod efi_uga
91+ insmod ieee1275_fb
92+ insmod vbe
93+ insmod vga
94+ insmod video_bochs
95+ insmod video_cirrus
96+ fi
97+}
98+
99+terminal_output ofconsole
100+if [ x$feature_timeout_style = xy ] ; then
101+ set timeout_style=menu
102+ set timeout=1
103+# Fallback normal timeout code in case the timeout_style feature is
104+# unavailable.
105+else
106+ set timeout=1
107+fi
108+### END /etc/grub.d/00_header ###
109+
110+### BEGIN /etc/grub.d/01_menu_auto_hide ###
111+if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then
112+ set last_boot_ok=1
113+else
114+ set last_boot_ok=0
115+fi
116+
117+# Reset boot_indeterminate after a successful boot
118+if [ "${boot_success}" = "1" ] ; then
119+ set boot_indeterminate=0
120+# Avoid boot_indeterminate causing the menu to be hidden more then once
121+elif [ "${boot_indeterminate}" = "1" ]; then
122+ set boot_indeterminate=2
123+fi
124+set boot_success=0
125+save_env boot_success boot_indeterminate
126+
127+if [ x$feature_timeout_style = xy ] ; then
128+ if [ "${menu_show_once}" ]; then
129+ unset menu_show_once
130+ save_env menu_show_once
131+ set timeout_style=menu
132+ set timeout=60
133+ elif [ "${menu_auto_hide}" -a "${last_boot_ok}" = "1" ]; then
134+ set orig_timeout_style=${timeout_style}
135+ set orig_timeout=${timeout}
136+ if [ "${fastboot}" = "1" ]; then
137+ # timeout_style=menu + timeout=0 avoids the countdown code keypress check
138+ set timeout_style=menu
139+ set timeout=0
140+ else
141+ set timeout_style=hidden
142+ set timeout=1
143+ fi
144+ fi
145+fi
146+### END /etc/grub.d/01_menu_auto_hide ###
147+
148+### BEGIN /etc/grub.d/01_users ###
149+if [ -f ${prefix}/user.cfg ]; then
150+ source ${prefix}/user.cfg
151+ if [ -n "${GRUB2_PASSWORD}" ]; then
152+ set superusers="root"
153+ export superusers
154+ password_pbkdf2 root ${GRUB2_PASSWORD}
155+ fi
156+fi
157+### END /etc/grub.d/01_users ###
158+
159+### BEGIN /etc/grub.d/02_ignition_firstboot ###
160+# We store the file on the /boot/ partition so find the
161+# boot partition. On UEFI this may different than the grub
162+# $root so we search for it here.
163+# https://github.com/coreos/ignition-dracut/issues/51
164+search --set=bootpart --label boot
165+# Determine if this is a first boot and set the variable
166+# to be used later on the kernel command line.
167+set ignition_firstboot=""
168+if [ -f "(${bootpart})/ignition.firstboot" ]; then
169+ # default to dhcp networking parameters to be used with ignition
170+ set ignition_network_kcmdline='rd.neednet=1 ip=dhcp'
171+
172+ # source in the `ignition.firstboot` file which could override the
173+ # above $ignition_network_kcmdline with static networking config.
174+ # This override feature is primarily used by coreos-installer to
175+ # persist static networking config provided during install to the
176+ # first boot of the machine.
177+ source "(${bootpart})/ignition.firstboot"
178+
179+ # we support setting variables in the
180+ set ignition_firstboot="ignition.firstboot $ignition_network_kcmdline $ignition_extra_kcmdline"
181+fi
182+### END /etc/grub.d/02_ignition_firstboot ###
183+
184+### BEGIN /etc/grub.d/10_linux_bls ###
185+
186+### END /etc/grub.d/10_linux_bls ###
187+
188+### BEGIN /etc/grub.d/15_ostree ###
189+menuentry 'Red Hat Enterprise Linux CoreOS 42.80.20191030.0 (Ootpa) (ostree)' --class gnu-linux --class gnu --class os --unrestricted 'ostree-0-645e1535-a6f3-4fa6-a82c-b8c032619a7b' {
190+load_video
191+set gfxpayload=keep
192+insmod gzio
193+insmod part_gpt
194+insmod ext2
195+set root='hd0,gpt2'
196+if [ x$feature_platform_search_hint = xy ]; then
197+ search --no-floppy --fs-uuid --set=root --hint='hd0,gpt2' 645e1535-a6f3-4fa6-a82c-b8c032619a7b
198+else
199+ search --no-floppy --fs-uuid --set=root 645e1535-a6f3-4fa6-a82c-b8c032619a7b
200+fi
201+linux /ostree/rhcos-6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/vmlinuz-4.18.0-80.11.2.el8_0.ppc64le console=tty0 console=hvc0,115200n8 rootflags=defaults,prjquota rw $ignition_firstboot root=UUID=8d8a5c3b-97e6-4d7b-bb87-206af5a9d851 ostree=/ostree/boot.0/rhcos/6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/0 ignition.platform.id=openstack
202+initrd /ostree/rhcos-6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/initramfs-4.18.0-80.11.2.el8_0.ppc64le.img
203+}
204+### END /etc/grub.d/15_ostree ###
205+
206+### BEGIN /etc/grub.d/20_linux_xen ###
207+### END /etc/grub.d/20_linux_xen ###
208+
209+### BEGIN /etc/grub.d/20_ppc_terminfo ###
210+ terminfo -g 80x24 ofconsole
211+### END /etc/grub.d/20_ppc_terminfo ###
212+
213+### BEGIN /etc/grub.d/30_os-prober ###
214+### END /etc/grub.d/30_os-prober ###
215+
216+### BEGIN /etc/grub.d/30_uefi-firmware ###
217+### END /etc/grub.d/30_uefi-firmware ###
218+
219+### BEGIN /etc/grub.d/40_custom ###
220+# This file provides an easy way to add custom menu entries. Simply type the
221+# menu entries you want to add after this comment. Be careful not to change
222+# the 'exec tail' line above.
223+### END /etc/grub.d/40_custom ###
224+
225+### BEGIN /etc/grub.d/41_custom ###
226+if [ -f ${config_directory}/custom.cfg ]; then
227+ source ${config_directory}/custom.cfg
228+elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
229+ source $prefix/custom.cfg;
230+fi
231+### END /etc/grub.d/41_custom ###
232diff --git a/test/parser/test-grub2-rhcos-ootpa.c b/test/parser/test-grub2-rhcos-ootpa.c
233new file mode 100644
234index 0000000..19299be
235--- /dev/null
236+++ b/test/parser/test-grub2-rhcos-ootpa.c
237@@ -0,0 +1,38 @@
238+
239+#include "parser-test.h"
240+
241+void run_test(struct parser_test *test)
242+{
243+ struct discover_boot_option *opt;
244+ struct discover_context *ctx;
245+ struct discover_device *dev;
246+
247+ ctx = test->ctx;
248+
249+ dev = test_create_device(test, "bootdev");
250+ dev->label = "boot";
251+ device_handler_add_device(test->handler, dev);
252+
253+ test_read_conf_file(test, "grub2-rhcos-ootpa.conf",
254+ "/grub/grub.cfg");
255+
256+ /* add the ignition.firstboot file on the boot-labelled partition,
257+ * to check that we can source this correctly */
258+ test_add_file_string(test, dev,
259+ "/ignition.firstboot",
260+ "ignition_extra_kcmdline=meep\n");
261+
262+ test_run_parser(test, "grub2");
263+
264+ check_boot_option_count(ctx, 1);
265+
266+ opt = get_boot_option(ctx, 0);
267+ check_name(opt,
268+ "Red Hat Enterprise Linux CoreOS 42.80.20191030.0 (Ootpa) (ostree)");
269+ check_args(opt, "console=tty0 console=hvc0,115200n8 "
270+ "rootflags=defaults,prjquota rw "
271+ "ignition.firstboot rd.neednet=1 ip=dhcp meep "
272+ "root=UUID=8d8a5c3b-97e6-4d7b-bb87-206af5a9d851 "
273+ "ostree=/ostree/boot.0/rhcos/6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/0 "
274+ "ignition.platform.id=openstack");
275+}
276--
2772.17.1
278