-
Notifications
You must be signed in to change notification settings - Fork 268
/
sles4sap.pm
149 lines (124 loc) · 5.6 KB
/
sles4sap.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
## no critic (RequireFilenameMatchesPackage);
package sles4sap;
use base "opensusebasetest";
use strict;
use warnings;
use testapi;
use utils;
use hacluster 'pre_run_hook';
use isotovideo;
use x11utils 'ensure_unlocked_desktop';
our @EXPORT = qw(
fix_path
set_ps_cmd
set_sap_info
become_sapadm
test_pids_max
test_forkbomb
test_version_info
test_instance_properties
test_stop
test_start_service
test_start_instance
);
our $prev_console;
our $sapadmin;
our $sid;
our $instance;
our $ps_cmd;
sub fix_path {
my ($self, $var) = @_;
my ($proto, $path) = split m|://|, $var;
my @aux = split '/', $path;
$proto = 'cifs' if ($proto eq 'smb' or $proto eq 'smbfs');
die 'Currently only supported protocols are nfs and smb/smbfs/cifs'
unless ($proto eq 'nfs' or $proto eq 'cifs');
$aux[0] .= ':' if ($proto eq 'nfs');
$aux[0] = '//' . $aux[0] if ($proto eq 'cifs');
$path = join '/', @aux;
return ($proto, $path);
}
sub set_ps_cmd {
my ($self, $procname) = @_;
$ps_cmd = 'ps auxw | grep ' . $procname . ' | grep -vw grep';
return $ps_cmd;
}
sub set_sap_info {
my ($self, $sid_env, $instance_env) = @_;
$sid = uc($sid_env);
$instance = $instance_env;
$sapadmin = lc($sid_env) . 'adm';
return ($sapadmin);
}
sub become_sapadm {
# Allow SAP Admin user to inform status via $testapi::serialdev
assert_script_run "chown $sapadmin /dev/$testapi::serialdev";
type_string "su - $sapadmin\n";
# Change the working shell to bash as SAP's installer sets the admin
# user's shell to /bin/csh and csh has problems with strings that start
# with ~ which can be generated by testapi::hashed_string() leading to
# unexpected failures of script_output() or assert_script_run()
type_string "exec bash\n";
}
sub test_pids_max {
# UserTasksMax should be set to "infinity" in /etc/systemd/logind.conf.d/sap.conf
my $uid = script_output "id -u $sapadmin";
# The systemd-run command generates syslog output that may end up in the console, so save the output to a file
assert_script_run "systemd-run --slice user -qt su - $sapadmin -c 'cat /sys/fs/cgroup/pids/user.slice/user-${uid}.slice/pids.max' | tr -d '\\r' | tee /tmp/pids-max";
my $rc1 = script_run "grep -qx max /tmp/pids-max";
# nproc should be set to "unlimited" in /etc/security/limits.d/99-sapsys.conf
# Check that nproc * 2 + 1 >= threads-max
assert_script_run "systemd-run --slice user -qt su - $sapadmin -c 'ulimit -u' -s /bin/bash | tr -d '\\r' | tee /tmp/nproc";
my $rc2 = script_run "[[ \$(( \$(< /tmp/nproc) * 2 + 1)) -ge \$(sysctl -n kernel.threads-max) ]]";
record_soft_failure "bsc#1031355" if ($rc1 or $rc2);
}
sub test_forkbomb {
# NOTE: Do not call this function on the qemu backend.
# The first forkbomb can create 3 times as many processes as the second due to unknown bug
assert_script_run "curl -f -v " . autoinst_url . "/data/sles4sap/forkbomb.pl > /tmp/forkbomb.pl; chmod +x /tmp/forkbomb.pl";
# The systemd-run command generates syslog output that may end up in the console, so save the output to a file
assert_script_run "systemd-run --slice user -qt su - $sapadmin -c /tmp/forkbomb.pl | tr -d '\\r' > /tmp/user-procs", 600;
my $user_procs = script_output "cat /tmp/user-procs";
my $root_procs = script_output "/tmp/forkbomb.pl", 600;
# Check that the SIDadm user can create at least 99% of the processes root could create
record_soft_failure "bsc#1031355" if ($user_procs < $root_procs * 0.99);
}
sub test_version_info {
my $output = script_output "sapcontrol -nr $instance -function GetVersionInfo";
die "sapcontrol: GetVersionInfo API failed\n\n$output" unless ($output =~ /GetVersionInfo[\r\n]+OK/);
}
sub test_instance_properties {
my $output = script_output "sapcontrol -nr $instance -function GetInstanceProperties | grep ^SAP";
die "sapcontrol: GetInstanceProperties API failed\n\n$output" unless ($output =~ /SAPSYSTEM.+SAPSYSTEMNAME.+SAPLOCALHOST/s);
$output =~ /SAPSYSTEMNAME, Attribute, ([A-Z][A-Z0-9]{2})/m;
die "sapcontrol: SAP administrator [$sapadmin] does not match with System SID [$1]" if ($1 ne $sid);
}
sub test_stop {
my $output = script_output "sapcontrol -nr $instance -function Stop";
die "sapcontrol: Stop API failed\n\n$output" unless ($output =~ /Stop[\r\n]+OK/);
$output = script_output "sapcontrol -nr $instance -function StopService";
die "sapcontrol: StopService API failed\n\n$output" unless ($output =~ /StopService[\r\n]+OK/);
}
sub test_start_service {
my $output = script_output "sapcontrol -nr $instance -function StartService $sid";
die "sapcontrol: StartService API failed\n\n$output" unless ($output =~ /StartService[\r\n]+OK/);
# We can't use the $ps_cmd alias, as number of process can be >1 on some HANA version
$output = script_output "pgrep -a sapstartsrv | grep -w $sid";
my @olines = split(/\n/, $output);
die "sapcontrol: wrong number of processes running after a StartService\n\n" . @olines unless (@olines == 1);
die "sapcontrol failed to start the service" unless ($output =~ /sapstartsrv/);
}
sub test_start_instance {
my $output = script_output "sapcontrol -nr $instance -function Start";
die "sapcontrol: Start API failed\n\n$output" unless ($output =~ /Start[\r\n]+OK/);
$output = script_output $ps_cmd;
my @olines = split(/\n/, $output);
die "sapcontrol: failed to start the instance" unless (@olines > 1);
}
sub post_run_hook {
my ($self) = @_;
return unless ($prev_console);
select_console($prev_console, await_console => 0);
ensure_unlocked_desktop if ($prev_console eq 'x11');
}
1;