diff --git a/lib/anacondalog.pm b/lib/anacondalog.pm index 2d8035b3..917fdcf1 100644 --- a/lib/anacondalog.pm +++ b/lib/anacondalog.pm @@ -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: diff --git a/lib/fedorabase.pm b/lib/fedorabase.pm new file mode 100644 index 00000000..388ad493 --- /dev/null +++ b/lib/fedorabase.pm @@ -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: diff --git a/lib/fedoralog.pm b/lib/fedoralog.pm index 0fa9701c..25d3db96 100644 --- a/lib/fedoralog.pm +++ b/lib/fedoralog.pm @@ -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 *"; diff --git a/needles/anaconda_console.json b/needles/anaconda_console.json deleted file mode 100644 index 8a438470..00000000 --- a/needles/anaconda_console.json +++ /dev/null @@ -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" - } - ] -} \ No newline at end of file diff --git a/needles/anaconda_console.png b/needles/anaconda_console.png deleted file mode 100644 index b31f7fc7..00000000 Binary files a/needles/anaconda_console.png and /dev/null differ diff --git a/needles/root_logged_in.json b/needles/root_logged_in.json index ba1e828b..bc0b9a7d 100644 --- a/needles/root_logged_in.json +++ b/needles/root_logged_in.json @@ -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" + ] } \ No newline at end of file diff --git a/needles/root_logged_in2.json b/needles/root_logged_in2.json deleted file mode 100644 index 2e7c2ac8..00000000 --- a/needles/root_logged_in2.json +++ /dev/null @@ -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": [] -} \ No newline at end of file diff --git a/needles/root_logged_in2.png b/needles/root_logged_in2.png deleted file mode 100644 index c6173d4e..00000000 Binary files a/needles/root_logged_in2.png and /dev/null differ diff --git a/needles/root_logged_in_rawhide20150311.json b/needles/root_logged_in_rawhide20150311.json index b202d6a0..8c09feb6 100644 --- a/needles/root_logged_in_rawhide20150311.json +++ b/needles/root_logged_in_rawhide20150311.json @@ -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" + ] +} diff --git a/needles/user_logged_in.json b/needles/user_logged_in.json index a598a586..40933378 100644 --- a/needles/user_logged_in.json +++ b/needles/user_logged_in.json @@ -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" - } - ] -} \ No newline at end of file +{ + "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" + ] +} diff --git a/needles/user_logged_in_20150721f23.json b/needles/user_logged_in_20150721f23.json new file mode 100644 index 00000000..40933378 --- /dev/null +++ b/needles/user_logged_in_20150721f23.json @@ -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" + ] +} diff --git a/needles/user_logged_in_20150721f23.png b/needles/user_logged_in_20150721f23.png new file mode 100644 index 00000000..f029ef5b Binary files /dev/null and b/needles/user_logged_in_20150721f23.png differ diff --git a/tests/_console_wait_login.pm b/tests/_console_wait_login.pm index 22c13b74..1bd7f08f 100644 --- a/tests/_console_wait_login.pm +++ b/tests/_console_wait_login.pm @@ -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 { diff --git a/tests/disk_guided_delete_partial_postinstall.pm b/tests/disk_guided_delete_partial_postinstall.pm index 5e0f9867..076b7018 100644 --- a/tests/disk_guided_delete_partial_postinstall.pm +++ b/tests/disk_guided_delete_partial_postinstall.pm @@ -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"; diff --git a/tests/disk_guided_free_space_postinstall.pm b/tests/disk_guided_free_space_postinstall.pm index fc7cbf5f..b04be03f 100644 --- a/tests/disk_guided_free_space_postinstall.pm +++ b/tests/disk_guided_free_space_postinstall.pm @@ -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"; diff --git a/tests/disk_guided_multi_empty_all_postinstall.pm b/tests/disk_guided_multi_empty_all_postinstall.pm index 252a07a9..0c1473bf 100644 --- a/tests/disk_guided_multi_empty_all_postinstall.pm +++ b/tests/disk_guided_multi_empty_all_postinstall.pm @@ -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"; diff --git a/tests/disk_guided_multi_postinstall.pm b/tests/disk_guided_multi_postinstall.pm index e034428b..3da0b1b6 100644 --- a/tests/disk_guided_multi_postinstall.pm +++ b/tests/disk_guided_multi_postinstall.pm @@ -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"; diff --git a/tests/disk_part_software_raid_postinstall.pm b/tests/disk_part_software_raid_postinstall.pm index eb1b9712..c572f01f 100644 --- a/tests/disk_part_software_raid_postinstall.pm +++ b/tests/disk_part_software_raid_postinstall.pm @@ -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"; diff --git a/tests/install_source_graphical.pm b/tests/install_source_graphical.pm index a06e3b34..d13b353c 100644 --- a/tests/install_source_graphical.pm +++ b/tests/install_source_graphical.pm @@ -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"; diff --git a/tests/install_source_variation.pm b/tests/install_source_variation.pm index d833bdc3..2f7c06d9 100644 --- a/tests/install_source_variation.pm +++ b/tests/install_source_variation.pm @@ -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"; diff --git a/tests/upgrade_postinstall_minimal.pm b/tests/upgrade_postinstall_minimal.pm index bd86aa3d..86fc1abd 100644 --- a/tests/upgrade_postinstall_minimal.pm +++ b/tests/upgrade_postinstall_minimal.pm @@ -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"; } diff --git a/tests/upgrade_preinstall.pm b/tests/upgrade_preinstall.pm index 72a1a5c4..f5b4883b 100644 --- a/tests/upgrade_preinstall.pm +++ b/tests/upgrade_preinstall.pm @@ -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";