#!/bin/bash## kola:## # We don't need a special Ignition config and we don't modify the VM## exclusive: false## # s390x doesn't have any configuration in platforms.yaml, so## # platforms.json is not included in the image## architectures: "! s390x"## description: Verify that the kargs and grub.cfg commands specified in## platforms.json have been properly applied to the image.# Also check cosa correctly translated platforms.yaml to platforms.json, by# spot-checking certain expected values in platforms.json.set -xeuo pipefail# shellcheck disable=SC1091. "$KOLA_EXT_DATA/commonlib.sh"platform_json_kargs() {jq -r ".$1.kernel_arguments // [] | join(\" \")" < /boot/coreos/platforms.json}platform_json_grub_cmds() {jq -r ".$1.grub_commands // [] | join(\"\\\\n\")" < /boot/coreos/platforms.json}check_platforms_json() {local platform="$1" expected_kargs="$2" expected_grub_cmds="$3"found_kargs=$(platform_json_kargs "$platform")found_grub_cmds=$(platform_json_grub_cmds "$platform")if [ "$expected_kargs" != "$found_kargs" ]; thenfatal "platforms.json incorrect kargs for $platform"fiif [ "$expected_grub_cmds" != "$found_grub_cmds" ]; thenfatal "platforms.json incorrect GRUB commands for $platform"fiok "platforms.json for $platform"}# Check whether platforms.json existsif [ ! -e /boot/coreos/platforms.json ]; thenfatal "platforms.json doesn't exist!"fiok "platforms.json exists!"# Check that platforms.json matches grub.cfg and kargsplatform=$(cmdline_arg ignition.platform.id)expected_kargs=$(platform_json_kargs "$platform")expected_grub_cmds=$(platform_json_grub_cmds "$platform")if [ -f /boot/grub2/console.cfg ]; thengrub_console_cfg_file=/boot/grub2/console.cfgelsegrub_console_cfg_file=/boot/grub2/grub.cfgfiif [ -n "$expected_kargs" ] && ! grep -Eq " ${expected_kargs}( |$)" /proc/cmdline; thenfatal "Didn't find $expected_kargs in $(cat /proc/cmdline)"fiif [ -n "$expected_grub_cmds" ] && ! grep -qzP "\n${expected_grub_cmds}\n" $grub_console_cfg_file; thenfatal "Didn't find platform grub commands in ${grub_console_cfg_file}"fiok "platforms.json matches grub.cfg and kargs"# Check that platforms.json has reasonable contents (i.e. that cosa# properly forwarded it from platforms.yaml).# Check at least one platform on each architecture.case $(uname -m) inx86_64)# Matches the legacy defaultscheck_platforms_json qemu "console=tty0 console=ttyS0,115200n8" "serial --speed=115200\nterminal_input serial console\nterminal_output serial console"# Different from legacy defaultscheck_platforms_json applehv "console=tty0 console=hvc0" "serial --speed=115200\nterminal_input serial console\nterminal_output serial console"check_platforms_json azure "console=tty0 console=ttyS0,115200n8" "";;aarch64)# GRUB commands but no kargscheck_platforms_json qemu "" "serial --speed=115200\nterminal_input serial console\nterminal_output serial console";;ppc64le)# Kargs but no GRUB commandscheck_platforms_json qemu "console=hvc0 console=tty0" "";;riscv)# Matches the legacy defaultscheck_platforms_json qemu "console=tty0 console=ttyS0,115200n8" "serial --speed=115200\nterminal_input serial console\nterminal_output serial console";;esacok "platforms.json has expected contents"