From 05326982f34cbc02a3f459fb02611ad352dd1697 Mon Sep 17 00:00:00 2001 From: Lukas Ruzicka Date: Tue, 7 Nov 2023 12:22:23 +0100 Subject: [PATCH] Create an RTT test as a proof of concept. --- templates.fif.json | 14 +++++ tests/rtt/aaa_setup.pm | 26 +++++++++ tests/rtt/boot_once.pm | 72 +++++++++++++++++++++++++ tests/rtt/cmdline_preserved.pm | 46 ++++++++++++++++ tests/rtt/set_default.pm | 98 ++++++++++++++++++++++++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 tests/rtt/aaa_setup.pm create mode 100644 tests/rtt/boot_once.pm create mode 100644 tests/rtt/cmdline_preserved.pm create mode 100644 tests/rtt/set_default.pm diff --git a/templates.fif.json b/templates.fif.json index f0c515e0..0b44df38 100644 --- a/templates.fif.json +++ b/templates.fif.json @@ -3126,6 +3126,20 @@ "USER_LOGIN": "false", "WORKER_CLASS": "tap2" } + }, + "rtt_tests": { + "profiles": { + "fedora-Server-dvd-iso-aarch64-*-aarch64": 20, + "fedora-Server-dvd-iso-ppc64le-*-ppc64le": 20, + "fedora-Server-dvd-iso-x86_64-*-64bit": 20 + }, + "settings": { + "BOOTFROM": "c", + "HDD_1": "disk_%FLAVOR%_%MACHINE%.qcow2", + "POSTINSTALL_PATH": "tests/rtt", + "START_AFTER_TEST": "%DEPLOY_UPLOAD_TEST%", + "USER_LOGIN": "false" + } } } } diff --git a/tests/rtt/aaa_setup.pm b/tests/rtt/aaa_setup.pm new file mode 100644 index 00000000..589089ba --- /dev/null +++ b/tests/rtt/aaa_setup.pm @@ -0,0 +1,26 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + + +# This will log root onto a virtual console and an image +# will be created for further use. +# Thus we will not have to restore everything and clean at +# the end of every test script. + +sub run { + my $self = shift; + + # Let's go to the virtual console + $self->root_console(tty => 3); +} + + +sub test_flags { + return {fatal => 1, milestone => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/rtt/boot_once.pm b/tests/rtt/boot_once.pm new file mode 100644 index 00000000..0e3a0fcc --- /dev/null +++ b/tests/rtt/boot_once.pm @@ -0,0 +1,72 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + + +# This test adds a new boot entry into Grub and sets this +# entry as the next boot entry. Then it reboots the computer +# and checks that the temporary boot entry has been booted. +# Then it reboots again and sees, if the original boot +# entry is used. + +sub run { + my $self = shift; + my $new_cmdline = ''; + my $title = "Terminator kernel"; + my $cli_args = "terminate"; + + # Let's go to the virtual console to perform the testing. + $self->root_console(tty => 3); + + # Now, we have a freshly booted system with the + # default boot entry, so we will remember the + # command line. + my $default_cmdline = script_output("cat /proc/cmdline"); + + # Then we will set up the temporary boot entry. + # First, let's check that no /boot/kernel exists + my $system = script_output("uname -r"); + assert_script_run("! grubby --info=/boot/kernel"); + assert_script_run("cp /boot/vmlinuz-$system /boot/kernel"); + assert_script_run("cp /boot/initramfs-$system.img /boot/initrd"); + # Assert that no test arguments exist in the cmdline. + assert_script_run("! grep $cli_args /proc/cmdline"); + # Add custom kernel entry + assert_script_run("grubby --copy-default --add-kernel=/boot/kernel --initrd=/boot/initrd --title='$title' --args=$cli_args"); + # Set temporary default + assert_script_run("grub2-reboot '$title'"); + + # Reboot the system. + enter_cmd("reboot"); + # Wait until we arrive at the login screen and log + # onto the console again. + boot_to_login_screen; + $self->root_console(tty => 3); + + # Check that the correct kernel has been booted. + assert_script_run("grep $cli_args /proc/cmdline"); + + # Reboot the system. + enter_cmd("reboot"); + # Wait until we arrive at the login screen and log + # onto the console again. + boot_to_login_screen; + $self->root_console(tty => 3); + + # Check that the previous kernel has been booted. + assert_script_run("! grep $cli_args /proc/cmdline"); + + my $current_cmdline = script_output("cat /proc/cmdline"); + + die("Some unexpected kernel entry has been used.") if ($current_cmdline ne $default_cmdline); +} + + +sub test_flags { + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/rtt/cmdline_preserved.pm b/tests/rtt/cmdline_preserved.pm new file mode 100644 index 00000000..30d0bf0f --- /dev/null +++ b/tests/rtt/cmdline_preserved.pm @@ -0,0 +1,46 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + + +# This test reboots the computer and checks that a correct boot entry +# is booted. + +sub run { + my $self = shift; + my $boot_count = 0; + my $old_cmdline = ''; + my $new_cmdline = ''; + + # Let's go to the virtual console to perform the testing. + $self->root_console(tty => 3); + + # Now, we have a freshly booted system, so we will + # record the current kernel command line. + $old_cmdline = script_output("cat /proc/cmdline"); + + # Reboot the system. + enter_cmd("reboot"); + # Wait until we arrive at the login screen and log + # onto the console again. + boot_to_login_screen; + $self->root_console(tty => 3); + + # Now, let us check the cmdline again and compare it + # to the previous. We will fail, if the two cmdlines + # differ. + $new_cmdline = script_output("cat /proc/cmdline"); + diag("Expected cmdline: $old_cmdline"); + diag("Current cmdline: $new_cmdline"); + die("CMDline check failed.") if ($old_cmdline ne $new_cmdline); +} + + +sub test_flags { + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/rtt/set_default.pm b/tests/rtt/set_default.pm new file mode 100644 index 00000000..46bc4f03 --- /dev/null +++ b/tests/rtt/set_default.pm @@ -0,0 +1,98 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + + +# This test adds a new boot entry into Grub and sets this +# entry as the next boot entry. Then it reboots the computer +# and checks that the temporary boot entry has been booted. +# Then it reboots again and sees, if the original boot +# entry is used. + +sub print_saved_entry { + my $saved_entry = script_output('grub2-editenv list | awk -F= \'$1 == "saved_entry" { print $2}\''); + return $saved_entry; +} + +sub reboot { + enter_cmd("reboot"); + boot_to_login_screen; + sleep 5; +} + +sub run { + my $self = shift; + my $new_cmdline = ''; + my $title = "Terminator kernel"; + my $cli_args = "terminate"; + + # Let's go to the virtual console to perform the testing. + $self->root_console(tty => 3); + + my $machine_id = script_output("cat /etc/machine-id"); + + # Now, we have a freshly booted system with the + # default boot entry, so we will remember the + # command line. + my $default_cmdline = script_output("cat /proc/cmdline", timeout => 60); + + # Backup the current entries + assert_script_run("cp -r /boot/loader/entries old-entries"); + assert_script_run("cp /boot/grub2/grubenv grubenv"); + my $original_entry = print_saved_entry(); + # Then we will set up the temporary boot entry. + # First, let's check that no /boot/kernel exists + my $system = script_output("uname -r"); + # Add custom kernel entry + assert_script_run("grubby --add-kernel=/boot/vmlinuz-$system --initrd=/boot/initramfs-$system.img --copy-default --title='$title' --args=$cli_args"); + # Set temporary default + assert_script_run("grub2-reboot '$machine_id-$system.0~custom'"); + + # Reboot the system. + reboot(); + $self->root_console(tty => 3); + + # Check that the correct kernel has been booted. + my $current_cmdline = script_output("cat /proc/cmdline", timeout => 60); + die("Default entry has been booted.") if ($current_cmdline eq $default_cmdline); + assert_script_run("grep $cli_args /proc/cmdline"); + + # Reboot the system. + reboot(); + $self->root_console(tty => 3); + + # Check that the previous kernel has been booted. + my $current_cmdline = script_output("cat /proc/cmdline", timeout => 60); + die("Custom entry has been booted.") if ($current_cmdline ne $default_cmdline); + assert_script_run("! grep $cli_args /proc/cmdline"); + # Set the new entry as default and reboot. + assert_script_run("grub2-set-default '$machine_id-$system.0~custom'"); + # + # Reboot the system. + reboot(); + $self->root_console(tty => 3); + + # Check that the new kernel has been booted. + my $current_cmdline = script_output("cat /proc/cmdline"); + die("Default entry has been booted.") if ($current_cmdline eq $default_cmdline); + assert_script_run("grep $cli_args /proc/cmdline"); + + # Reboot again + reboot(); + $self->root_console(tty => 3); + + # Check that the new kernel has been booted again. + my $current_cmdline = script_output("cat /proc/cmdline"); + die("Default entry has been booted.") if ($current_cmdline eq $default_cmdline); + assert_script_run("grep $cli_args /proc/cmdline"); +} + + +sub test_flags { + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: