From 4b8e411479709f4ab429f183db3a6a239b430b4d Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Wed, 22 Jul 2015 11:24:40 -0700 Subject: [PATCH] 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 0 bytes needles/root_logged_in.json | 42 ++++++---- needles/root_logged_in2.json | 18 ---- needles/root_logged_in2.png | Bin 1184 -> 0 bytes needles/root_logged_in_rawhide20150311.json | 42 ++++++---- needles/user_logged_in.json | 42 ++++++---- needles/user_logged_in_20150721f23.json | 25 ++++++ needles/user_logged_in_20150721f23.png | Bin 0 -> 4566 bytes tests/_console_wait_login.pm | 38 ++------- .../disk_guided_delete_partial_postinstall.pm | 2 +- tests/disk_guided_free_space_postinstall.pm | 2 +- ...disk_guided_multi_empty_all_postinstall.pm | 2 +- tests/disk_guided_multi_postinstall.pm | 2 +- tests/disk_part_software_raid_postinstall.pm | 2 +- tests/install_source_graphical.pm | 4 +- tests/install_source_variation.pm | 5 +- tests/upgrade_postinstall_minimal.pm | 2 +- tests/upgrade_preinstall.pm | 4 +- 22 files changed, 228 insertions(+), 182 deletions(-) create mode 100644 lib/fedorabase.pm delete mode 100644 needles/anaconda_console.json delete mode 100644 needles/anaconda_console.png delete mode 100644 needles/root_logged_in2.json delete mode 100644 needles/root_logged_in2.png create mode 100644 needles/user_logged_in_20150721f23.json create mode 100644 needles/user_logged_in_20150721f23.png 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 b31f7fc7a928a7da55f16059eea361a357efe80f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 392 zcmeAS@N?(olHy`uVBq!ia0y~yU;#3j85o&?R6|L-ACO`T@Ck7R(yLaj5>Bpv!@$63 z>*?YcQgQ3;CEdKk1`-X4*$F2S3>LI=tl}z~p|JSTiU-WrQ4<6E0(_khTOZhR_GN!r z)6xa!nctk}tW33B+HM}R?QCVO=k9Iq?oEIB?fL$%({7?>Wn&es5oQ?T&8nsqDKBQ!K6-xob^t zNG@60SNrN3*NoG9Sk7ebVLPLnaDDsgo$d!-N=^7}vhFKel*3-uoc_1GI*g^W`?T*K zFqo>j$S3$$&y6DjhP?8*Uh5Cr6_(rc%L9E%LtxVsUu}^1a#8U#eUL4lu6{1-oD!M< D*xiBN 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 c6173d4e379bc136b079faa8d072d1cbe1fa2435..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1184 zcmeAS@N?(olHy`uVBq!ia0y~yU;#3j85o&?R6|L-ACO`T@Ck7R(yLaj5>Bpv15^^~ z>EaktaqI1^wSA90MA{zmvr4ka37j>ZBId%jZ<6Cu)}^e+rX8HP{_G2d#|qh|D;{bU zI6jG-uwO2-JTR%bPX5Z(tPiI=r``>n1~hix9@qBQ{99E{`d(GY)ZaNJj6-A9I{O(a znprm$G(8Ld->v@pFZ;l{@L&HpR)lfj|HeN?u&9ouTUv7`YZsJt}s-dy?kO%$;mH*(^^AyKFT3&HTQu$nh$ZTF?0S7UR_w zg?}4%u(cc&S!gg*H?VJ^#>QhNHr3Cc`=#gaDZXyBA}dP2-7(H4cZbuvZE=fMuVw!C z%9~?z9F3reioVqAO>${_u=BLxlr}P<pqK?aA zo#cfbgy`COm;=sj3gz2{Hwtk2_(u+Ds$9;qt5)^u~2-Rq*t=hm@1tAN7hFG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TCLPN5O@;vWlg~g~_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";