-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathconsoletest.pm
105 lines (75 loc) · 2.46 KB
/
consoletest.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright 2019 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later
package consoletest;
use base "opensusebasetest";
use strict;
use warnings;
use testapi;
use known_bugs;
use version_utils qw(is_public_cloud is_openstack);
use Utils::Logging qw(export_logs_basic export_logs_desktop);
use utils;
my %avc_record = (
start => 0,
end => undef
);
=head1 consoletest
C<consoletest> - Base class for all console tests
=cut
=head2 post_run_hook
Method executed when run() finishes.
=cut
sub post_run_hook {
my ($self) = @_;
# start next test in home directory
enter_cmd "cd";
record_avc_selinux_alerts();
# clear screen to make screen content ready for next test
$self->clear_and_verify_console;
}
=head2 post_fail_hook
Method executed when run() finishes and the module has result => 'fail'
=cut
sub post_fail_hook {
my ($self) = @_;
return if get_var('NOLOGS');
record_avc_selinux_alerts();
$self->SUPER::post_fail_hook;
# at this point the instance is shutdown
return if (is_public_cloud() || is_openstack());
# Remaining log functions are executed in Utils::Logging::export_logs()
# called in opensusebasetest::post_fail_hook()
select_console('log-console');
show_oom_info;
show_tasks_in_blocked_state;
}
=head2 record_avc_selinux_alerts
List AVCs that have been recorded during a runtime of a test module that executes this function
=cut
sub record_avc_selinux_alerts {
if ((current_console() !~ /root|log/) || (script_run('test -f /var/log/audit/audit.log') != 0)) {
return;
}
my @logged = split(/\n/, script_output('ausearch -m avc -r', timeout => 300, proceed_on_failure => 1));
# no new messages are registered
if (scalar @logged <= $avc_record{start}) {
return;
}
$avc_record{end} = scalar @logged - 1;
my @avc = @logged[$avc_record{start} .. $avc_record{end}];
$avc_record{start} = $avc_record{end} + 1;
record_info('AVC', join("\n", @avc));
}
=head2 use_wicked_network_manager
use_wicked_network_manager();
switch network manager to wicked.
=cut
sub use_wicked_network_manager {
zypper_call("in wicked");
assert_script_run "systemctl disable NetworkManager --now";
assert_script_run "systemctl enable --force wicked --now";
assert_script_run "systemctl start wickedd.service";
assert_script_run "systemctl start wicked.service";
assert_script_run qq{systemctl status wickedd.service | grep \"active \(running\)\"};
}
1;