File: collect_system_info.sh

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (322 lines) | stat: -rw-r--r-- 9,131 bytes parent folder | download | duplicates (2)
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env bash

plan 44

PT_TMPDIR="$TEST_PT_TMPDIR"
PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
TOOL="pt-summary"

. "$LIB_DIR/log_warn_die.sh"
. "$LIB_DIR/alt_cmds.sh"
. "$LIB_DIR/parse_options.sh"
. "$LIB_DIR/summary_common.sh"
. "$LIB_DIR/parse_options.sh"
. "$LIB_DIR/collect_system_info.sh"

# Prefix (with path) for the collect files.
p="$PT_TMPDIR/collect_mysql_info"
samples="$PERCONA_TOOLKIT_BRANCH/t/pt-summary/samples"

mkdir "$p"

parse_options "$BIN_DIR/pt-summary" --sleep 1

setup_commands

collect_system_data "$p"

p2="$PT_TMPDIR/collect_mysql_info2"
mkdir "$p2"
touch "$p2/some_empty_file"
collect_system_data "$p2"

cmd_ok "test ! -e \"$p2/some_empty_file\"" "collect_system_data removes empty files before exiting"

cat <<EOF > "$PT_TMPDIR/expected"
Fusion-MPT SAS
EOF
find_raid_controller_lspci "$samples/lspci-001.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "lspci-001.txt"

cat <<EOF > "$PT_TMPDIR/expected"
LSI Logic Unknown
EOF
find_raid_controller_lspci "$samples/lspci-002.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "lspci-002.txt"

cat <<EOF > "$PT_TMPDIR/expected"
AACRAID
EOF
find_raid_controller_lspci "$samples/lspci-003.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "lspci-003.txt"

cat <<EOF > "$PT_TMPDIR/expected"
LSI Logic MegaRAID SAS
EOF
find_raid_controller_lspci "$samples/lspci-004.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "lspci-004.txt"

cat <<EOF > "$PT_TMPDIR/expected"
Fusion-MPT SAS
EOF
find_raid_controller_lspci "$samples/lspci-005.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "lspci-005.txt"

cat <<EOF > "$PT_TMPDIR/expected"
HP Smart Array
EOF
find_raid_controller_lspci "$samples/lspci-006.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "lspci-006.txt"

# find_raid_controller_dmesg

cat <<EOF > "$PT_TMPDIR/expected"
Fusion-MPT SAS
EOF
find_raid_controller_dmesg "$samples/dmesg-001.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-001.txt"

cat <<EOF > "$PT_TMPDIR/expected"
AACRAID
EOF
find_raid_controller_dmesg "$samples/dmesg-002.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-002.txt"

cat <<EOF > "$PT_TMPDIR/expected"
LSI Logic MegaRAID SAS
EOF
find_raid_controller_dmesg "$samples/dmesg-003.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-003.txt"

cat <<EOF > "$PT_TMPDIR/expected"
AACRAID
EOF
find_raid_controller_dmesg "$samples/dmesg-004.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-004.txt"

cat <<EOF > "$PT_TMPDIR/expected"
Fusion-MPT SAS
EOF
find_raid_controller_dmesg "$samples/dmesg-005.txt" > "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-005.txt"

# TODO is this right?
cat <<EOF > "$PT_TMPDIR/expected"
EOF
find_raid_controller_dmesg "$samples/dmesg-006.txt" > "$PT_TMPDIR/got"
cat "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-006.txt"

# TODO is this right?
cat <<EOF > "$PT_TMPDIR/expected"
EOF
find_raid_controller_dmesg "$samples/dmesg-007.txt" > "$PT_TMPDIR/got"
cat "$PT_TMPDIR/got"
no_diff "$PT_TMPDIR/got" "$PT_TMPDIR/expected" "dmesg-007.txt"

# raid_controller

rm "$PT_TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
raid_controller "" "" > "$PT_TMPDIR/raid_controller_outfile.tmp"

is \
   "$(get_var raid_controller "$PT_TMPDIR/raid_controller_outfile.tmp")" \
   "No RAID controller detected" \
   "raid_controller has a sane default"

rm "$PT_TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
raid_controller "" "$samples/lspci-001.txt" > "$PT_TMPDIR/raid_controller_outfile.tmp"
is \
   "$(get_var raid_controller "$PT_TMPDIR/raid_controller_outfile.tmp")" \
   "Fusion-MPT SAS" \
   "raid_controller gets the correct result from an lspci file"

rm "$PT_TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
raid_controller "$samples/dmesg-004.txt" "" > "$PT_TMPDIR/raid_controller_outfile.tmp"
is \
   "$(get_var raid_controller "$PT_TMPDIR/raid_controller_outfile.tmp")" \
   "AACRAID" \
   "...Or from a dmseg file"

# find_virtualization_dmesg

i=1
for expected in "" "" "" "" "" "Xen" "VirtualBox"; do
   find_virtualization_dmesg "$samples/dmesg-00$i.txt" > "$PT_TMPDIR/got"
   is "$(cat "$PT_TMPDIR/got")" "$expected" "dmesg-00$i.txt"
   i=$(($i + 1))
done

# linux_exclusive_collection

fake_command () {
   local cmd="$1"
   local output="$2"

   printf "#!/usr/bin/env bash\necho \"${output}\"\n" > "$PT_TMPDIR/${cmd}_replacement"
   chmod +x "$PT_TMPDIR/${cmd}_replacement"
   eval "CMD_$(echo $cmd | tr '[a-z]' '[A-Z]' | tr '\-' '_')=\"$PT_TMPDIR/${cmd}_replacement\""
}

