1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2024-12-21 01:43:09 +00:00
os-autoinst-distri-fedora/lib/installedtest.pm

162 lines
5.9 KiB
Perl
Raw Normal View History

package installedtest;
use strict;
use base 'basetest';
# base class for tests that run on installed system
# should be used when with tests, where system is already installed, e. g all parts
# of upgrade tests, postinstall phases...
use testapi qw(is_serial_terminal :DEFAULT);
use utils;
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
2015-07-22 18:24:40 +00:00
sub root_console {
# Switch to a default or specified TTY and log in as root.
my $self = shift;
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
2015-07-22 18:24:40 +00:00
my %args = (
tty => 1, # what TTY to login to
timeout => 0, # passed through to console_login
@_
);
if (get_var("SERIAL_CONSOLE")) {
# select the first virtio terminal, for now we assume we can
# always use that (we may have to make this smarter in future)
select_console("virtio-console");
}
else {
# For normal terminal emulation, use key combo to reach a tty
send_key "ctrl-alt-f$args{tty}";
}
console_login(timeout => $args{timeout}); # Do the login.
}
sub post_fail_hook {
my $self = shift;
if (check_screen ['emergency_rescue', 'emergency_rescue_nopassword'], 3) {
if (match_has_tag 'emergency_rescue') {
my $password = get_var("ROOT_PASSWORD", "weakpassword");
type_string "$password";
}
send_key 'ret';
# bring up network so we can upload logs
assert_script_run "dhclient";
}
else {
$self->root_console(tty => 6);
# fix up keyboard layout, if we failed before the test did this
# itself; if it's already been done, should be safe, will just
# fail and carry on
console_loadkeys_us;
}
# if we're in dracut, do things different
my $dracut = 0;
if (check_screen "root_console_dracut", 0) {
$dracut = 1;
script_run "dhclient";
}
# We can't rely on tar being in minimal installs, but we also can't
# rely on dnf always working (it fails in emergency mode, not sure
# why), so try it. if we don't get a return code, process may be
# stuck waiting on network or something, so hit ctrl-c
unless (script_run "dnf -y install tar", 180) {
unless (is_serial_terminal) {
send_key "ctrl-c";
}
}
# if we don't have tar or a network connection, we'll try and at
# least send out *some* kinda info via the serial line
my $hostip = testapi::host_ip();
if ((script_run "rpm -q tar") || (script_run "ping -c 2 ${hostip}")) {
if ($dracut) {
script_run 'printf "\n** RDSOSREPORT **\n" > /dev/' . $serialdev;
script_run "cat /run/initramfs/rdsosreport.txt > /dev/${serialdev}";
return;
}
script_run 'printf "\n** IP ADDR **\n" > /dev/' . $serialdev;
script_run "ip addr > /dev/${serialdev} 2>&1";
script_run 'printf "\n** IP ROUTE **\n" > /dev/' . $serialdev;
script_run "ip route > /dev/${serialdev} 2>&1";
script_run 'printf "\n** NETWORKMANAGER.SERVICE STATUS **\n" > /dev/' . $serialdev;
script_run "systemctl --no-pager -l status NetworkManager.service > /dev/${serialdev} 2>&1";
script_run 'printf "\n** JOURNAL **\n" > /dev/' . $serialdev;
script_run "journalctl --no-pager > /dev/${serialdev}";
return;
}
if ($dracut) {
upload_logs "/run/initramfs/rdsosreport.txt", failok => 1;
# that's all that's really useful, so...
return;
}
# Note: script_run returns the exit code, so the logic looks weird.
# We're testing that the directory exists and contains something.
unless (script_run 'test -n "$(ls -A /var/tmp/abrt)" && cd /var/tmp/abrt && tar czvf tmpabrt.tar.gz *') {
upload_logs "/var/tmp/abrt/tmpabrt.tar.gz";
add a cockpit realmd FreeIPA join test Summary: This requires a few other changes: * turn clone_host_resolv into clone_host_file, letting you clone any given host file (cloning /etc/hosts seems to make both server deployment and client enrolment faster/more reliable) * allow loading of multiple POSTINSTALL tests (so we can share the freeipa_client_postinstall test). Note this is compatible, existing uses will work fine * move initial password change for the IPA test users into the server deployment test (so the client tests don't conflict over doing that) * add GRUB_POSTINSTALL, for specifying boot parameters for boot of the installed system, and make it work by tweaking _console_wait _login (doesn't work for _graphical_wait_login yet, as I didn't need that) * make the static networking config for tap tests into a library function so the tests can share it * handle ABRT problem dirs showing up in /var/spool/abrt as well as /var/tmp/abrt (because the enrol attempt hits #1330766 and the crash report shows up in /var/spool/abrt, don't ask me why the difference, I just work here) * specify the DNS servers from the worker host's resolv.conf as the forwarders for the FreeIPA server when deploying it; if we don't do this, rolekit defaults to using the root servers as forwarders(!) and thus we get the public, not phx2-appropriate, results for e.g. mirrors.fedoraproject.org, some of which the workers can't reach, so PackageKit package install always fails (boy, was it fun figuring THAT mess out) Even after all that, the test still doesn't actually pass, but I'm reasonably confident this is because it's hitting actual bugs, not because it's broken. It runs into #1330766 nearly every time (I think I saw *one* time the enrolment actually succeeded), and seems to run into a subsequent bug I hadn't seen before when trying to work around that by trying the join again (see https://bugzilla.redhat.com/show_bug.cgi?id=1330766#c37 ). Test Plan: Run the test, see what happens. If you're really lucky, it'll actually pass. But you'll probably run into #1330766#c37, I'm mostly posting for comment. You'll need a tap-capable openQA instance to test this. Reviewers: jskladan, garretraziel Reviewed By: garretraziel Subscribers: tflink Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D880
2016-06-07 20:00:39 +00:00
}
unless (script_run 'test -n "$(ls -A /var/spool/abrt)" && cd /var/spool/abrt && tar czvf spoolabrt.tar.gz *') {
upload_logs "/var/spool/abrt/spoolabrt.tar.gz";
}
# upload any core dump files caught by coredumpctl
unless (script_run 'test -n "$(ls -A /var/lib/systemd/coredump)" && cd /var/lib/systemd/coredump && tar czvf coredump.tar.gz *') {
upload_logs "/var/lib/systemd/coredump/coredump.tar.gz";
}
# upload bind log (for FreeIPA server test)
unless (script_run 'test -f /var/named/data/named.run') {
upload_logs "/var/named/data/named.run";
}
# update PostgreSQL initialization log (for database_server test)
unless (script_run 'test -f /var/lib/pgsql/initdb_postgresql.log') {
upload_logs "/var/lib/pgsql/initdb_postgresql.log";
}
# Upload /var/log
add QA:Testcase_FreeIPA_password_change test Summary: again, added as a non-fatal module for realmd_join_cockpit as it's convenient to do it here. Also abstract a couple of ipa bits into a new exporter package in the style of SUSE's mm_network, rather than using ill-fitting class inheritance as we have before - we should probably convert our existing class based stuff to work this way. Also a few minor tweaks and clean-ups of the other tests: The path in console_login() where we detect login of a regular user when we want root or vice versa and log out was actually broken because it would 'wait' for the result of the 'exit' command, which obviously doesn't work (as it relies on running another command afterwards, and we're no longer at a shell). This commit no longer actually uses that path, but I spotted the bug with an earlier version of this which did, and we may as well keep the fix. /var/log/lastlog is an apparently-extremely-large sparse file. A couple of times it seemed to cause tar to run very slowly while creating the /var/log archive for upload on failure. It's no use for diagnosing bugs, so we may as well exclude it from the archive. I caught cockpit webUI login failing one time when testing the test, so threw in a wait_still_screen before starting to type the URL, as we have for the FreeIPA webUI. I also caught a timing issue with the openQA webUI policy add step; the test flips from the Users screen to the HBAC screen then clicks the 'add' button, but there's actually an identical 'add' button on *both* screens, so it could wind up trying to click the one on the Users screen instead, if the web UI took a few milliseconds to switch. So we throw in a needle match to make sure we're actually on the HBAC screen before clicking the button. We make the freeipa_webui test a 'milestone' so that if the new test fails, restoring to the last-known-good milestone doesn't take so long; it actually seems like openQA can get confused and try to cancel the test if restoring the milestone takes a *really* long time, and wind up with a zombie qemu process, which isn't good. This seems to avoid that happening. Test Plan: In the simple case, just run all the FreeIPA-related tests on Fedora 24 (as Rawhide is broken) and make sure they all work properly. To get a bit more advanced you can throw in an `assert_script_run 'false'` in either of the non-fatal tests to break it and make sure things go properly when that happens (the last milestone should be restored - which should be right after freeipa_webui, sitting at tty1 - and run properly; things are set up so each test starts with root logged in on tty1). Reviewers: jskladan, garretraziel Reviewed By: garretraziel Subscribers: tflink Differential Revision: https://phab.qadevel.cloud.fedoraproject.org/D935
2016-08-03 20:21:12 +00:00
# lastlog can mess up tar sometimes and it's not much use
unless (script_run "tar czvf /tmp/var_log.tar.gz --exclude='lastlog' /var/log") {
upload_logs "/tmp/var_log.tar.gz";
}
# Sometimes useful for diagnosing FreeIPA issues
upload_logs "/etc/nsswitch.conf", failok => 1;
if (get_var("FLAVOR") eq "updates-everything-boot-iso") {
# for installer creation test
script_run "df -h";
upload_logs "/root/imgbuild/pylorax.log", failok => 1;
upload_logs "/root/imgbuild/lorax.log", failok => 1;
upload_logs "/root/imgbuild/program.log", failok => 1;
}
if (get_var("TEST") eq "live_build") {
# for live image creation test
script_run "df -h";
script_run 'mock -r openqa --chroot "ls -l /chroot_tmpdir/lmc-logs/anaconda"';
unless (script_run "mock -r openqa --copyout /chroot_tmpdir/lmc-logs/livemedia-out.log .") {
upload_logs "livemedia-out.log";
}
unless (script_run "mock -r openqa --copyout /chroot_tmpdir/lmc-logs/anaconda/ anaconda") {
assert_script_run "tar cvzf anaconda.tar.gz anaconda/";
upload_logs "anaconda.tar.gz";
}
}
}
# For update tests, let's do the update package info log stuff,
# it may be useful for diagnosing the cause of the failure
advisory_get_installed_packages;
advisory_check_nonmatching_packages(fatal => 0);
1;
# vim: set sw=4 et: