Develop a new test for system updates via Cockpit.

* server-cockpit-updates tests that Cockpit can be used to update the system.
* server-cockpit-autoupdate tests that users can use dnf-automatic for system
updates.
* cockpit functions were removed from utils.pm and put into an extra library
for cockpit - cockpit.pm which all cockpit tests are now using.

Review cockpit.pm

Review autoupdate test.

Review the update test.

Fix typo in cockpit.pm

Add sleep.

Add missing command.

Delete an unused needle.
This commit is contained in:
Lukas Ruzicka 2019-09-10 14:59:57 +02:00
parent 0782f4faf2
commit d82f4ecd7f
42 changed files with 468 additions and 28 deletions

53
lib/cockpit.pm Normal file
View File

@ -0,0 +1,53 @@
package cockpit;
use strict;
use base 'Exporter';
use Exporter;
use lockapi;
use testapi;
use utils;
our @EXPORT = qw(start_cockpit select_cockpit_update check_updates);
sub start_cockpit {
# Starting from a console, get to a browser with Cockpit (running
# on localhost) shown. If $login is truth-y, also log in. Assumes
# X and Firefox are installed.
my $login = shift || 0;
# https://bugzilla.redhat.com/show_bug.cgi?id=1439429
assert_script_run "sed -i -e 's,enable_xauth=1,enable_xauth=0,g' /usr/bin/startx";
disable_firefox_studies;
# run firefox directly in X as root. never do this, kids!
type_string "startx /usr/bin/firefox -width 1024 -height 768 http://localhost:9090\n";
assert_screen "cockpit_login", 30;
# this happened on early Modular Server composes...
record_soft_failure "Unbranded Cockpit" if (match_has_tag "cockpit_login_unbranded");
wait_still_screen 5;
if ($login) {
type_safely "root";
wait_screen_change { send_key "tab"; };
type_safely get_var("ROOT_PASSWORD", "weakpassword");
send_key "ret";
assert_screen "cockpit_main";
# wait for any animation or other weirdness
# can't use wait_still_screen because of that damn graph
sleep 3;
}
}
sub select_cockpit_update {
# This method navigates to to the updates screen
assert_and_click "cockpit_software_updates", '', 120;
# wait for the updates to download
assert_screen 'cockpit_updates_check', 300;
}
sub check_updates {
my $logfile = shift;
sleep 2;
my $checkresult = script_run "dnf check-update > $logfile";
upload_logs "$logfile", failok=>1;
return($checkresult);
}

View File