test_linux_exclusive_collection () {
   local dir="$1"

   # First, let's try what happens if none of the commands are available
   local CMD_LVS=""
   local CMD_VGS=""
   local CMD_NETSTAT=""
   local PT_SUMMARY_SKIP=""

   mkdir "$dir/1"
   if [ -e "$dir/sysctl" ]; then
      cp "$dir/sysctl" "$dir/1/"
   fi
   linux_exclusive_collection "$dir/1"

   is \
      "$(ls "$dir/1" | grep 'lvs\|vgs\|netstat' )" \
      "" \
      'linux_exclusive_collection: If a command isnt available, doesnt create spurious files'

   local i=1
   for f in lvs vgs netstat; do
      fake_command "$f" "ok $i"
      i=$(($i + 1))
   done
   
   mkdir "$dir/2"
   if [ -e "$dir/sysctl" ]; then
      cp "$dir/sysctl" "$dir/2/"
   fi
   linux_exclusive_collection "$dir/2"

   is \
      "$(ls "${dir}/2" | grep 'lvs\|vgs\|netstat' | sort | xargs echo )" \
      "lvs lvs.stderr netstat vgs" \
      "linux_exclusive_collection: And works as expected if they are there"

   local i=1
   for f in lvs vgs netstat; do
      is \
         "$(cat "${dir}/2/${f}")" \
         "ok $i" \
         "linux_exclusive_collection: output for $f is correct"
      i=$(($i + 1))
   done
}

platform="$(get_var platform "$p/summary")"

if [ "$platform" = "Linux" ]; then
   mkdir "$PT_TMPDIR/linux_data"
   if [ -e "$p/sysctl" ]; then
      cp "$p/sysctl" "$PT_TMPDIR/linux_data/sysctl"
   fi
   test_linux_exclusive_collection "$PT_TMPDIR/linux_data"
   rm -rf "$PT_TMPDIR/linux_data"
else
   skip 1 5 "Tests exclusive for Linux"
fi

# propietary_raid_controller

test_propietary_raid_controller () {
   local dir="$1"

   local CMD_ARCCONF=""
   local CMD_HPACUCLI=""
   local CMD_MEGACLI64=""

   local controller=""
   mkdir "$dir/1"
   for controller in "AACRAID" "HP Smart Array" "LSI Logic MegaRAID SAS"; do
      rm "$dir/1/summary" 2>/dev/null
      touch "$dir/1/summary"
      propietary_raid_controller "$dir/1/raid-controller" "$dir/1/summary" "$dir/1" "$controller"
      is \
         "$(get_var "internal::raid_opt" "$dir/1/summary")" \
         0 \
         "propietary_raid_controller: correct raid_opt default for $controller"

      cmd_ok \
         "grep -q 'RAID controller software not found' \"$dir/1/raid-controller\"" \
         "propietary_raid_controller: correct default for $controller if the command isn't available"
   done
   
   mkdir "$dir/2"
   fake_command arcconf "ok arcconf"
   propietary_raid_controller "$dir/2/raid-controller" "$dir/2/summary" "$dir/2" "AACRAID"
   is \
      "$(get_var "internal::raid_opt" "$dir/2/summary")" \
      1 \
      "propietary_raid_controller: correct raid_opt default for $controller when arcconf is there"

   is \
      "$(cat "$dir/2/raid-controller")" \
      "ok arcconf" \
      "AACRAID calls arcconf"
}

mkdir "$PT_TMPDIR/raid_controller"
test_propietary_raid_controller "$PT_TMPDIR/raid_controller"


# notable_processes_info
(
   sleep 50000
) 2>/dev/null &
forked_pid="$!"

if [ -w /proc/$forked_pid/oom_adj ] \
      && echo "-17" > /proc/$forked_pid/oom_adj 2>/dev/null; then

   notable_processes_info > "$PT_TMPDIR/notable_procs"
   like \
      "$(cat "$PT_TMPDIR/notable_procs")" \
      "${forked_pid}\\s+-17" \
      "notable_proccesses_info finds the process we manually changed earlier"

else
   skip 1 1 "oom_adj doesn't exist or isn't writeable"
fi

disown $forked_pid
kill -9 $forked_pid

# dmidecode_system_info

test_dmidecode_system_info () {
   local dir="$1"

   local CMD_DMIDECODE=""
   touch "$dir/outfile"
   dmidecode_system_info "$dir/outfile"

   cmd_ok '! test -s "$dir/outfile"' "If dmidecode isn't found, produces nothing"

   fake_command dmidecode '[$@]'
   dmidecode_system_info > "$dir/outfile"

   cat <<EOF >> "$dir/expected"
vendor    [-s system-manufacturer]
system    [-s system-manufacturer]; [-s system-product-name]; v[-s system-version] ([-s chassis-type])
servicetag    [-s system-serial-number]
EOF

   no_diff \
      "$dir/outfile" \
      "$dir/expected" \
      "..but if it's there, it gets called with the expected parameters "
}

mkdir "$PT_TMPDIR/dmidecode_system_info"
test_dmidecode_system_info "$PT_TMPDIR/dmidecode_system_info"

# fio_status_minus_a

for i in $( seq 1 4 ); do
   fake_command "fio-status" "\"; cat $samples/fio-status-00${i}.txt; echo \""
   fio_status_minus_a "$PT_TMPDIR/got"

   no_diff "$PT_TMPDIR/got" "$samples/Linux/004/fio-00$i" "fio_status_minus_a works for fio-status-00${i}.txt"
done