forked from os-autoinst/os-autoinst-distri-opensuse
/
lvm_thin_check.pm
73 lines (65 loc) · 2.49 KB
/
lvm_thin_check.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# SUSE's openQA tests
#
# Copyright © 2009-2013 Bernhard M. Wiedemann
# Copyright © 2012-2018 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: Simple LVM thin provisioning check
# Maintainer: Martin Loviska <mloviska@suse.com>
use strict;
use warnings;
use base "opensusebasetest";
use testapi;
use utils;
use y2logsstep;
use serial_terminal 'select_virtio_console';
sub run {
my $lv_stats = {
write_access => qr/\s{2}LV Write Access \s+ read\/write/,
status => qr/\s{2}LV Status \s+ available/,
readahead => qr/\s{2}Read ahead sectors \s+ auto/,
# 254 as major no. points to dev-mapper, see /proc/devices
block_device => qr/\s{2}Block device \s+ 254:\d/
};
select_virtio_console();
record_info('INFO', 'Print lvm setup');
assert_script_run 'lsblk';
assert_script_run 'lvmdiskscan';
assert_script_run 'lvscan';
assert_script_run 'lvs -a | tee original_usage';
assert_script_run 'pvs -a';
# thin volume does not exceed thin pool size in our tests
my @volumes = split(/\n/, script_output q[lvscan | awk '{print $2}'| sed s/\'//g]);
# check for read only volumes and
foreach my $volume (@volumes) {
chomp;
my $lvdisp_out = script_output "lvdisplay $volume";
foreach (keys %{$lv_stats}) {
die "Value of $lv_stats->{$_} was not found in $volume configuration" unless ($lvdisp_out =~ /(?<tested_string>$lv_stats->{$_})/);
record_info('TEST', "Found $+{tested_string} in $volume");
}
}
record_info('INFO', 'Create a file on thin volume');
my $test_file = '/home/bernhard/test_file.txt';
assert_script_run "dd if=/dev/zero of=$test_file count=1024 bs=1M";
assert_script_run "ls -lah $test_file";
assert_script_run 'lvs -a | tee instant_usage';
if ((script_run 'diff original_usage instant_usage') != 1) {
die "LVM usage stats do not differ!";
}
}
sub post_fail_hook {
my $self = shift;
select_console 'root-console';
my $lvmdump_regex = qr{/root/lvmdump-.*?-\d+\.tgz};
my $out = script_output 'lvmdump';
if ($out =~ /(?<lvmdump_gzip>$lvmdump_regex)/) {
upload_logs "$+{lvmdump_gzip}";
}
$self->save_and_upload_log('lvm dumpconfig', '/tmp/lvm_dumpconf.out');
$self->SUPER::post_fail_hook;
}
1;