forked from os-autoinst/os-autoinst-distri-opensuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18_saputils.t
259 lines (210 loc) · 9.97 KB
/
18_saputils.t
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Test::Warnings;
use Test::MockModule;
use Data::Dumper;
use List::Util qw(any);
use testapi;
use saputils;
subtest '[calculate_hana_topology] invalid output' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'PUFFI');
ok keys %$topology == 0, 'No entry in topology if SAPHanaSR-showAttr has nothing';
};
subtest '[calculate_hana_topology] minimal 2 nodes' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/vhost="AAAAAAA"
Hosts/vmhana02/vhost="BBBBBBB"');
ok keys %$topology == 2, 'Output is about exactly 2 hosts';
ok((any { qr/vmhana01/ } keys %$topology), 'External hash has key vmhana01');
ok((any { qr/vmhana02/ } keys %$topology), 'External hash has key vmhana02');
};
subtest '[calculate_hana_topology] internal keys' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
note("Parsed input looks like " . Dumper($topology));
ok((keys %$topology eq 2), "Parsed input has two hosts, so two outer keys.");
while (my ($key, $value) = each %$topology) {
ok((keys %$value eq 3), "Parsed input has 3 values for each host, so 3 inner keys.");
# how to access one value of an inner hash
like(%$value{remoteHost}, qr/vmhana0/, 'remoteHost is like vmhana0');
}
# how to access one inner value in one shot
ok((%$topology{vmhana01}->{sync_state} eq 'PRIM'), 'sync_state of vmhana01 is exactly PRIM');
};
subtest '[check_hana_topology] healthy cluster' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="online"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="online"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology);
ok(($topology_ready == 1), 'healthy cluster leads to the return of 1');
};
subtest '[check_hana_topology] healthy cluster with custom node_state_match' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="PAPERINO"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="PAPERINO"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology, node_state_match => 'PAPERINO');
ok(($topology_ready == 1), 'healthy cluster leads to the return of 1');
};
subtest '[check_hana_topology] healthy cluster with custom node_state_match pacemaker 2.1.7' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="1234"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="5678"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology, node_state_match => '\d');
ok(($topology_ready == 1), 'healthy cluster leads to the return of 1');
};
subtest '[check_hana_topology] healthy cluster with custom node_state_match pacemaker 2.1.7' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="1234"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="0"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology, node_state_match => '[1-9]');
ok(($topology_ready == 0), 'unhealthy cluster leads to the return of 0');
};
subtest '[check_hana_topology] unhealthy cluster not online' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="NOT ONLINE AT ALL"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="online"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology);
ok(($topology_ready == 0), 'unhealthy cluster leads to the return of 0');
};
subtest '[check_hana_topology] unhealthy cluster no PRIM' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="online"
Hosts/vmhana01/sync_state="SOK"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="online"
Hosts/vmhana02/sync_state="SOK"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology);
ok(($topology_ready == 0), 'unhealthy cluster leads to the return of 0');
};
subtest '[check_hana_topology] unhealthy cluster SFAIL' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="online"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="online"
Hosts/vmhana02/sync_state="SFAIL"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology);
ok(($topology_ready == 0), 'unhealthy cluster leads to the return of 0');
};
subtest '[check_hana_topology] unhealthy cluster missing field' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Global/global/cib-time="Thu Feb 1 18:33:56 2024"
Global/global/maintenance="false"
Sites/site_b/b="SOK"
Hosts/vmhana01/remoteHost="vmhana02"
Hosts/vmhana01/node_state="online"
Hosts/vmhana01/sync_state="PRIM"
Hosts/vmhana01/vhost="vmhana01"
Hosts/vmhana02/remoteHost="vmhana01"
Hosts/vmhana02/node_state="online"
Hosts/vmhana02/vhost="vmhana02"');
my $topology_ready = check_hana_topology(input => $topology);
ok(($topology_ready == 0), 'unhealthy cluster leads to the return of 0');
};
subtest '[check_hana_topology] invalid input' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $topology = calculate_hana_topology(input => 'Balamb Garden');
my $topology_ready = check_hana_topology(input => $topology);
ok(($topology_ready == 0), 'invalid input leads to the return of 0');
};
subtest '[check_crm_output] input argument is mandatory' => sub {
dies_ok { check_crm_output() };
};
subtest '[check_crm_output] no starting no failed' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $ret = check_crm_output(input => 'PUFFI');
ok $ret eq 1, "Ret:$ret has to be 1";
};
subtest '[check_crm_output] starting and failed' => sub {
my $saputils = Test::MockModule->new('saputils', no_auto => 1);
$saputils->redefine(record_info => sub { note(join(' ', 'RECORD_INFO -->', @_)); });
my $ret = check_crm_output(input => '
: Starting
Failed Resource Actions:');
ok $ret eq 0, "Ret:$ret has to be 0";
};
done_testing;