create fedora base class, factor out console login

Summary:
Root console in anaconda got broken by RHBZ #1222413 - no
shell on tty2. Decided to clean up console use in general as
part of fixing it.

This creates a class 'fedorabase' and has 'anacondalog' and
'fedoralog' both inherit from it. boot_to_login_screen is
moved there (as it seems appropriate) and it has a new
method, console_login, which basically handles 'get me a
shell on a console': if we're already at one it returns,
if not it'll type the user name and the password *if
necessary* (sometimes it's not) and return once it sees a
prompt. It takes a hash of named parameters for user,
password and 'check', which is whether it should die if it
fails to reach a console or not (some users don't want it
to).

anacondalog and fedoralog both get 'root_console' methods
which do something appropriate and then call
console_login; both have a hash of named parameters,
anacondalog's version only bothers with 'check', while
fedoralog's also accepts 'tty' to pick the tty to use.

This also adjusts all things which try to get to a console
prompt to use either root_console or console_login as
appropriate.

It also tweaks the needle tags a bit, drops some unneeded
needles, and adds a new 'user console prompt' needle; we
really just need two versions of the root prompt needle
and two of the user prompt needle (one for <F23, one for
F23+ - the console font changed in F23, and the @ character
at least doesn't match between the two). I think we still
need the <F23 case for upgrade tests, for now.

Test Plan:
Do a full test run and see that more tests
succeed. I've done a run on happyassassin with a hack to
workaround the SELinux issue for interactive installs,
and the results look good. I also fiddled about a bit to
test some different cases, like forcing a failure in a
live test to test post_fail_hook (and hence root_console)
in that scenario, and forcing failures after some console
commands had been run to check that it DTRT when we've
already reached a console, etc.

Reviewers: jskladan, garretraziel

Reviewed By: jskladan, garretraziel

Subscribers: tflink

Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D462
This commit is contained in:
Adam Williamson 2015-07-22 11:24:40 -07:00
parent 2e4c1c2325
commit 4b8e411479
22 changed files with 228 additions and 182 deletions

View File

@ -1,5 +1,5 @@
package anacondalog;
use base 'basetest';
use base 'fedorabase';
use testapi;
@ -12,21 +12,8 @@ sub post_fail_hook {
$has_traceback = 1;
}
send_key "ctrl-alt-f2";
my $logged_in = 0;
if (get_var("LIVE") && check_screen "text_console_login", 20) {
# On live installs, we need to log in
type_string "root";
send_key "ret";
if (check_screen "root_logged_in", 10) {
$logged_in = 1;
}
}
elsif (check_screen "anaconda_console", 10) {
$logged_in = 1;
}
if ($logged_in == 1) {
$self->root_console(check=>0);
if (check_screen "root_console", 10) {
upload_logs "/tmp/X.log";
upload_logs "/tmp/anaconda.log";
upload_logs "/tmp/packaging.log";
@ -52,6 +39,24 @@ sub post_fail_hook {
}
}
sub root_console {
my $self = shift;
my %args = (
check => 1,
@_);
if (get_var("LIVE")) {
send_key "ctrl-alt-f2";
}
else {
# Working around RHBZ 1222413, no console on tty2
send_key "ctrl-alt-f1";
send_key "ctrl-b";
send_key "2";
}
$self->console_login(user=>"root",check=>$args{check});
}
1;
# vim: set sw=4 et:

79
lib/fedorabase.pm Normal file
View File

@ -0,0 +1,79 @@
package fedorabase;
use base 'basetest';
use testapi;
sub console_login {
my $self = shift;
my %args = (
user => "root",
password => get_var("ROOT_PASSWORD", "weakpassword"),
check => 1,
@_);
my $good = "";
my $bad = "";
my $needuser = 1;
my $needpass = 1;
if ($args{user} eq "root") {
$good = "root_console";
$bad = "user_console";
}
else {
$good = "user_console";
$bad = "root_console";
}
for my $n (1 .. 10) {
# This little loop should handle all possibilities quite
# efficiently: already at a prompt (previously logged in, or
# anaconda case), only need to enter username (live case),
# need to enter both username and password (installed system
# case). There are some annoying cases here involving delays
# to various commands and the limitations of needles;
# text_console_login also matches when the password prompt
# is displayed (as the login prompt is still visible), and
# both still match after login is complete, unless something
# runs 'clear'. The sleeps and $needuser / $needpass attempt
# to mitigate these problems.
if (check_screen $good, 0) {
return;
}
elsif (check_screen $bad, 0) {
type_string "exit\n";
sleep 2;
}
if ($needuser and check_screen "text_console_login", 0) {
type_string "$args{user}\n";
$needuser = 0;
sleep 2;
}
elsif ($needpass and check_screen "console_password_required", 0) {
type_string "$args{password}\n";
$needpass = 0;
# Sometimes login takes a bit of time, so add an extra sleep
sleep 2;
}
sleep 1;
}
# If we got here we failed; if 'check' is set, die.
$args{check} && die "Failed to reach console!"
}
sub boot_to_login_screen {
my $self = shift;
my $boot_done_screen = shift;
my $stillscreen = shift || 10;
my $timeout = shift || 60;
wait_still_screen $stillscreen, $timeout;
if ($boot_done_screen ne "") {
assert_screen $boot_done_screen;
}
}
1;
# vim: set sw=4 et:

View File

@ -1,42 +1,23 @@
package fedoralog;
use base 'basetest';
use base 'fedorabase';
use testapi;
sub login_as_root {
sub root_console {
my $self = shift;
my $tty = shift || 1;
my $password = get_var("ROOT_PASSWORD", "weakpassword");
my %args = (
tty => 1,
check => 1,
@_);
send_key "ctrl-alt-f$tty";
assert_screen "text_console_login", 20;
type_string "root";
send_key "ret";
assert_screen "console_password_required", 10;
type_string $password;
send_key "ret";
assert_screen "root_logged_in", 10;
}
sub boot_to_login_screen {
my $self = shift;
my $boot_done_screen = shift;
my $stillscreen = shift || 10;
my $timeout = shift || 60;
wait_still_screen $stillscreen, $timeout;
if ($boot_done_screen ne "") {
assert_screen $boot_done_screen;
}
send_key "ctrl-alt-f$args{tty}";
$self->console_login(check=>$args{check});
}
sub post_fail_hook {
my $self = shift;
$self->login_as_root(2);
$self->root_console(tty=>2);
# Upload all ABRT logs
type_string "cd /var/tmp/abrt && tar czvf abrt.tar.gz *";

View File

@ -1,25 +0,0 @@
{
"tags": [
"anaconda_console",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-OFW-1",
"ENV-FLAVOR-server"
],
"area": [
{
"xpos": 0,
"ypos": 0,
"width": 121,
"height": 54,
"type": "match"
},
{
"xpos": 194,
"ypos": 0,
"width": 35,
"height": 27,
"type": "match"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 B

View File

@ -1,18 +1,26 @@
{
"properties": [],
"area": [
{
"width": 156,
"xpos": 0,
"height": 19,
"ypos": 113,
"type": "match"
}
],
"tags": [
"root_logged_in",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
]
{
"area": [
{
"height": 17,
"type": "match",
"width": 40,
"xpos": 7,
"ypos": 111
},
{
"height": 14,
"type": "match",
"width": 17,
"xpos": 137,
"ypos": 112
}
],
"properties": [],
"tags": [
"root_logged_in",
"root_console",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
]
}

View File

@ -1,18 +0,0 @@
{
"area": [
{
"xpos": 0,
"ypos": 110,
"type": "match",
"height": 22,
"width": 156
}
],
"tags": [
"root_logged_in",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
],
"properties": []
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,17 +1,25 @@
{
"tags": [
"root_logged_in",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
],
"area": [
{
"xpos": 0,
"ypos": 80,
"width": 152,
"height": 14,
"type": "match"
}
]
}
{
"area": [
{
"height": 14,
"type": "match",
"width": 41,
"xpos": 7,
"ypos": 80
},
{
"height": 14,
"type": "match",
"width": 16,
"xpos": 136,
"ypos": 80
}
],
"tags": [
"root_logged_in",
"root_console",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
]
}

View File

@ -1,17 +1,25 @@
{
"tags": [
"user_logged_in",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
],
"area": [
{
"xpos": 1,
"ypos": 94,
"width": 155,
"height": 20,
"type": "match"
}
]
}
{
"area": [
{
"height": 14,
"type": "match",
"width": 41,
"xpos": 7,
"ypos": 95
},
{
"height": 17,
"type": "match",
"width": 17,
"xpos": 136,
"ypos": 93
}
],
"tags": [
"user_logged_in",
"user_console",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
]
}

View File

@ -0,0 +1,25 @@
{
"area": [
{
"height": 14,
"type": "match",
"width": 41,
"xpos": 7,
"ypos": 95
},
{
"height": 17,
"type": "match",
"width": 17,
"xpos": 136,
"ypos": 93
}
],
"tags": [
"user_logged_in",
"user_console",
"ENV-DISTRI-fedora",
"ENV-INSTLANG-en_US",
"ENV-FLAVOR-server"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -1,8 +1,9 @@
use base "basetest";
use base "fedorabase";
use strict;
use testapi;
sub run {
my $self = shift;
# If KICKSTART is set, then the wait_time needs to
# consider the install time
@ -11,37 +12,12 @@ sub run {
# Reboot and wait for the text login
assert_screen "text_console_login", $wait_time;
if ((get_var("USER_LOGIN") && get_var("USER_PASSWORD")) || get_var("ROOT_PASSWORD"))
{
my $user_logged_in = 0;
if (get_var("USER_LOGIN"))
{
type_string get_var("USER_LOGIN");
send_key "ret";
type_string get_var("USER_PASSWORD");
send_key "ret";
assert_screen "user_logged_in", 10;
$user_logged_in = 1;
}
if (get_var("ROOT_PASSWORD"))
{
if ($user_logged_in == 1)
{
type_string "su -";
send_key "ret";
assert_screen "console_password_required", 10;
}
else
{
type_string "root";
send_key "ret";
}
type_string get_var("ROOT_PASSWORD");
send_key "ret";
assert_screen "root_logged_in", 10;
}
if (get_var("USER_LOGIN") && get_var("USER_PASSWORD")) {
$self->console_login(user=>get_var("USER_LOGIN"), password=>get_var("USER_PASSWORD"));
}
if (get_var("ROOT_PASSWORD")) {
$self->console_login(user=>"root", password=>get_var("ROOT_PASSWORD"));
}
}
sub test_flags {

View File

@ -3,7 +3,7 @@ use strict;
use testapi;
sub run {
assert_screen "root_logged_in";
assert_screen "root_console";
type_string 'reset; mount /dev/vda2 /mnt; echo $?'; # if you use doublequotes, $? gets replaced by Perl with last error code
send_key "ret";
assert_screen "console_command_success";

View File

@ -3,7 +3,7 @@ use strict;
use testapi;
sub run {
assert_screen "root_logged_in";
assert_screen "root_console";
type_string 'reset; mount /dev/vda1 /mnt; echo $?'; # if you use doublequotes, $? gets replaced by Perl with last error code
send_key "ret";
assert_screen "console_command_success";

View File

@ -3,7 +3,7 @@ use strict;
use testapi;
sub run {
assert_screen "root_logged_in";
assert_screen "root_console";
# when two disks are selected in installation, LVM is used
type_string "reset; pvdisplay";

View File

@ -3,7 +3,7 @@ use strict;
use testapi;
sub run {
assert_screen "root_logged_in";
assert_screen "root_console";
type_string 'reset; mount /dev/sdb1 /mnt; echo $?'; # if you use doublequotes, $? gets replaced by Perl with last error code
send_key "ret";
assert_screen "console_command_success";

View File

@ -3,7 +3,7 @@ use strict;
use testapi;
sub run {
assert_screen "root_logged_in";
assert_screen "root_console";
type_string "reset; cat /proc/mdstat";
send_key "ret";
assert_screen "console_raid_used";

View File

@ -3,6 +3,7 @@ use strict;
use testapi;
sub run {
my $self = shift;
# Anaconda hub
assert_screen "anaconda_main_hub", 300; #
@ -48,8 +49,7 @@ sub run {
assert_screen "anaconda_main_hub", 300;
# check that the repo was used
send_key "ctrl-alt-f2";
wait_idle 10;
$self->root_console;
type_string "grep \"".$repourl."\" /tmp/packaging.log"; # | grep \"added repo\"";
send_key "ret";
assert_screen "anaconda_install_source_check_repo_added";

View File

@ -4,7 +4,7 @@ use testapi;
sub run {
# !!! GRUB parameter is set in _boot_to_anaconda.pm !!!
my $self = shift;
# Anaconda hub
assert_screen "anaconda_main_hub";
@ -15,8 +15,7 @@ sub run {
$repourl = get_var("REPOSITORY_VARIATION")."/".$fedora_version."/".get_var("ARCH")."/os";
# check that the repo was used
send_key "ctrl-alt-f2";
wait_idle 10;
$self->root_console;
type_string "grep \"".$repourl."\" /tmp/packaging.log"; #| grep \"added repo\"";
send_key "ret";
assert_screen "anaconda_install_source_check_repo_added";

View File

@ -7,7 +7,7 @@ sub run {
my $self = shift;
$self->boot_to_login_screen();
$self->login_as_root(3);
$self->root_console(tty=>3);
assert_screen "console_f22_installed";
}

View File

@ -11,7 +11,7 @@ sub run {
} else {
$self->boot_to_login_screen();
}
$self->login_as_root(3);
$self->root_console(tty=>3);
type_string 'yum -y update; echo $?';
send_key "ret";
@ -27,7 +27,7 @@ sub run {
} else {
$self->boot_to_login_screen();
}
$self->login_as_root(3);
$self->root_console(tty=>3);
type_string 'yum -y install fedup; echo $?';
send_key "ret";