~percona-toolkit-dev/percona-toolkit/fix-empty-table-bug-987393

« back to all changes in this revision

Viewing changes to t/lib/bash/collect_system_info.sh

  • Committer: Daniel Nichter
  • Date: 2012-04-03 16:14:55 UTC
  • mfrom: (217.6.22 2.0.3)
  • Revision ID: daniel@percona.com-20120403161455-ntv33vju9o6njtqv
Merge summary-tools-2.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
plan 40
 
4
 
 
5
TMPDIR="$TEST_TMPDIR"
 
6
PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
 
7
TOOL="pt-summary"
 
8
 
 
9
. "$LIB_DIR/log_warn_die.sh"
 
10
. "$LIB_DIR/alt_cmds.sh"
 
11
. "$LIB_DIR/parse_options.sh"
 
12
. "$LIB_DIR/summary_common.sh"
 
13
. "$LIB_DIR/parse_options.sh"
 
14
. "$LIB_DIR/collect_system_info.sh"
 
15
 
 
16
# Prefix (with path) for the collect files.
 
17
p="$TMPDIR/collect_mysql_info"
 
18
samples="$PERCONA_TOOLKIT_BRANCH/t/pt-summary/samples"
 
19
 
 
20
mkdir "$p"
 
21
 
 
22
parse_options "$BIN_DIR/pt-summary" --sleep 1
 
23
 
 
24
setup_commands
 
25
 
 
26
collect_system_data "$p"
 
27
 
 
28
p2="$TMPDIR/collect_mysql_info2"
 
29
mkdir "$p2"
 
30
touch "$p2/some_empty_file"
 
31
collect_system_data "$p2"
 
32
 
 
33
cmd_ok "test ! -e \"$p2/some_empty_file\"" "collect_system_data removes empty files before exiting"
 
34
 
 
35
cat <<EOF > "$TMPDIR/expected"
 
36
Fusion-MPT SAS
 
37
EOF
 
38
find_raid_controller_lspci "$samples/lspci-001.txt" > "$TMPDIR/got"
 
39
no_diff "$TMPDIR/got" "$TMPDIR/expected" "lspci-001.txt"
 
40
 
 
41
cat <<EOF > "$TMPDIR/expected"
 
42
LSI Logic Unknown
 
43
EOF
 
44
find_raid_controller_lspci "$samples/lspci-002.txt" > "$TMPDIR/got"
 
45
no_diff "$TMPDIR/got" "$TMPDIR/expected" "lspci-002.txt"
 
46
 
 
47
cat <<EOF > "$TMPDIR/expected"
 
48
AACRAID
 
49
EOF
 
50
find_raid_controller_lspci "$samples/lspci-003.txt" > "$TMPDIR/got"
 
51
no_diff "$TMPDIR/got" "$TMPDIR/expected" "lspci-003.txt"
 
52
 
 
53
cat <<EOF > "$TMPDIR/expected"
 
54
LSI Logic MegaRAID SAS
 
55
EOF
 
56
find_raid_controller_lspci "$samples/lspci-004.txt" > "$TMPDIR/got"
 
57
no_diff "$TMPDIR/got" "$TMPDIR/expected" "lspci-004.txt"
 
58
 
 
59
cat <<EOF > "$TMPDIR/expected"
 
60
Fusion-MPT SAS
 
61
EOF
 
62
find_raid_controller_lspci "$samples/lspci-005.txt" > "$TMPDIR/got"
 
63
no_diff "$TMPDIR/got" "$TMPDIR/expected" "lspci-005.txt"
 
64
 
 
65
cat <<EOF > "$TMPDIR/expected"
 
66
HP Smart Array
 
67
EOF
 
68
find_raid_controller_lspci "$samples/lspci-006.txt" > "$TMPDIR/got"
 
69
no_diff "$TMPDIR/got" "$TMPDIR/expected" "lspci-006.txt"
 
70
 
 
71
# find_raid_controller_dmesg
 
72
 
 
73
cat <<EOF > "$TMPDIR/expected"
 
74
Fusion-MPT SAS
 
75
EOF
 
76
find_raid_controller_dmesg "$samples/dmesg-001.txt" > "$TMPDIR/got"
 
77
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-001.txt"
 
78
 
 
79
cat <<EOF > "$TMPDIR/expected"
 
80
AACRAID
 
81
EOF
 
82
find_raid_controller_dmesg "$samples/dmesg-002.txt" > "$TMPDIR/got"
 
83
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-002.txt"
 
84
 
 
85
cat <<EOF > "$TMPDIR/expected"
 
86
LSI Logic MegaRAID SAS
 
87
EOF
 
88
find_raid_controller_dmesg "$samples/dmesg-003.txt" > "$TMPDIR/got"
 
89
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-003.txt"
 
90
 
 
91
cat <<EOF > "$TMPDIR/expected"
 
92
AACRAID
 
