1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2024-12-01 17:53:08 +00:00
os-autoinst-distri-fedora/tests/rtt/set_default.pm

99 lines
3.2 KiB
Perl
Raw Normal View History

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: