From 7b588baa638b64ddf1398bb3aa7746125a836840 Mon Sep 17 00:00:00 2001 From: Sofia Syrianidou Date: Tue, 7 Apr 2020 12:54:26 +0200 Subject: [PATCH] Add autoyast test for yast2-ntp-client systemd timers --- .../autoyast_systemd_timesync.xml | 90 +++++++++++++++++++ lib/autoyast.pm | 2 +- schedule/yast/autoyast_systemd_timesync.yaml | 29 ++++++ tests/console/verify_systemd_timesync.pm | 59 ++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 data/autoyast_sle15/autoyast_systemd_timesync.xml create mode 100644 schedule/yast/autoyast_systemd_timesync.yaml create mode 100644 tests/console/verify_systemd_timesync.pm diff --git a/data/autoyast_sle15/autoyast_systemd_timesync.xml b/data/autoyast_sle15/autoyast_systemd_timesync.xml new file mode 100644 index 000000000000..aad0a81a5028 --- /dev/null +++ b/data/autoyast_sle15/autoyast_systemd_timesync.xml @@ -0,0 +1,90 @@ + + + + + + true + + {{SCC_REGCODE}} + true + {{SCC_URL}} + + + sle-module-basesystem + {{VERSION}} + {{ARCH}} + + + + + + false + + + + + -1 + + + + true + + + auto + + +
{{NTP_SERVER_ADDRESS}}
+ true + false +
+
+ 1 +
+ + + base + basesystem + enhanced_base + yast2_basis + + + SLES + + + + + Bernhard M. Wiedemann + false + nots3cr3t + bernhard + + + false + nots3cr3t + root + + + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + +
+ diff --git a/lib/autoyast.pm b/lib/autoyast.pm index 35c30f89e815..74062a0ead3e 100644 --- a/lib/autoyast.pm +++ b/lib/autoyast.pm @@ -436,7 +436,7 @@ sub adjust_network_conf { sub expand_variables { my ($profile) = @_; # Expand other variables - my @vars = qw(SCC_REGCODE SCC_REGCODE_HA SCC_REGCODE_GEO SCC_REGCODE_HPC SCC_URL ARCH LOADER_TYPE); + my @vars = qw(SCC_REGCODE SCC_REGCODE_HA SCC_REGCODE_GEO SCC_REGCODE_HPC SCC_URL ARCH LOADER_TYPE NTP_SERVER_ADDRESS); # Push more variables to expand from the job setting my @extra_vars = push @vars, split(/,/, get_var('AY_EXPAND_VARS', '')); diff --git a/schedule/yast/autoyast_systemd_timesync.yaml b/schedule/yast/autoyast_systemd_timesync.yaml new file mode 100644 index 000000000000..31d9c870cb98 --- /dev/null +++ b/schedule/yast/autoyast_systemd_timesync.yaml @@ -0,0 +1,29 @@ +name: autoyast_systemd_timesync +description: > + Test performs autoyast installation where profile dictates that ntp is configured for one time synchronization. + Following, checks for the use of systemd timesync instead of cron, validates configuration and functionality. +vars: + AUTOYAST: autoyast_sle15/autoyast_systemd_timesync.xml + AUTOYAST_PREPARE_PROFILE: 1 + NTP_SERVER_ADDRESS: cz.pool.ntp.org +schedule: + - autoyast/prepare_profile + - installation/isosize + - installation/bootloader_start + - autoyast/installation + - autoyast/console + - autoyast/login + - autoyast/clone + - autoyast/verify_cloned_profile + - autoyast/logs + - autoyast/autoyast_reboot + - installation/grub_test + - installation/first_boot + - console/verify_systemd_timesync +test_data: + profile: + ntp-client: + ntp_servers: + ntp_server: + address: cz.pool.ntp.org + ntp_sync: 1 diff --git a/tests/console/verify_systemd_timesync.pm b/tests/console/verify_systemd_timesync.pm new file mode 100644 index 000000000000..34e9f35633f9 --- /dev/null +++ b/tests/console/verify_systemd_timesync.pm @@ -0,0 +1,59 @@ +# SUSE's openQA tests +# +# Copyright © 2020 SUSE LLC +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# Summary: Verify that systemd timer is used for time synchronization. +# - Check if yast-timer configuration file exists and contains expected values. +# - Check configured time synchronization server address. +# - Check the message logs for "One time synchronization" occurrence. +# Maintainer: Sofia Syrianidou + +use strict; +use warnings; +use base 'y2_installbase'; +use testapi; +use scheduler 'get_test_suite_data'; +use Test::Assert ':all'; + +sub run { + my $test_data = get_test_suite_data(); + select_console 'root-console'; + + record_info("Check configuration", "Check if file /etc/systemd/system/yast-timesync.timer exists and has expected configuration."); + assert_script_run('ls /etc/systemd/system/yast-timesync.timer'); + my $conf_file = script_output("cat /etc/systemd/system/yast-timesync.timer"); + $conf_file =~ /OnUnitActiveSec=(?\S+)min/; + my $expected_interval = $test_data->{profile}->{'ntp-client'}->{ntp_sync}; + assert_equals($expected_interval, $+{interval}, "The interval in yast-timesync configuration file is not the expected one."); + + record_info("Check server", "Check if the configured time synchronization server is the expected one."); + my $expected_server = $test_data->{profile}->{'ntp-client'}->{ntp_servers}->{ntp_server}->{address}; + my $chrony_conf = script_output("cat /etc/chrony.conf"); + $chrony_conf =~ /(\R|^)pool\s(?\S+)/; + assert_equals($expected_server, $+{server}); + + record_info("Check sync", "Check if the use of systemd timers can be spotted in the journal logs as expected."); + # The first "One time synchronization" is not happening immediately after boot. In order to make sure that first sync + # has already happened before checking the logs, the following loop will check the logs repeatedly until logs are found + # or uptime minutes are more that OnBootSec+1 ( +1 due to timers inaccuracy ). + $conf_file =~ /OnBootSec=(?\S+)min/; + my $uptime; + my $not_synced = 1; + { + do { + $not_synced = script_run("journalctl -u yast-timesync | grep \"Started One time sync configured by YaST\""); + last unless ($not_synced); + $uptime = script_output("uptime | cut -c19,20"); + script_run("echo \"Waiting 10 seconds before rechecking logs for One time synchronization\""); + sleep 10; + } while ($uptime <= ($+{onbootsec} + 1)); + } + die "One time synchronization was not spotted in the journal logs as expected" if $not_synced; +} + +1;