93
EOF
 
94
find_raid_controller_dmesg "$samples/dmesg-004.txt" > "$TMPDIR/got"
 
95
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-004.txt"
 
96
 
 
97
cat <<EOF > "$TMPDIR/expected"
 
98
Fusion-MPT SAS
 
99
EOF
 
100
find_raid_controller_dmesg "$samples/dmesg-005.txt" > "$TMPDIR/got"
 
101
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-005.txt"
 
102
 
 
103
# TODO is this right?
 
104
cat <<EOF > "$TMPDIR/expected"
 
105
EOF
 
106
find_raid_controller_dmesg "$samples/dmesg-006.txt" > "$TMPDIR/got"
 
107
cat "$TMPDIR/got"
 
108
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-006.txt"
 
109
 
 
110
# TODO is this right?
 
111
cat <<EOF > "$TMPDIR/expected"
 
112
EOF
 
113
find_raid_controller_dmesg "$samples/dmesg-007.txt" > "$TMPDIR/got"
 
114
cat "$TMPDIR/got"
 
115
no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-007.txt"
 
116
 
 
117
# raid_controller
 
118
 
 
119
rm "$TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
 
120
raid_controller "" "" > "$TMPDIR/raid_controller_outfile.tmp"
 
121
 
 
122
is \
 
123
   "$(get_var raid_controller "$TMPDIR/raid_controller_outfile.tmp")" \
 
124
   "No RAID controller detected" \
 
125
   "raid_controller has a sane default"
 
126
 
 
127
rm "$TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
 
128
raid_controller "" "$samples/lspci-001.txt" > "$TMPDIR/raid_controller_outfile.tmp"
 
129
is \
 
130
   "$(get_var raid_controller "$TMPDIR/raid_controller_outfile.tmp")" \
 
131
   "Fusion-MPT SAS" \
 
132
   "raid_controller gets the correct result from an lspci file"
 
133
 
 
134
rm "$TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
 
135
raid_controller "$samples/dmesg-004.txt" "" > "$TMPDIR/raid_controller_outfile.tmp"
 
136
is \
 
137
   "$(get_var raid_controller "$TMPDIR/raid_controller_outfile.tmp")" \
 
138
   "AACRAID" \
 
139
   "...Or from a dmseg file"
 
140
 
 
141
# find_virtualization_dmesg
 
142
 
 
143
i=1
 
144
for expected in "" "" "" "" "" "Xen" "VirtualBox"; do
 
145
   find_virtualization_dmesg "$samples/dmesg-00$i.txt" > "$TMPDIR/got"
 
146
   is "$(cat "$TMPDIR/got")" "$expected" "dmesg-00$i.txt"
 
147
   i=$(($i + 1))
 
148
done
 
149
 
 
150
# linux_exclusive_collection
 
151
 
 
152
fake_command () {
 
153
   local cmd="$1"
 
154
   local output="$2"
 
155
 
 
156
   printf "#!/usr/bin/env bash\necho \"${output}\"\n" > "$TMPDIR/${cmd}_replacement"
 
157
   chmod +x "$TMPDIR/${cmd}_replacement"
 
158
   eval "CMD_$(echo $cmd | tr '[a-z]' '[A-Z]')=\"$TMPDIR/${cmd}_replacement\""
 
159
}
 
160
 
 
161
test_linux_exclusive_collection () {
 
162
   local dir="$1"
 
163
 
 
164
   # First, let's try what happens if none of the commands are available
 
165
   local CMD_LVS=""
 
166
   local CMD_VGS=""
 
167
   local CMD_NETSTAT=""
 
168
   local PT_SUMMARY_SKIP=""
 
169
 
 
170
   mkdir "$dir/1"
 
171
   cp "$dir/sysctl" "$dir/1/"
 
172
   linux_exclusive_collection "$dir/1"
 
173
 
 
174
   is \
 
175
      "$(ls "$dir/1" | grep 'lvs\|vgs\|netstat' )" \
 
176
      "" \
 
177
      'linux_exclusive_collection: If a command isnt available, doesnt create spurious files'
 
178
 
 
179
   local i=1
 
180
   for f in lvs vgs netstat; do
 
181
      fake_command "$f" "ok $i"
 
182
      i=$(($i + 1))
 
183
   done
 
184
   
 
185
   mkdir "$dir/2"
 
186
   cp "$dir/sysctl" "$dir/2/"
 
187
   linux_exclusive_collection "$dir/2"
 
188
 
 
189
   is \
 
190
      "$(ls "${dir}/2" | grep 'lvs\|vgs\|netstat' | sort | xargs echo )" \
 
191
      "lvs lvs.stderr netstat vgs" \
 
192
      "linux_exclusive_collection: And works as expected if they are there"
 
193
 
 
194
   local i=1
 
195
   for f in lvs vgs netstat; do
 
196
      is \
 
197
         "$(cat "${dir}/2/${f}")" \
 
198
         "ok $i" \
 
199
         "linux_exclusive_collection: output for $f is correct"
 
200
      i=$(($i + 1))
 
201
   done
 
202
}
 
