Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial tests for Yomi #8163

Merged
merged 8 commits into from Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ tools/tidy
.perltidyrc
*.tdy
.*.swp
*~
24 changes: 24 additions & 0 deletions data/yomi/run_qemu
@@ -0,0 +1,24 @@
#!/bin/bash -ex

# The first parameter is the scenario name
if [ -z "$1" ]; then
echo 'Missing scenario name'
exit 1
fi
scenario="$1"

efi=
if [[ "$scenario" == *-efi ]]; then
efi='-drive if=pflash,format=raw,unit=0,readonly,file=/usr/share/qemu/ovmf-x86_64-code.bin '
efi+='-drive if=pflash,format=raw,unit=1,file=/usr/share/qemu/ovmf-x86_64-vars.bin '
fi

qemu-system-x86_64 \
-nographic \
-enable-kvm \
-m 1024 \
-net nic,model=virtio \
-net user,hostfwd=tcp::10022-:22 \
-cdrom openSUSE-Tumbleweed-Yomi*.iso \
-hda hda.qcow2 \
$efi
1 change: 0 additions & 1 deletion lib/main_common.pm
Expand Up @@ -2927,7 +2927,6 @@ sub load_mm_autofs_tests {
loadtest "network/autofs_client";
}
}

}

1;
15 changes: 15 additions & 0 deletions schedule/yomi/single@yomi.yaml
@@ -0,0 +1,15 @@
name: single@yomi
description: >-
Install openSUSE in a single HD system using Yomi.
vars:
TEST: single
BOOT_HDD_IMAGE: 1
test_data:
from_factory: 1
schedule:
- boot/boot_to_desktop
- yomi/yomi_formula
- yomi/fetch_iso
- yomi/start_qemu
- yomi/yomi_scenario
- yomi/stop_qemu
31 changes: 31 additions & 0 deletions tests/yomi/fetch_iso.pm
@@ -0,0 +1,31 @@
# Yomi's openQA tests
#
# Copyright © 2019 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: Fetch Yomi image from OBS
# Maintainer: Alberto Planas <aplanas@suse.de>

use strict;
use warnings;
use base "consoletest";
use testapi;
use utils;

sub run {
select_console 'root-console';

my $base_url = 'https://download.opensuse.org/repositories/systemsmanagement:/yomi/images/iso/';
my $iso = 'openSUSE-Tumbleweed-Yomi.x86_64-*.iso';
assert_script_run "wget -r -l1 -np -nd '$base_url' -A '$iso'", timeout => 360;
}

sub test_flags {
return {fatal => 1};
}

1;
80 changes: 80 additions & 0 deletions tests/yomi/start_qemu.pm
@@ -0,0 +1,80 @@
# Yomi's openQA tests
#
# Copyright © 2019 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: Install QEMU and launch the inner minion
# Maintainer: Alberto Planas <aplanas@suse.de>

use strict;
use warnings;
use base "consoletest";
use testapi;
use utils;

sub install_qemu {
zypper_call 'in qemu';
zypper_call 'in qemu-x86';
zypper_call 'in qemu-tools';
zypper_call 'in ovmf';
}

sub assert_script_run_qemu {
my ($command) = @_;
assert_script_run "ssh -oStrictHostKeyChecking=no -p 10022 localhost '$command'";
}

sub start_qemu {
my ($scenario) = @_;

assert_script_run 'qemu-img create -f qcow2 hda.qcow2 24G';

assert_script_run 'curl -O ' . autoinst_url . '/data/yomi/run_qemu';
assert_script_run 'chmod a+x run_qemu';
type_string "nohup ./run_qemu $scenario 2>&1 | tee -i /dev/$serialdev &\n";

wait_serial('localhost login:', 360) || die 'login not found, QEMU not launched';

script_run 'reset && clear';
}

sub start_minion {
# Remove all the keys
assert_script_run 'salt-key -yD';

assert_script_run_qemu 'echo "master: 10.0.2.2" > /etc/salt/minion.d/master.conf';
assert_script_run_qemu 'echo minion > /etc/salt/minion_id';
assert_script_run_qemu '> /var/log/salt/minion';
assert_script_run_qemu 'systemctl restart salt-minion.service';

# Give some time for the minion to connect
sleep 20;

# Only list the keys, as will be accepted by autosign
assert_script_run 'salt-key -L';

# Validate the connection to the minion
script_run "salt -l debug minion test.ping";
assert_screen 'yomi-test-ping', 120;
}

sub run {
select_console 'root-console';

# Get the name of the scenario from the test name
my $scenario = get_var('TEST', 'simple');

install_qemu;
start_qemu $scenario;
start_minion;
}

sub test_flags {
return {fatal => 1};
}

1;
26 changes: 26 additions & 0 deletions tests/yomi/stop_qemu.pm
@@ -0,0 +1,26 @@
# Yomi's openQA tests
#
# Copyright © 2019 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: Stop QEMU
# Maintainer: Alberto Planas <aplanas@suse.de>

use strict;
use warnings;
use base "consoletest";
use testapi;
use utils;

sub run {
select_console 'root-console';

script_run 'pkill -9 qemu';
script_run 'rm hda.qcow2';
}

1;
39 changes: 39 additions & 0 deletions tests/yomi/yomi_formula.pm
@@ -0,0 +1,39 @@
# Yomi's openQA tests
#
# Copyright © 2019 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: Install and configure yomi-formula
# Maintainer: Alberto Planas <aplanas@suse.de>

use strict;
use warnings;
use base "consoletest";
use testapi;
use utils;

sub run {
select_console 'root-console';

# Install yomi-formula, and salt-master as a requirement
my $repo = 'https://download.opensuse.org/repositories/systemsmanagement:/yomi/openSUSE_Tumbleweed/systemsmanagement:yomi.repo';
zypper_call "ar -C -G -f '$repo'";
zypper_call '--gpg-auto-import-keys ref';
zypper_call 'in yomi-formula';

# Configure salt-master
assert_script_run 'cp -a /usr/share/yomi/pillar.conf /etc/salt/master.d/';
assert_script_run 'cp -a /usr/share/yomi/autosign.conf /etc/salt/master.d/';
assert_script_run 'echo -e "base:\n \'*\':\n - yomi.installer" > /srv/salt/top.sls';
assert_script_run 'systemctl restart salt-master.service';
}

sub test_flags {
return {fatal => 1};
}

1;
119 changes: 119 additions & 0 deletions tests/yomi/yomi_scenario.pm
@@ -0,0 +1,119 @@
# Yomi's openQA tests
#
# Copyright © 2019 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: Run a scenario passed via the TEST variable
# Maintainer: Alberto Planas <aplanas@suse.de>

use strict;
use warnings;
use base "consoletest";
use testapi;
use utils;

my %SCENARIOS = (
simple => {
efi => 'False',
partition => "\\'msdos\\'",
device_type => "\\'sd\\'",
root_filesystem => "\\'ext2\\'",
home_filesystem => 'False',
snapper => 'False',
swap => 'False',
mode => "\\'single\\'",
},
'microos-efi' => {
efi => 'True',
partition => "\\'gpt\\'",
device_type => "\\'sd\\'",
root_filesystem => "\\'btrfs\\'",
home_filesystem => 'False',
snapper => 'True',
swap => 'False',
mode => "\\'microos\\'",
},
);

sub assert_script_run_qemu {
my ($command) = @_;
assert_script_run "ssh -oStrictHostKeyChecking=no -p 10022 localhost '$command'";
}

sub get_from_qemu {
my ($file_path) = @_;
assert_script_run "scp -oStrictHostKeyChecking=no -P 10022 localhost:$file_path .";
}

sub set_pillar_var {
my ($key, $value) = @_;
my $sls = '/usr/share/yomi/pillar/installer.sls';
assert_script_run "sed -i \$'s/{% set $key = .* %}/{% set $key = $value %}/' $sls";
}

sub set_pillar_config_var {
my ($key, $value) = @_;
my $sls = '/usr/share/yomi/pillar/installer.sls';
assert_script_run "sed -i \$'s/ $key: .*/ $key: $value/' $sls";
}

sub configure_scenario {
my ($scenario) = @_;

for my $key (keys %{$SCENARIOS{$scenario}}) {
set_pillar_var $key, $SCENARIOS{$scenario}{$key};
}

# Disable reboot, so we can recover the logs later
set_pillar_config_var('reboot', 'no');

# Enable console mode
set_pillar_config_var('grub2_console', 'yes');

assert_script_run "head -n 40 /usr/share/yomi/pillar/installer.sls";
}

sub run {
select_console 'root-console';

# Get the name of the scenario from the test name
my $scenario = get_var('TEST', 'simple');
if (!exists $SCENARIOS{$scenario}) {
die "scenario $scenario is not a valid one";
}

configure_scenario $scenario;

# Install the operating system in the inner QEMU
type_string "salt -l debug minion state.highstate |& tee -i salt /dev/$serialdev\n";
wait_serial('Total states run:', 1200);

# Get the assets and upload then before any assert that can kill
# the test
upload_asset 'salt';
upload_asset '/var/log/salt/master';
get_from_qemu '/var/log/salt/minion';
upload_asset 'minion';

# Validate that there are not errors in the salt output
assert_script_run "grep 'Failed:[[:space:]]*0' salt";

# Register that in the logs we do not have errors
my $errors_in_log = script_run "grep '][ERROR[[:space:]]*]' salt minion";
if (!$errors_in_log) {
record_info('Non-related errors in logs',
"The scenario $scenario have errors in the logs",
result => 'softfail');
}

# Reboot the inner QEMU to validate the boot loader
assert_script_run_qemu 'systemctl reboot';
wait_serial('Booting from Hard Disk...', 60) || die 'not booting from the correct media';
wait_serial('localhost login:', 1200) || die 'login not found, QEMU not launched';
}

1;