From dc7396442f8a7a0fe8f1443e302e269f513ac954 Mon Sep 17 00:00:00 2001 From: Jonathan Rivrain Date: Tue, 7 Jul 2020 14:19:59 +0200 Subject: [PATCH] Add verification modules for autoyast_lvm --- schedule/yast/autoyast/autoyast_lvm.yaml | 36 +++++++++++++++++++ tests/autoyast/verify_lvm_partitions.pm | 29 +++++++++++++++ tests/console/validate_lvm.pm | 45 ++++++++++++++++++++---- 3 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 tests/autoyast/verify_lvm_partitions.pm diff --git a/schedule/yast/autoyast/autoyast_lvm.yaml b/schedule/yast/autoyast/autoyast_lvm.yaml index c8f7fb377d43..f600b2716095 100644 --- a/schedule/yast/autoyast/autoyast_lvm.yaml +++ b/schedule/yast/autoyast/autoyast_lvm.yaml @@ -13,6 +13,7 @@ schedule: - autoyast/installation - autoyast/console - autoyast/login + - console/validate_lvm - autoyast/wicked - autoyast/autoyast_verify - autoyast/repos @@ -21,3 +22,38 @@ schedule: - autoyast/autoyast_reboot - installation/grub_test - installation/first_boot + - autoyast/verify_cloned_profile + - autoyast/verify_lvm_partitions +test_data: + profile: + partitioning: + - drive: + unique_key: device + device: /dev/system + partitions: + - partition: + unique_key: lv_name + lv_name: root_lv + mount: / + - partition: + unique_key: lv_name + lv_name: opt_lv + mount: /opt + - partition: + unique_key: lv_name + lv_name: swap_lv + mount: swap + - drive: + unique_key: device + device: /dev/sda + partitions: + - partition: + unique_key: partition_nr + partition_nr: 1 + lvm_group: system + - partition: + unique_key: partition_nr + partition_nr: 2 + - partition: + unique_key: partition_nr + partition_nr: 3 diff --git a/tests/autoyast/verify_lvm_partitions.pm b/tests/autoyast/verify_lvm_partitions.pm new file mode 100644 index 000000000000..0e7b5e5d0e93 --- /dev/null +++ b/tests/autoyast/verify_lvm_partitions.pm @@ -0,0 +1,29 @@ +# 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 lvm partitions after autoyast installation +# Maintainer: qa-sle-yast + +use strict; +use warnings; +use parent 'installbasetest'; +use testapi; +use scheduler 'get_test_suite_data'; + +sub run { + my $test_data = get_test_suite_data(); + + my $vg = $test_data->{profile}->{partitioning}->[1]->{drive}->{partitions}->[0]->{partition}->{lvm_group}; + assert_script_run("vgdisplay $vg"); + foreach my $partition (@{$test_data->{profile}->{partitioning}->[0]->{drive}->{partitions}}) { + assert_script_run("lvdisplay /dev/$vg/$partition->{partition}->{lv_name}"); + } +} + +1; diff --git a/tests/console/validate_lvm.pm b/tests/console/validate_lvm.pm index 6a4c09e8fdf1..93b778f49e1c 100644 --- a/tests/console/validate_lvm.pm +++ b/tests/console/validate_lvm.pm @@ -18,6 +18,7 @@ use utils; use y2_module_basetest 'workaround_suppress_lvm_warnings'; use Test::Assert ':all'; use Mojo::JSON 'decode_json'; +use List::Util 'sum'; sub pre_run_hook { select_console('root-console'); @@ -29,8 +30,8 @@ sub run { assert_script_run('lvmconfig --mergedconfig --validate | grep "LVM configuration valid."', fail_message => 'LVM config validation failed'); - record_info('LVM volume', 'Verify the LVM physical volume exists'); - assert_script_run('lvmdiskscan -v | grep "1 LVM physical volume"', + record_info('LVM volume', 'Verify the LVM physical volume(s) exist'); + assert_script_run('lvmdiskscan -v | egrep "[[:digit:]] LVM physical volume[s]{0,1}$"', fail_message => 'LVM physical volume does not exist.'); record_info('ACTIVE volumes', 'Verify all Logical Volumes are ACTIVE'); @@ -40,8 +41,39 @@ sub run { } record_info('equal extents', 'Verify sum of logical extents corresponds to physical extent size'); - my $pvTotalPE = script_output q[pvdisplay|grep "Total PE" | awk '{print $3}']; - my $pvFreePE = script_output q[pvdisplay|grep "Free PE" | awk '{print $3}']; + + # Sum up the Physical Extents across all Physical Volumes within each Volume group + # of a given system. So it gives us : $PEs_in_VGs{$vg} = [@extents_in_vg] + # Then do the same for the free extents, so we can compare total PEs with total logical extents. + my @PV = split(/\n/, script_output qq[pvdisplay |grep "PV Name" |awk '{print \$3}']); + my @VG = split(/\n/, script_output qq[vgdisplay |grep "VG Name" |awk '{print \$3}']); + my %PEs_in_PVs; + my %FEs_in_PVs; + + foreach my $vg (@VG) { + my @extents_in_vg; + my @free_extents_in_vg; + foreach my $pv (@PV) { + my $vg_for_pv = script_output qq[pvdisplay $pv |grep "$vg" |awk '{print \$3}']; + chomp($vg_for_pv); + if ("$vg_for_pv" eq "$vg") { + my $extents_in_pv = script_output qq[pvdisplay $pv |grep "Total PE" |awk '{print \$3}']; + my $free_extents_in_pv = script_output qq[pvdisplay $pv |grep "Free PE" |awk '{print \$3}']; + chomp($extents_in_pv, $free_extents_in_pv); + push(@extents_in_vg, $extents_in_pv); + push(@free_extents_in_vg, $free_extents_in_pv); + } + $PEs_in_PVs{$vg} = [@extents_in_vg]; + $FEs_in_PVs{$vg} = [@free_extents_in_vg]; + } + } + + my $total_PEs; + my $total_free_PEs; + foreach my $vg (keys %PEs_in_PVs) { + $total_PEs = sum @{$PEs_in_PVs{$vg}}; + $total_free_PEs = sum @{$FEs_in_PVs{$vg}}; + } my @volumes = split(/\n/, script_output q[lvscan | awk '{print $2}'| sed s/\'//g]); my $lv_size = 0; @@ -66,10 +98,9 @@ sub run { } die "Partitions not found in $volume configuration: \n $results" if ($results); } - assert_equals($pvTotalPE - $pvFreePE, $lv_size, "Sum of Logical Extents differs!"); - + assert_equals($total_PEs - $total_free_PEs, $lv_size, "Sum of Logical Extents differs!"); record_info('LVM usage stats', 'Verify LVM usage stats are updated after adding a file.'); - my $test_file = '/home/bernhard/test_file.txt'; + my $test_file = '/home/test_file.txt'; assert_script_run 'df -h | tee original_usage'; assert_script_run "dd if=/dev/zero of=$test_file count=1024 bs=1M"; assert_script_run "ls -lah $test_file";