203
 
 
204
platform="$(get_var platform "$p/summary")"
 
205
 
 
206
if [ "$platform" = "Linux" ]; then
 
207
   mkdir "$TMPDIR/linux_data"
 
208
   cp "$p/sysctl" "$TMPDIR/linux_data/sysctl"
 
209
   test_linux_exclusive_collection "$TMPDIR/linux_data"
 
210
else
 
211
   skip 1 5 "Tests exclusive for Linux"
 
212
fi
 
213
 
 
214
# propietary_raid_controller
 
215
 
 
216
test_propietary_raid_controller () {
 
217
   local dir="$1"
 
218
 
 
219
   local CMD_ARCCONF=""
 
220
   local CMD_HPACUCLI=""
 
221
   local CMD_MEGACLI64=""
 
222
 
 
223
   local controller=""
 
224
   mkdir "$dir/1"
 
225
   for controller in "AACRAID" "HP Smart Array" "LSI Logic MegaRAID SAS"; do
 
226
      rm "$dir/1/summary" 2>/dev/null
 
227
      touch "$dir/1/summary"
 
228
      propietary_raid_controller "$dir/1/raid-controller" "$dir/1/summary" "$dir/1" "$controller"
 
229
      is \
 
230
         "$(get_var "internal::raid_opt" "$dir/1/summary")" \
 
231
         0 \
 
232
         "propietary_raid_controller: correct raid_opt default for $controller"
 
233
 
 
234
      cmd_ok \
 
235
         "grep -q 'RAID controller software not found' \"$dir/1/raid-controller\"" \
 
236
         "propietary_raid_controller: correct default for $controller if the command isn't available"
 
237
   done
 
238
   
 
239
   mkdir "$dir/2"
 
240
   fake_command arcconf "ok arcconf"
 
241
   propietary_raid_controller "$dir/2/raid-controller" "$dir/2/summary" "$dir/2" "AACRAID"
 
242
   is \
 
243
      "$(get_var "internal::raid_opt" "$dir/2/summary")" \
 
244
      1 \
 
245
      "propietary_raid_controller: correct raid_opt default for $controller when arcconf is there"
 
246
 
 
247
   is \
 
248
      "$(cat "$dir/2/raid-controller")" \
 
249
      "ok arcconf" \
 
250
      "AACRAID calls arcconf"
 
251
}
 
252
 
 
253
mkdir "$TMPDIR/raid_controller"
 
254
test_propietary_raid_controller "$TMPDIR/raid_controller"
 
255
 
 
256
 
 
257
# notable_processes_info
 
258
(
 
259
   sleep 50000
 
260
) 2>/dev/null &
 
261
forked_pid="$!"
 
262
 
 
263
if [ -e /proc/$forked_pid/oom_adj ] \
 
264
      && echo "-17" > /proc/$forked_pid/oom_adj 2>/dev/null; then
 
265
 
 
266
   notable_processes_info > "$TMPDIR/notable_procs"
 
267
   like \
 
268
      "$(cat "$TMPDIR/notable_procs")" \
 
269
      "${forked_pid}\\s+-17" \
 
270
      "notable_proccesses_info finds the process we manually changed earlier"
 
271
 
 
272
else
 
273
   skip 1 1 "Either this OS doesn't have an oom, or this user doesn't have enough privileges to change the oom of other processes"
 
274
fi
 
275
 
 
276
disown $forked_pid
 
277
kill -9 $forked_pid
 
278
 
 
279
# dmidecode_system_info
 
280
 
 
281
test_dmidecode_system_info () {
 
282
   local dir="$1"
 
283
 
 
284
   local CMD_DMIDECODE=""
 
285
   touch "$dir/outfile"
 
286
   dmidecode_system_info "$dir/outfile"
 
287
 
 
288
   cmd_ok '! test -s "$dir/outfile"' "If dmidecode isn't found, produces nothing"
 
289
 
 
290
   fake_command dmidecode '[$@]'
 
291
   dmidecode_system_info > "$dir/outfile"
 
292
 
 
293
   cat <<EOF >> "$dir/expected"
 
294
vendor    [-s system-manufacturer]
 
295
system    [-s system-manufacturer]; [-s system-product-name]; v[-s system-version] ([-s chassis-type])
 
296
servicetag    [-s system-serial-number]
 
297
EOF
 
298
 
 
299
   no_diff \
 
300
      "$dir/outfile" \
 
301
      "$dir/expected" \
 
302
      "..but if it's there, it gets called with the expected parameters "
 
303
}
 
304
 
 
305
mkdir "$TMPDIR/dmidecode_system_info"
 
306
test_dmidecode_system_info "$TMPDIR/dmidecode_system_info"
 
307