2015-03-18 21:28:03 +00:00
|
|
|
package fedoradistribution;
|
2020-02-13 21:31:05 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2015-03-18 21:28:03 +00:00
|
|
|
use base 'distribution';
|
2019-11-06 12:55:27 +00:00
|
|
|
use Cwd;
|
2015-03-18 21:28:03 +00:00
|
|
|
|
|
|
|
# Fedora distribution class
|
|
|
|
|
2015-08-05 06:23:59 +00:00
|
|
|
# Distro-specific functions, that are actually part of the API
|
|
|
|
# (and it's completely up to us to implement them) should be here
|
|
|
|
|
|
|
|
# functions that can be reimplemented:
|
2021-12-23 12:08:13 +00:00
|
|
|
# ensure_installed (reimplemented here)
|
|
|
|
# x11_start_program (reimplemented here)
|
|
|
|
# become_root (reimplemented here)
|
|
|
|
# script_sudo (reimplemented here)
|
|
|
|
# assert_script_sudo (reimplemented here
|
|
|
|
# type_password (works as is)
|
2015-08-05 06:23:59 +00:00
|
|
|
|
2016-10-20 16:24:48 +00:00
|
|
|
# importing whole testapi creates circular dependency, so import only
|
2016-02-10 08:42:56 +00:00
|
|
|
# necessary functions from testapi
|
2021-12-23 12:08:13 +00:00
|
|
|
use testapi qw(check_var get_var send_key type_string assert_screen check_screen assert_script_run validate_script_output enter_cmd type_password);
|
|
|
|
use utils qw(console_login desktop_vt menu_launch_type);
|
2015-03-18 21:28:03 +00:00
|
|
|
|
2022-05-24 23:52:13 +00:00
|
|
|
# Class constructor
|
|
|
|
sub new {
|
|
|
|
my ($class) = @_;
|
|
|
|
my $self = $class->SUPER::new(@_);
|
|
|
|
|
|
|
|
# script_run requires this to be set distri-wide or specified on
|
|
|
|
# each invocation, it tells os-autoinst what to do if a script_run
|
|
|
|
# times out (rather than succeeding or failing)
|
|
|
|
$self->{script_run_die_on_timeout} = 1;
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:28:03 +00:00
|
|
|
sub init() {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->SUPER::init();
|
2019-11-20 16:39:28 +00:00
|
|
|
# Initialize the first virtio serial console as "virtio-console"
|
2019-11-06 12:55:27 +00:00
|
|
|
if (check_var('BACKEND', 'qemu')) {
|
2019-11-20 17:15:20 +00:00
|
|
|
$self->add_console('virtio-console', 'virtio_terminal', {});
|
2023-05-02 00:07:06 +00:00
|
|
|
$self->add_console('user-virtio-console', 'virtio_terminal', {socked_path => cwd() . '/virtio_console_user'});
|
2019-11-06 12:55:27 +00:00
|
|
|
for (my $num = 1; $num < get_var('VIRTIO_CONSOLE_NUM', 1); $num++) {
|
2019-11-20 16:39:28 +00:00
|
|
|
# initialize second virtio serial console as
|
|
|
|
# "virtio-console1", third as "virtio-console2" etc.
|
2019-11-20 17:15:20 +00:00
|
|
|
$self->add_console('virtio-console' . $num, 'virtio_terminal', {socked_path => cwd() . '/virtio_console' . $num});
|
2019-11-06 12:55:27 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-18 21:28:03 +00:00
|
|
|
}
|
|
|
|
|
2021-12-23 12:08:13 +00:00
|
|
|
# This routine should be able to start a graphical application in various DEs
|
|
|
|
# across Fedora, as it uses the Alt-F2 combination that is known to work
|
|
|
|
# similarly everywhere, maybe not in i3 or sway, but we do not test them so often anyway.
|
|
|
|
# If this should change in the future, we would need to enhance this routine.
|
2016-02-10 08:42:56 +00:00
|
|
|
sub x11_start_program {
|
2015-03-18 21:28:03 +00:00
|
|
|
my ($self, $program, $timeout, $options) = @_;
|
|
|
|
send_key "alt-f2";
|
2015-09-17 07:49:55 +00:00
|
|
|
assert_screen "desktop_runner";
|
2016-09-12 17:24:30 +00:00
|
|
|
type_string $program, 20;
|
2022-07-28 20:32:57 +00:00
|
|
|
sleep 5; # because of KDE dialog - SUSE guys are doing the same!
|
2015-03-18 21:28:03 +00:00
|
|
|
send_key "ret", 1;
|
|
|
|
}
|
|
|
|
|
2021-12-23 12:08:13 +00:00
|
|
|
# ensure_installed checks if a package is already installed and if not install it.
|
2022-07-28 20:32:57 +00:00
|
|
|
# To make it happen, it will switch to a virtual terminal (if not already there)
|
|
|
|
# and try to install the package. DNF will skip the installation,
|
2021-12-23 12:08:13 +00:00
|
|
|
# if it is already installed.
|
|
|
|
sub ensure_installed {
|
|
|
|
my ($self, @packages) = @_;
|
|
|
|
# First, let's assume that we are in the virtual console and that we want to stay there
|
|
|
|
# when the routine finishes.
|
|
|
|
my $stay_on_console = 1;
|
|
|
|
# We will check if GUI elements are present, that would suggest that we are not in the
|
|
|
|
# console but in GUI.
|
|
|
|
if (check_screen("apps_menu_button")) {
|
2022-07-28 20:32:57 +00:00
|
|
|
# In that case, we want to return to GUI after the routine finishes.
|
2021-12-23 12:08:13 +00:00
|
|
|
$stay_on_console = 0;
|
2022-07-28 20:32:57 +00:00
|
|
|
# From GUI we need to switch to the console.
|
|
|
|
send_key("ctrl-alt-f3");
|
|
|
|
# Let's wait to allow for screen changes.
|
|
|
|
sleep 5;
|
|
|
|
# And do the login.
|
|
|
|
console_login();
|
2021-12-23 12:08:13 +00:00
|
|
|
}
|
|
|
|
# Try to install the packages via dnf. If it is already installed, DNF will not do anything
|
|
|
|
# so there is no need to do any complicated magic.
|
|
|
|
assert_script_run("dnf install -y @packages", timeout => 240);
|
|
|
|
# If we need to leave the console.
|
|
|
|
if ($stay_on_console == 0) {
|
2022-07-28 20:32:57 +00:00
|
|
|
desktop_vt();
|
2021-12-23 12:08:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 20:32:57 +00:00
|
|
|
# This subroutine switches to the root account.
|
2021-12-23 12:08:13 +00:00
|
|
|
# On Fedora, the system can be installed with a valid root account (root password assigned)
|
|
|
|
# or without it (with root password empty). If no root password is provided through environment
|
2022-07-28 20:32:57 +00:00
|
|
|
# variables, we assume that the system is a "rootless" system. In that case we will use
|
|
|
|
# `sudo -i` to acquire the administrator access.
|
2021-12-23 12:08:13 +00:00
|
|
|
sub become_root {
|
2022-07-28 20:32:57 +00:00
|
|
|
# If ROOT_PASSWORD exists, it means that the root account exists, too.
|
2021-12-23 12:08:13 +00:00
|
|
|
# To become root, we will use the real root account and we'll switch to it.
|
|
|
|
if (check_var("ROOT_PASSWORD")) {
|
2022-07-28 20:32:57 +00:00
|
|
|
my $password = get_var("ROOT_PASSWORD");
|
|
|
|
enter_cmd("su -", max_interval => 15, wait_screen_changes => 3);
|
|
|
|
type_password($password, max_interval => 15);
|
|
|
|
send_key("ret");
|
2021-12-23 12:08:13 +00:00
|
|
|
}
|
|
|
|
# If no root password is set, it means, that we are only using an administrator
|
|
|
|
# who is in the wheel group and therefore we will use the sudo command to obtain
|
|
|
|
# the admin rights.
|
|
|
|
else {
|
|
|
|
my $password = get_var("USER_PASSWORD") || "weakpassword";
|
2022-07-28 20:32:57 +00:00
|
|
|
enter_cmd("sudo -i", max_interval => 15, wait_screen_changes => 3);
|
|
|
|
# The SUDO warning might be displayed so let's wait it out a bit.
|
|
|
|
sleep 2;
|
|
|
|
type_password($password, max_interval => 15);
|
|
|
|
send_key("ret");
|
2021-12-23 12:08:13 +00:00
|
|
|
}
|
|
|
|
sleep 2;
|
|
|
|
# Now we should be root. Let's check for root prompt.
|
|
|
|
assert_screen("root_logged_in");
|
|
|
|
}
|
|
|
|
|
|
|
|
# This routine is adapted from the SuSE distribution file.
|
|
|
|
# There are two differences however. To save a needle,
|
|
|
|
# we actually call the `sudo -k` command instead plain sudo to always
|
|
|
|
# require a password. Then, we do not need to check for
|
|
|
|
# password prompt and and we can provide the password any time.
|
|
|
|
# Also, the routine uses the serial console to check for messages
|
|
|
|
# passed to it after the command has finished to save some time.
|
|
|
|
# The serial console is only accessible for the root user, so that
|
|
|
|
# mechanism does not work when not root (why would anyone use sudo
|
2022-07-28 20:32:57 +00:00
|
|
|
# if they were root already anyway).
|
2021-12-23 12:08:13 +00:00
|
|
|
# To override this, call `make_serial_writable` from `utils.pm` in the
|
|
|
|
# beginning of the test script to enable serial console for normal users.
|
|
|
|
sub script_sudo {
|
|
|
|
my ($self, $prog, $wait) = @_;
|
|
|
|
|
|
|
|
# If $wait is not assigned, let's make it 10 seconds to give some
|
|
|
|
# time to the commands to finish.
|
|
|
|
$wait //= 10;
|
|
|
|
|
|
|
|
my $str;
|
|
|
|
if ($wait > 0) {
|
2022-07-28 20:32:57 +00:00
|
|
|
# Create a uniqe hash from the command and the wait time.
|
|
|
|
$str = testapi::hashed_string("SS$prog$wait");
|
|
|
|
# Chain the commands to pass the message to the serial console.
|
2021-12-23 12:08:13 +00:00
|
|
|
$prog = "$prog; echo $str > /dev/$testapi::serialdev";
|
|
|
|
}
|
|
|
|
# Run the command with `sudo -k`
|
|
|
|
type_string "sudo -k $prog\n";
|
|
|
|
# Put a user password (we might not know the root password anyway)
|
|
|
|
my $password = get_var("USER_PASSWORD") || "weakpassword";
|
|
|
|
type_password($password);
|
|
|
|
send_key "ret";
|
|
|
|
# Wait for the message hash to appear on the serial console which indicates
|
2022-07-28 20:32:57 +00:00
|
|
|
# that the command has finished. No matter what time has passed, finish
|
2021-12-23 12:08:13 +00:00
|
|
|
# or die if no message appears on time.
|
|
|
|
if ($str) {
|
|
|
|
return testapi::wait_serial($str, $wait);
|
|
|
|
}
|
|
|
|
send_key("ret");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run the script with sudo and check the exit code after it has run.
|
|
|
|
# See the script_sudo subroutine for details.
|
|
|
|
sub assert_script_sudo {
|
|
|
|
my ($self, $prog, $wait) = @_;
|
|
|
|
script_sudo($prog, $wait);
|
|
|
|
# Validate that the command exited with a correct exit code.
|
2022-07-28 20:32:57 +00:00
|
|
|
validate_script_output('echo $?', sub { $_ == 0 });
|
2021-12-23 12:08:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:28:03 +00:00
|
|
|
1;
|
|
|
|
# vim: set sw=4 et:
|