@ -7,7 +7,7 @@ use Exporter;
use lockapi;
use testapi;
our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us do_bootloader boot_decrypt check_release menu_launch_type start_cockpit repo_setup gnome_initial_setup anaconda_create_user check_desktop_clean download_modularity_tests quit_firefox advisory_get_installed_packages advisory_check_nonmatching_packages start_with_launcher quit_with_shortcut lo_dismiss_tip disable_firefox_studies select_rescue_mode copy_devcdrom_as_isofile bypass_1691487 get_release_number check_left_bar check_top_bar check_prerelease check_version spell_version_number _assert_and_click is_branched rec_log click_unwanted_notifications repos_mirrorlist/;
our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us do_bootloader boot_decrypt check_release menu_launch_type repo_setup gnome_initial_setup anaconda_create_user check_desktop_clean download_modularity_tests quit_firefox advisory_get_installed_packages advisory_check_nonmatching_packages start_with_launcher quit_with_shortcut lo_dismiss_tip disable_firefox_studies select_rescue_mode copy_devcdrom_as_isofile bypass_1691487 get_release_number check_left_bar check_top_bar check_prerelease check_version spell_version_number _assert_and_click is_branched rec_log click_unwanted_notifications repos_mirrorlist/;
sub run_with_error_check {
my ($func, $error_screen) = @_;
@ -316,33 +316,6 @@ sub disable_firefox_studies {
assert_script_run 'printf \'{"policies": {"DisableFirefoxStudies": true}}\' > $(rpm --eval %_libdir)/firefox/distribution/policies.json';
}
sub start_cockpit {
# Starting from a console, get to a browser with Cockpit (running
# on localhost) shown. If $login is truth-y, also log in. Assumes
# X and Firefox are installed.
my $login = shift || 0;
# https://bugzilla.redhat.com/show_bug.cgi?id=1439429
assert_script_run "sed -i -e 's,enable_xauth=1,enable_xauth=0,g' /usr/bin/startx";
disable_firefox_studies;
# run firefox directly in X as root. never do this, kids!
type_string "startx /usr/bin/firefox -width 1024 -height 768 http://localhost:9090\n";
assert_screen "cockpit_login", 45;
# this happened on early Modular Server composes...
record_soft_failure "Unbranded Cockpit" if (match_has_tag "cockpit_login_unbranded");
# login screen has a flashing cursor so screen is not still at level 47
wait_still_screen(stilltime=>5, similarity_level=>45);
if ($login) {
type_safely "root";
wait_screen_change { send_key "tab"; };
type_safely get_var("ROOT_PASSWORD", "weakpassword");
send_key "ret";
assert_screen "cockpit_main";
# wait for any animation or other weirdness
# can't use wait_still_screen because of that damn graph
sleep 3;
}
}
sub repos_mirrorlist {
# Use mirrorlist not metalink so we don't hit the timing issue where
# the infra repo is updated but mirrormanager metadata checksums

View File

@ -0,0 +1,15 @@
{
"area": [
{
"xpos": 596,
"ypos": 331,
"width": 71,
"height": 19,
"type": "match"
}
],
"properties": [],
"tags": [
"autoupdate_planned_day"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"xpos": 797,
"ypos": 330,
"width": 50,
"height": 18,
"type": "match"
}
],
"properties": [],
"tags": [
"autoupdate_planned_time"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"width": 62,
"type": "match",
"ypos": 554,
"height": 22,
"xpos": 192
}
],
"properties": [],
"tags": [
"cockpit_software_updates"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"xpos": 844,
"ypos": 362,
"height": 18,
"type": "match",
"width": 71
}
],
"properties": [],
"tags": [
"cockpit_updates_all_install"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"height": 34,
"type": "match",
"ypos": 190,
"width": 48,
"xpos": 468
}
],
"properties": [],
"tags": [
"cockpit_updates_auto"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"type": "match",
"width": 48,
"xpos": 613,
"ypos": 268,
"height": 27
}
],
"properties": [],
"tags": [
"cockpit_updates_auto_on"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -0,0 +1,15 @@
{
"properties": [],
"tags": [
"cockpit_updates_available"
],
"area": [
{
"xpos": 264,
"ypos": 259,
"width": 185,
"height": 28,
"type": "match"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"xpos": 835,
"ypos": 191,
"height": 22,
"type": "match",
"width": 142
}
],
"properties": [],
"tags": [
"cockpit_updates_check"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"xpos": 304,
"ypos": 309,
"width": 143,
"height": 17,
"type": "match"
}
],
"properties": [],
"tags": [
"cockpit_updates_console_update"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"xpos": 909,
"height": 17,
"ypos": 554,
"type": "match",
"width": 43
}
],
"properties": [],
"tags": [
"cockpit_updates_dnf_install"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"ypos": 554,
"height": 17,
"xpos": 909,
"width": 43,
"type": "match"
}
],
"properties": [],
"tags": [
"cockpit_updates_dnf_install"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"ypos": 450,
"height": 21,
"xpos": 635,
"width": 94,
"type": "match"
}
],
"properties": [],
"tags": [
"cockpit_updates_reconnect"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -0,0 +1,15 @@
{
"properties": [],
"tags": [
"cockpit_updates_restart_confirm"
],
"area": [
{
"xpos": 576,
"ypos": 260,
"width": 46,
"height": 15,
"type": "match"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"ypos": 376,
"height": 19,
"xpos": 543,
"type": "match",
"width": 51
}
],
"properties": [],
"tags": [
"cockpit_updates_restart_ignore"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -0,0 +1,15 @@
{
"properties": [],
"tags": [
"cockpit_updates_restart_ignore"
],
"area": [
{
"xpos": 519,
"ypos": 260,
"width": 43,
"height": 16,
"type": "match"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,15 @@
{
"properties": [],
"tags": [
"cockpit_updates_security_install"
],
"area": [
{
"xpos": 619,
"ypos": 267,
"width": 93,
"height": 16,
"type": "match"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -0,0 +1,15 @@
{
"area": [
{
"width": 75,
"type": "match",
"ypos": 329,
"height": 60,
"xpos": 637
}
],
"properties": [],
"tags": [
"cockpit_updates_updated"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -843,6 +843,17 @@
},
test_suite => { name => "server_cockpit_basic" },
},
{
machine => { name => "64bit" },
prio => 30,
product => {
arch => "x86_64",
distri => "fedora",
flavor => "Server-dvd-iso",
version => "*",
},
test_suite => { name => "server_cockpit_updates" },
},
{
machine => { name => "64bit" },
prio => 30,
@ -5281,6 +5292,20 @@
{ key => "+HDD_1", value => "disk_%MACHINE%_cockpit.qcow2" },
],
},
{
name => "server_cockpit_updates",
settings => [
{ key => "POSTINSTALL", value => "server_cockpit_updates server_cockpit_autoupdate" },
{ key => "USER_LOGIN", value => "false" },
{ key => "ROOT_PASSWORD", value => "weakpassword" },
# to understand the '+' values in this test and the next,
# see the `jobs_from_update` docstring in fedora_openqa
# schedule.py
{ key => "+START_AFTER_TEST", value => "server_cockpit_default" },
{ key => "BOOTFROM", value => "c" },
{ key => "+HDD_1", value => "disk_%MACHINE%_cockpit.qcow2" },
],
},
{
name => "realmd_join_cockpit",
settings => [

View File

@ -4,6 +4,7 @@ use testapi;
use lockapi;
use utils;
use tapnet;
use cockpit;
sub run {
my $self = shift;

View File

@ -0,0 +1,44 @@
use base "installedtest";
use strict;
use testapi;
use utils;
use packagetest;
use cockpit;
sub run {
my $self=shift;
bypass_1691487;
# Start Cockpit
start_cockpit(1);
# Navigate to the Update screen
select_cockpit_update();
# Switch on automatic updates
assert_and_click 'cockpit_updates_auto', '', 120;
assert_and_click 'cockpit_updates_dnf_install', '', 120;
assert_screen 'cockpit_updates_auto_on';
# Check the default automatic settings Everyday at 6 o'clock.
assert_screen 'autoupdate_planned_day';
assert_screen 'autoupdate_planned_time';
# Quit Cockpit
send_key "ctrl-q";
sleep 3;
# Check that the dnf-automatic service has started
assert_script_run "systemctl is-active dnf-automatic-install.timer";
# Check that it is scheduled correctly
validate_script_output "systemctl show dnf-automatic-install.timer | grep TimersCalendar", sub {$_ =~ "06:00:00" };
}
sub test_flags {
return { always_rolllback => 1 };
}
1;
# vim: set sw=4 et:

View File

@ -2,6 +2,7 @@ use base "installedtest";
use strict;
use testapi;
use utils;
use cockpit;
sub run {
my $self=shift;

View File

@ -2,6 +2,7 @@ use base "installedtest";
use strict;
use testapi;
use utils;
use cockpit;
sub run {
my $self = shift;

View File

@ -0,0 +1,87 @@
use base "installedtest";
use strict;
use testapi;
use utils;
use packagetest;
use cockpit;
sub run {
my $self=shift;
bypass_1691487;
my $cockdate = "0";
# Remove a package, disable repositories and enable test repositories, install the package
# from that repository to make the system outdated and verify that that package was
# correctly installed.
prepare_test_packages;
verify_installed_packages;
# Start Cockpit
start_cockpit(1);
# Navigate to update screen
select_cockpit_update();
# If security updates are available, install them first,
# so that we test the most buttons in one go.
# After updates, ignore restart because we do not need
# restarting the machine to continue. Also, we would have
# to deal with much more complicated workflow.
#
if (check_screen('cockpit_updates_security_install',1)) {
assert_and_click 'cockpit_updates_security_install';
sleep 60; # wait until things are installed
assert_and_click 'cockpit_updates_restart_ignore';
wait_still_screen 2;
}
# Install the rest of the updates, or any updates
# that have not been previously installed.
assert_and_click 'cockpit_updates_all_install';
my $run = 0;
while ($run < 40) {
# When Cockpit packages are also included in the updates
# the user is forced to reconnect, i.e. to restart the Web Application
# and relog for further interaction. We will check if reconnection is
# needed and if so, we will restart Firefox and login again.
#
if (check_screen("cockpit_updates_reconnect", 1)) {
send_key "ctrl-q";
sleep 5;
start_cockpit(1);
select_cockpit_update();
$run = 50;
}
# Ignore rebooting the system because we want to finish the test instead.
elsif (check_screen('cockpit_updates_restart_ignore', 1)) {
assert_and_click 'cockpit_updates_restart_ignore';
$run = 50;
}
else {
sleep 10;
$run = $run + 1;
}
}
# Check that the system is updated
assert_screen 'cockpit_updates_updated';
# Switch off Cockpit
send_key "ctrl-q";
# Wait a couple of seconds for the terminal to settle down, the command was
# entered incorrectly which resulted in a failure.
sleep 5;
# Verify that the test package was updated correctly.
verify_updated_packages;
}
sub test_flags {
return { always_rollback => 1 };
}
1;
# vim: set sw=4 et: