Skip to content

Commit

Permalink
Add autoyast test for yast2-ntp-client systemd timers
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiasyria committed Apr 8, 2020
1 parent f2c8b93 commit b476169
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
89 changes: 89 additions & 0 deletions data/autoyast_sle15/autoyast_systemd_timesync.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<!-- minimal autoyast profile -->
<suse_register>
<do_registration config:type="boolean">true</do_registration>
<email/>
<reg_code>{{SCC_REGCODE}}</reg_code>
<install_updates config:type="boolean">true</install_updates>
<reg_server>{{SCC_URL}}</reg_server>
<addons config:type="list">
<addon>
<name>sle-module-basesystem</name>
<version>{{VERSION}}</version>
<arch>{{ARCH}}</arch>
</addon>
</addons>
</suse_register>
<general>
<mode>
<confirm config:type="boolean">false</confirm>
</mode>
</general>
<bootloader>
<global>
<timeout config:type="integer">-1</timeout>
</global>
</bootloader>
<networking>
<keep_install_network config:type="boolean">true</keep_install_network>
</networking>
<ntp-client>
<ntp_policy>auto</ntp_policy>
<ntp_servers config:type="list">
<ntp_server>
<address>cz.pool.ntp.org</address>
<iburst config:type="boolean">true</iburst>
<offline config:type="boolean">false</offline>
</ntp_server>
</ntp_servers>
<ntp_sync>3</ntp_sync>
</ntp-client>
<software>
<patterns config:type="list">
<pattern>base</pattern>
<pattern>basesystem</pattern>
<pattern>enhanced_base</pattern>
<pattern>yast2_basis</pattern>
</patterns>
<products config:type="list">
<product>SLES</product>
</products>
</software>
<users config:type="list">
<user>
<fullname>Bernhard M. Wiedemann</fullname>
<encrypted config:type="boolean">false</encrypted>
<user_password>nots3cr3t</user_password>
<username>bernhard</username>
</user>
<user>
<encrypted config:type="boolean">false</encrypted>
<user_password>nots3cr3t</user_password>
<username>root</username>
</user>
</users>
<report>
<errors>
<log config:type="boolean">true</log>
<show config:type="boolean">true</show>
<timeout config:type="integer">0</timeout>
</errors>
<messages>
<log config:type="boolean">true</log>
<show config:type="boolean">true</show>
<timeout config:type="integer">0</timeout>
</messages>
<warnings>
<log config:type="boolean">true</log>
<show config:type="boolean">true</show>
<timeout config:type="integer">0</timeout>
</warnings>
<yesno_messages>
<log config:type="boolean">true</log>
<show config:type="boolean">true</show>
<timeout config:type="integer">0</timeout>
</yesno_messages>
</report>
</profile>
27 changes: 27 additions & 0 deletions schedule/yast/autoyast_systemd_timesync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
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: 3
42 changes: 42 additions & 0 deletions tests/console/verify_systemd_timesync.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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.
# Maintainer: Sofia Syrianidou <ssyrianidou@suse.com>

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 yast-timesync.timer", "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=(?<interval>(\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.");
# Default value for first time sync is 1 minute. Module pauses in order to be able to track the sync in the logs.
sleep 60;
record_info("Check logs for timesync", "Check if the use of systemd timers can be spotted in the journal logs as it's expected.");
assert_script_run('journalctl -u yast-timesync --since "2 minutes ago" | grep "Started One time sync configured by YaST"');
record_info("Check time deviation correction", "Check if \"One time synchronization\" will fix time deviation as expected.");
script_run("date");
assert_script_run('date $(date +%m%d%H%M%Y.%S -d "1 minute ago")');
assert_script_run('journalctl -fu yast-timesync --since now | grep "wrong by"', ($expected_interval * 60));
my $time_deviation = script_output('journalctl -fu yast-timesync | grep -oP "(?<=wrong by\s)[0-9,.,-]+"');
assert_true($time_deviation > 59, "One time sync was expected to fix a time deviation of 1 minute.");
}

1;

0 comments on commit b476169

Please sign in to comment.