Merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-quiet into lp:percona-toolkit/2.1
- pt-stalk-quiet
- Merge into 2.1
Proposed by
Daniel Nichter
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Daniel Nichter | ||||
Approved revision: | 527 | ||||
Merged at revision: | 521 | ||||
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-quiet | ||||
Merge into: | lp:percona-toolkit/2.1 | ||||
Diff against target: |
910 lines (+391/-87) 13 files modified
bin/pt-ioprofile (+15/-6) bin/pt-mysql-summary (+15/-6) bin/pt-pmp (+1/-1) bin/pt-sift (+1/-1) bin/pt-stalk (+53/-14) bin/pt-summary (+15/-6) lib/PerconaTest.pm (+33/-1) lib/bash/log_warn_die.sh (+14/-5) t/lib/bash/log_warn_die.sh (+83/-10) t/pt-stalk/option_sanity.t (+24/-0) t/pt-stalk/pt-stalk.t (+90/-33) t/pt-stalk/samples/plugin002.sh (+5/-0) util/test-bash-functions (+42/-4) |
||||
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-stalk-quiet | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email: mp+144766@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 525. By Daniel Nichter
-
Fix default log level in log_warn_die.sh.
- 526. By Daniel Nichter
-
Fix typo in t/pt-stalk/
option_ sanity. t. - 527. By Daniel Nichter
-
Fix error caused on some boxes by using diff when it's not defined.
Revision history for this message
Daniel Nichter (daniel-nichter) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/pt-ioprofile' | |||
2 | --- bin/pt-ioprofile 2013-01-03 00:54:18 +0000 | |||
3 | +++ bin/pt-ioprofile 2013-01-24 19:10:25 +0000 | |||
4 | @@ -20,23 +20,32 @@ | |||
5 | 20 | PTDEBUG="${PTDEBUG:-""}" | 20 | PTDEBUG="${PTDEBUG:-""}" |
6 | 21 | EXIT_STATUS=0 | 21 | EXIT_STATUS=0 |
7 | 22 | 22 | ||
8 | 23 | ts() { | ||
9 | 24 | TS=$(date +%F-%T | tr ':-' '_') | ||
10 | 25 | echo "$TS $*" | ||
11 | 26 | } | ||
12 | 27 | |||
13 | 28 | info() { | ||
14 | 29 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
15 | 30 | } | ||
16 | 31 | |||
17 | 23 | log() { | 32 | log() { |
20 | 24 | TS=$(date +%F-%T | tr ':-' '_'); | 33 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" |
19 | 25 | echo "$TS $*" | ||
21 | 26 | } | 34 | } |
22 | 27 | 35 | ||
23 | 28 | warn() { | 36 | warn() { |
25 | 29 | log "$*" >&2 | 37 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 |
26 | 30 | EXIT_STATUS=1 | 38 | EXIT_STATUS=1 |
27 | 31 | } | 39 | } |
28 | 32 | 40 | ||
29 | 33 | die() { | 41 | die() { |
31 | 34 | warn "$*" | 42 | ts "$*" >&2 |
32 | 43 | EXIT_STATUS=1 | ||
33 | 35 | exit 1 | 44 | exit 1 |
34 | 36 | } | 45 | } |
35 | 37 | 46 | ||
36 | 38 | _d () { | 47 | _d () { |
38 | 39 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2 | 48 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 |
39 | 40 | } | 49 | } |
40 | 41 | 50 | ||
41 | 42 | # ########################################################################### | 51 | # ########################################################################### |
42 | @@ -861,7 +870,7 @@ | |||
43 | 861 | # Execute the program if it was not included from another file. | 870 | # Execute the program if it was not included from another file. |
44 | 862 | # This makes it possible to include without executing, and thus test. | 871 | # This makes it possible to include without executing, and thus test. |
45 | 863 | if [ "${0##*/}" = "$TOOL" ] \ | 872 | if [ "${0##*/}" = "$TOOL" ] \ |
47 | 864 | || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then | 873 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
48 | 865 | 874 | ||
49 | 866 | # Parse command line options. We must do this first so we can | 875 | # Parse command line options. We must do this first so we can |
50 | 867 | # see if --daemonize was specified. | 876 | # see if --daemonize was specified. |
51 | 868 | 877 | ||
52 | === modified file 'bin/pt-mysql-summary' | |||
53 | --- bin/pt-mysql-summary 2013-01-03 00:54:18 +0000 | |||
54 | +++ bin/pt-mysql-summary 2013-01-24 19:10:25 +0000 | |||
55 | @@ -22,23 +22,32 @@ | |||
56 | 22 | PTDEBUG="${PTDEBUG:-""}" | 22 | PTDEBUG="${PTDEBUG:-""}" |
57 | 23 | EXIT_STATUS=0 | 23 | EXIT_STATUS=0 |
58 | 24 | 24 | ||
59 | 25 | ts() { | ||
60 | 26 | TS=$(date +%F-%T | tr ':-' '_') | ||
61 | 27 | echo "$TS $*" | ||
62 | 28 | } | ||
63 | 29 | |||
64 | 30 | info() { | ||
65 | 31 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
66 | 32 | } | ||
67 | 33 | |||
68 | 25 | log() { | 34 | log() { |
71 | 26 | TS=$(date +%F-%T | tr ':-' '_'); | 35 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" |
70 | 27 | echo "$TS $*" | ||
72 | 28 | } | 36 | } |
73 | 29 | 37 | ||
74 | 30 | warn() { | 38 | warn() { |
76 | 31 | log "$*" >&2 | 39 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 |
77 | 32 | EXIT_STATUS=1 | 40 | EXIT_STATUS=1 |
78 | 33 | } | 41 | } |
79 | 34 | 42 | ||
80 | 35 | die() { | 43 | die() { |
82 | 36 | warn "$*" | 44 | ts "$*" >&2 |
83 | 45 | EXIT_STATUS=1 | ||
84 | 37 | exit 1 | 46 | exit 1 |
85 | 38 | } | 47 | } |
86 | 39 | 48 | ||
87 | 40 | _d () { | 49 | _d () { |
89 | 41 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2 | 50 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 |
90 | 42 | } | 51 | } |
91 | 43 | 52 | ||
92 | 44 | # ########################################################################### | 53 | # ########################################################################### |
93 | @@ -2412,7 +2421,7 @@ | |||
94 | 2412 | # Execute the program if it was not included from another file. | 2421 | # Execute the program if it was not included from another file. |
95 | 2413 | # This makes it possible to include without executing, and thus test. | 2422 | # This makes it possible to include without executing, and thus test. |
96 | 2414 | if [ "${0##*/}" = "$TOOL" ] \ | 2423 | if [ "${0##*/}" = "$TOOL" ] \ |
98 | 2415 | || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then | 2424 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
99 | 2416 | 2425 | ||
100 | 2417 | # Set up temporary dir. | 2426 | # Set up temporary dir. |
101 | 2418 | mk_tmpdir | 2427 | mk_tmpdir |
102 | 2419 | 2428 | ||
103 | === modified file 'bin/pt-pmp' | |||
104 | --- bin/pt-pmp 2013-01-03 00:54:18 +0000 | |||
105 | +++ bin/pt-pmp 2013-01-24 19:10:25 +0000 | |||
106 | @@ -215,7 +215,7 @@ | |||
107 | 215 | # Execute the program if it was not included from another file. This makes it | 215 | # Execute the program if it was not included from another file. This makes it |
108 | 216 | # possible to include without executing, and thus test. | 216 | # possible to include without executing, and thus test. |
109 | 217 | if [ "${0##*/}" = "$TOOL" ] \ | 217 | if [ "${0##*/}" = "$TOOL" ] \ |
111 | 218 | || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then | 218 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
112 | 219 | mk_tmpdir | 219 | mk_tmpdir |
113 | 220 | main "$@" | 220 | main "$@" |
114 | 221 | rm_tmpdir | 221 | rm_tmpdir |
115 | 222 | 222 | ||
116 | === modified file 'bin/pt-sift' | |||
117 | --- bin/pt-sift 2013-01-03 00:54:18 +0000 | |||
118 | +++ bin/pt-sift 2013-01-24 19:10:25 +0000 | |||
119 | @@ -587,7 +587,7 @@ | |||
120 | 587 | # Execute the program if it was not included from another file. This makes it | 587 | # Execute the program if it was not included from another file. This makes it |
121 | 588 | # possible to include without executing, and thus test. | 588 | # possible to include without executing, and thus test. |
122 | 589 | if [ "${0##*/}" = "$TOOL" ] \ | 589 | if [ "${0##*/}" = "$TOOL" ] \ |
124 | 590 | || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then | 590 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
125 | 591 | main "${@:-""}" | 591 | main "${@:-""}" |
126 | 592 | fi | 592 | fi |
127 | 593 | 593 | ||
128 | 594 | 594 | ||
129 | === modified file 'bin/pt-stalk' | |||
130 | --- bin/pt-stalk 2013-01-03 00:54:18 +0000 | |||
131 | +++ bin/pt-stalk 2013-01-24 19:10:25 +0000 | |||
132 | @@ -22,23 +22,32 @@ | |||
133 | 22 | PTDEBUG="${PTDEBUG:-""}" | 22 | PTDEBUG="${PTDEBUG:-""}" |
134 | 23 | EXIT_STATUS=0 | 23 | EXIT_STATUS=0 |
135 | 24 | 24 | ||
136 | 25 | ts() { | ||
137 | 26 | TS=$(date +%F-%T | tr ':-' '_') | ||
138 | 27 | echo "$TS $*" | ||
139 | 28 | } | ||
140 | 29 | |||
141 | 30 | info() { | ||
142 | 31 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
143 | 32 | } | ||
144 | 33 | |||
145 | 25 | log() { | 34 | log() { |
148 | 26 | TS=$(date +%F-%T | tr ':-' '_'); | 35 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" |
147 | 27 | echo "$TS $*" | ||
149 | 28 | } | 36 | } |
150 | 29 | 37 | ||
151 | 30 | warn() { | 38 | warn() { |
153 | 31 | log "$*" >&2 | 39 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 |
154 | 32 | EXIT_STATUS=1 | 40 | EXIT_STATUS=1 |
155 | 33 | } | 41 | } |
156 | 34 | 42 | ||
157 | 35 | die() { | 43 | die() { |
159 | 36 | warn "$*" | 44 | ts "$*" >&2 |
160 | 45 | EXIT_STATUS=1 | ||
161 | 37 | exit 1 | 46 | exit 1 |
162 | 38 | } | 47 | } |
163 | 39 | 48 | ||
164 | 40 | _d () { | 49 | _d () { |
166 | 41 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2 | 50 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 |
167 | 42 | } | 51 | } |
168 | 43 | 52 | ||
169 | 44 | # ########################################################################### | 53 | # ########################################################################### |
170 | @@ -962,6 +971,10 @@ | |||
171 | 962 | : | 971 | : |
172 | 963 | } | 972 | } |
173 | 964 | 973 | ||
174 | 974 | after_interval_sleep() { | ||
175 | 975 | : | ||
176 | 976 | } | ||
177 | 977 | |||
178 | 965 | after_stalk() { | 978 | after_stalk() { |
179 | 966 | : | 979 | : |
180 | 967 | } | 980 | } |
181 | @@ -1066,9 +1079,7 @@ | |||
182 | 1066 | local seconds="$1" | 1079 | local seconds="$1" |
183 | 1067 | local msg="${2:-""}" | 1080 | local msg="${2:-""}" |
184 | 1068 | if oktorun; then | 1081 | if oktorun; then |
188 | 1069 | if [ -n "$msg" ]; then | 1082 | [ "$msg" ] && info "$msg" |
186 | 1070 | log "$msg" | ||
187 | 1071 | fi | ||
189 | 1072 | sleep $seconds | 1083 | sleep $seconds |
190 | 1073 | fi | 1084 | fi |
191 | 1074 | } | 1085 | } |
192 | @@ -1126,7 +1137,11 @@ | |||
193 | 1126 | fi | 1137 | fi |
194 | 1127 | 1138 | ||
195 | 1128 | local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true" | 1139 | local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true" |
197 | 1129 | log "$msg" | 1140 | if [ "$matched" ]; then |
198 | 1141 | log "$msg" | ||
199 | 1142 | else | ||
200 | 1143 | info "$msg" | ||
201 | 1144 | fi | ||
202 | 1130 | elif [ "$OPT_COLLECT" ]; then | 1145 | elif [ "$OPT_COLLECT" ]; then |
203 | 1131 | # Make the next if condition true. | 1146 | # Make the next if condition true. |
204 | 1132 | matched=1 | 1147 | matched=1 |
205 | @@ -1140,7 +1155,7 @@ | |||
206 | 1140 | # ################################################################## | 1155 | # ################################################################## |
207 | 1141 | # Start collecting, maybe. | 1156 | # Start collecting, maybe. |
208 | 1142 | # ################################################################## | 1157 | # ################################################################## |
210 | 1143 | log "Collect triggered" | 1158 | log "Collect $ITER triggered" |
211 | 1144 | 1159 | ||
212 | 1145 | # Send email to whomever that collect has been triggered. | 1160 | # Send email to whomever that collect has been triggered. |
213 | 1146 | if [ "$OPT_NOTIFY_BY_EMAIL" ]; then | 1161 | if [ "$OPT_NOTIFY_BY_EMAIL" ]; then |
214 | @@ -1166,8 +1181,8 @@ | |||
215 | 1166 | "$margin" | 1181 | "$margin" |
216 | 1167 | if [ $? -eq 0 ]; then | 1182 | if [ $? -eq 0 ]; then |
217 | 1168 | # There should be enough disk space, so collect. | 1183 | # There should be enough disk space, so collect. |
220 | 1169 | log "$msg" >> "$OPT_DEST/$prefix-trigger" | 1184 | ts "$msg" >> "$OPT_DEST/$prefix-trigger" |
221 | 1170 | log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger" | 1185 | ts "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger" |
222 | 1171 | last_prefix="$prefix" | 1186 | last_prefix="$prefix" |
223 | 1172 | 1187 | ||
224 | 1173 | # Plugin hook: | 1188 | # Plugin hook: |
225 | @@ -1181,7 +1196,7 @@ | |||
226 | 1181 | collect "$OPT_DEST" "$prefix" | 1196 | collect "$OPT_DEST" "$prefix" |
227 | 1182 | ) >> "$OPT_DEST/$prefix-output" 2>&1 & | 1197 | ) >> "$OPT_DEST/$prefix-output" 2>&1 & |
228 | 1183 | local collector_pid=$! | 1198 | local collector_pid=$! |
230 | 1184 | log "Collector PID $collector_pid" | 1199 | log "Collect $ITER PID $collector_pid" |
231 | 1185 | 1200 | ||
232 | 1186 | # Plugin hook: | 1201 | # Plugin hook: |
233 | 1187 | after_collect $collector_pid | 1202 | after_collect $collector_pid |
234 | @@ -1199,6 +1214,7 @@ | |||
235 | 1199 | # ################################################################## | 1214 | # ################################################################## |
236 | 1200 | # Done collecting. | 1215 | # Done collecting. |
237 | 1201 | # ################################################################## | 1216 | # ################################################################## |
238 | 1217 | log "Collect $ITER done" | ||
239 | 1202 | ITER=$((ITER + 1)) | 1218 | ITER=$((ITER + 1)) |
240 | 1203 | cycles_true=0 | 1219 | cycles_true=0 |
241 | 1204 | sleep_ok "$OPT_SLEEP" "Sleeping $OPT_SLEEP seconds after collect" | 1220 | sleep_ok "$OPT_SLEEP" "Sleeping $OPT_SLEEP seconds after collect" |
242 | @@ -1208,6 +1224,9 @@ | |||
243 | 1208 | else | 1224 | else |
244 | 1209 | # Trigger/check/value is ok, sleep until next check. | 1225 | # Trigger/check/value is ok, sleep until next check. |
245 | 1210 | sleep_ok "$OPT_INTERVAL" | 1226 | sleep_ok "$OPT_INTERVAL" |
246 | 1227 | |||
247 | 1228 | # Plugin hook: | ||
248 | 1229 | after_interval_sleep | ||
249 | 1211 | fi | 1230 | fi |
250 | 1212 | done | 1231 | done |
251 | 1213 | 1232 | ||
252 | @@ -1291,7 +1310,7 @@ | |||
253 | 1291 | # Execute the program if it was not included from another file. | 1310 | # Execute the program if it was not included from another file. |
254 | 1292 | # This makes it possible to include without executing, and thus test. | 1311 | # This makes it possible to include without executing, and thus test. |
255 | 1293 | if [ "${0##*/}" = "$TOOL" ] \ | 1312 | if [ "${0##*/}" = "$TOOL" ] \ |
257 | 1294 | || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then | 1313 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
258 | 1295 | 1314 | ||
259 | 1296 | # Parse command line options. We must do this first so we can | 1315 | # Parse command line options. We must do this first so we can |
260 | 1297 | # see if --daemonize was specified. | 1316 | # see if --daemonize was specified. |
261 | @@ -1737,6 +1756,10 @@ | |||
262 | 1737 | Called after sleeping L<"--sleep"> seconds for the collector process to finish. | 1756 | Called after sleeping L<"--sleep"> seconds for the collector process to finish. |
263 | 1738 | This hook is called after C<after_collect>. | 1757 | This hook is called after C<after_collect>. |
264 | 1739 | 1758 | ||
265 | 1759 | =item after_interval_sleep | ||
266 | 1760 | |||
267 | 1761 | Called after sleeping L<"--interval"> seconds after each trigger check. | ||
268 | 1762 | |||
269 | 1740 | =item after_stalk | 1763 | =item after_stalk |
270 | 1741 | 1764 | ||
271 | 1742 | Called after stalking. Since pt-stalk stalks forever by default, | 1765 | Called after stalking. Since pt-stalk stalks forever by default, |
272 | @@ -1840,6 +1863,22 @@ | |||
273 | 1840 | 1863 | ||
274 | 1841 | The variable to compare against the threshold. See L<"--function"> for details. | 1864 | The variable to compare against the threshold. See L<"--function"> for details. |
275 | 1842 | 1865 | ||
276 | 1866 | =item --verbose | ||
277 | 1867 | |||
278 | 1868 | type: int; default: 2 | ||
279 | 1869 | |||
280 | 1870 | Print more or less information while running. Since the tool is designed | ||
281 | 1871 | to be a long-running daemon, the default verbosity level only prints the | ||
282 | 1872 | most important information. If you run the tool interactively, you may | ||
283 | 1873 | want to use a higher verbosity level. | ||
284 | 1874 | |||
285 | 1875 | LEVEL PRINTS | ||
286 | 1876 | ===== ===================================== | ||
287 | 1877 | 0 Errors | ||
288 | 1878 | 1 Warnings | ||
289 | 1879 | 2 Matching triggers and collection info | ||
290 | 1880 | 3 Non-matching triggers | ||
291 | 1881 | |||
292 | 1843 | =item --version | 1882 | =item --version |
293 | 1844 | 1883 | ||
294 | 1845 | Print tool's version and exit. | 1884 | Print tool's version and exit. |
295 | 1846 | 1885 | ||
296 | === modified file 'bin/pt-summary' | |||
297 | --- bin/pt-summary 2013-01-03 00:54:18 +0000 | |||
298 | +++ bin/pt-summary 2013-01-24 19:10:25 +0000 | |||
299 | @@ -29,23 +29,32 @@ | |||
300 | 29 | PTDEBUG="${PTDEBUG:-""}" | 29 | PTDEBUG="${PTDEBUG:-""}" |
301 | 30 | EXIT_STATUS=0 | 30 | EXIT_STATUS=0 |
302 | 31 | 31 | ||
303 | 32 | ts() { | ||
304 | 33 | TS=$(date +%F-%T | tr ':-' '_') | ||
305 | 34 | echo "$TS $*" | ||
306 | 35 | } | ||
307 | 36 | |||
308 | 37 | info() { | ||
309 | 38 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
310 | 39 | } | ||
311 | 40 | |||
312 | 32 | log() { | 41 | log() { |
315 | 33 | TS=$(date +%F-%T | tr ':-' '_'); | 42 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" |
314 | 34 | echo "$TS $*" | ||
316 | 35 | } | 43 | } |
317 | 36 | 44 | ||
318 | 37 | warn() { | 45 | warn() { |
320 | 38 | log "$*" >&2 | 46 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 |
321 | 39 | EXIT_STATUS=1 | 47 | EXIT_STATUS=1 |
322 | 40 | } | 48 | } |
323 | 41 | 49 | ||
324 | 42 | die() { | 50 | die() { |
326 | 43 | warn "$*" | 51 | ts "$*" >&2 |
327 | 52 | EXIT_STATUS=1 | ||
328 | 44 | exit 1 | 53 | exit 1 |
329 | 45 | } | 54 | } |
330 | 46 | 55 | ||
331 | 47 | _d () { | 56 | _d () { |
333 | 48 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2 | 57 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 |
334 | 49 | } | 58 | } |
335 | 50 | 59 | ||
336 | 51 | # ########################################################################### | 60 | # ########################################################################### |
337 | @@ -2280,7 +2289,7 @@ | |||
338 | 2280 | # Execute the program if it was not included from another file. This makes it | 2289 | # Execute the program if it was not included from another file. This makes it |
339 | 2281 | # possible to include without executing, and thus test. | 2290 | # possible to include without executing, and thus test. |
340 | 2282 | if [ "${0##*/}" = "$TOOL" ] \ | 2291 | if [ "${0##*/}" = "$TOOL" ] \ |
342 | 2283 | || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then | 2292 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
343 | 2284 | 2293 | ||
344 | 2285 | # Set up temporary dir. | 2294 | # Set up temporary dir. |
345 | 2286 | mk_tmpdir | 2295 | mk_tmpdir |
346 | 2287 | 2296 | ||
347 | === modified file 'lib/PerconaTest.pm' | |||
348 | --- lib/PerconaTest.pm 2013-01-03 00:19:16 +0000 | |||
349 | +++ lib/PerconaTest.pm 2013-01-24 19:10:25 +0000 | |||
350 | @@ -58,7 +58,6 @@ | |||
351 | 58 | wait_until | 58 | wait_until |
352 | 59 | wait_for | 59 | wait_for |
353 | 60 | wait_until_slave_running | 60 | wait_until_slave_running |
354 | 61 | wait_until_no_lag | ||
355 | 62 | test_log_parser | 61 | test_log_parser |
356 | 63 | test_protocol_parser | 62 | test_protocol_parser |
357 | 64 | test_packet_parser | 63 | test_packet_parser |
358 | @@ -325,6 +324,39 @@ | |||
359 | 325 | ); | 324 | ); |
360 | 326 | }; | 325 | }; |
361 | 327 | 326 | ||
362 | 327 | sub kill_program { | ||
363 | 328 | my (%args) = @_; | ||
364 | 329 | |||
365 | 330 | my $pid_file = $args{pid_file}; | ||
366 | 331 | my $pid = $args{pid}; | ||
367 | 332 | |||
368 | 333 | if ( $pid_file ) { | ||
369 | 334 | chomp($pid = `cat $pid_file 2>/dev/null`); | ||
370 | 335 | } | ||
371 | 336 | |||
372 | 337 | if ( $pid ) { | ||
373 | 338 | PTDEVDEBUG && _d('Killing PID', $pid); | ||
374 | 339 | kill(15, $pid); | ||
375 | 340 | wait_until( | ||
376 | 341 | sub { my $is_alive = kill(0, $pid); return !$is_alive; }, | ||
377 | 342 | 1.5, # sleep between tries | ||
378 | 343 | 15, # max time to try | ||
379 | 344 | ); | ||
380 | 345 | if ( kill(0, $pid) ) { | ||
381 | 346 | warn "PID $pid did not die; using kill -9\n"; | ||
382 | 347 | kill(9, $pid); | ||
383 | 348 | } | ||
384 | 349 | } | ||
385 | 350 | else { | ||
386 | 351 | PTDEVDEBUG && _d('No PID to kill'); | ||
387 | 352 | } | ||
388 | 353 | |||
389 | 354 | if ( $pid_file && -f $pid_file ) { | ||
390 | 355 | PTDEVDEBUG && _d('Removing PID file', $pid_file); | ||
391 | 356 | unlink $pid_file; | ||
392 | 357 | } | ||
393 | 358 | } | ||
394 | 359 | |||
395 | 328 | sub not_running { | 360 | sub not_running { |
396 | 329 | my ($cmd) = @_; | 361 | my ($cmd) = @_; |
397 | 330 | PTDEVDEBUG && _d('Wait until not running:', $cmd); | 362 | PTDEVDEBUG && _d('Wait until not running:', $cmd); |
398 | 331 | 363 | ||
399 | === modified file 'lib/bash/log_warn_die.sh' | |||
400 | --- lib/bash/log_warn_die.sh 2012-08-13 15:23:18 +0000 | |||
401 | +++ lib/bash/log_warn_die.sh 2013-01-24 19:10:25 +0000 | |||
402 | @@ -28,23 +28,32 @@ | |||
403 | 28 | PTDEBUG="${PTDEBUG:-""}" | 28 | PTDEBUG="${PTDEBUG:-""}" |
404 | 29 | EXIT_STATUS=0 | 29 | EXIT_STATUS=0 |
405 | 30 | 30 | ||
406 | 31 | ts() { | ||
407 | 32 | TS=$(date +%F-%T | tr ':-' '_') | ||
408 | 33 | echo "$TS $*" | ||
409 | 34 | } | ||
410 | 35 | |||
411 | 36 | info() { | ||
412 | 37 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
413 | 38 | } | ||
414 | 39 | |||
415 | 31 | log() { | 40 | log() { |
418 | 32 | TS=$(date +%F-%T | tr ':-' '_'); | 41 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" |
417 | 33 | echo "$TS $*" | ||
419 | 34 | } | 42 | } |
420 | 35 | 43 | ||
421 | 36 | warn() { | 44 | warn() { |
423 | 37 | log "$*" >&2 | 45 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 |
424 | 38 | EXIT_STATUS=1 | 46 | EXIT_STATUS=1 |
425 | 39 | } | 47 | } |
426 | 40 | 48 | ||
427 | 41 | die() { | 49 | die() { |
429 | 42 | warn "$*" | 50 | ts "$*" >&2 |
430 | 51 | EXIT_STATUS=1 | ||
431 | 43 | exit 1 | 52 | exit 1 |
432 | 44 | } | 53 | } |
433 | 45 | 54 | ||
434 | 46 | _d () { | 55 | _d () { |
436 | 47 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2 | 56 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 |
437 | 48 | } | 57 | } |
438 | 49 | 58 | ||
439 | 50 | # ########################################################################### | 59 | # ########################################################################### |
440 | 51 | 60 | ||
441 | === modified file 't/lib/bash/log_warn_die.sh' | |||
442 | --- t/lib/bash/log_warn_die.sh 2012-06-11 20:51:43 +0000 | |||
443 | +++ t/lib/bash/log_warn_die.sh 2013-01-24 19:10:25 +0000 | |||
444 | @@ -1,17 +1,15 @@ | |||
445 | 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
446 | 2 | 2 | ||
447 | 3 | plan 6 | ||
448 | 4 | |||
449 | 5 | source "$LIB_DIR/log_warn_die.sh" | 3 | source "$LIB_DIR/log_warn_die.sh" |
450 | 6 | 4 | ||
452 | 7 | log "Hello world!" > $TEST_PT_TMPDIR/log | 5 | log "Hello world A!" > $TEST_PT_TMPDIR/log |
453 | 8 | cmd_ok \ | 6 | cmd_ok \ |
455 | 9 | "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \ | 7 | "grep -q 'Hello world A!' $TEST_PT_TMPDIR/log" \ |
456 | 10 | "log msg" | 8 | "log msg" |
457 | 11 | 9 | ||
459 | 12 | log "Hello" "world!" > $TEST_PT_TMPDIR/log | 10 | log "Hello" "world B!" > $TEST_PT_TMPDIR/log |
460 | 13 | cmd_ok \ | 11 | cmd_ok \ |
462 | 14 | "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \ | 12 | "grep -q 'Hello world B!' $TEST_PT_TMPDIR/log" \ |
463 | 15 | "log msg msg" | 13 | "log msg msg" |
464 | 16 | 14 | ||
465 | 17 | is \ | 15 | is \ |
466 | @@ -19,14 +17,14 @@ | |||
467 | 19 | "0" \ | 17 | "0" \ |
468 | 20 | "Exit status 0" | 18 | "Exit status 0" |
469 | 21 | 19 | ||
471 | 22 | warn "Hello world!" 2> $TEST_PT_TMPDIR/log | 20 | warn "Hello world C!" 2> $TEST_PT_TMPDIR/log |
472 | 23 | cmd_ok \ | 21 | cmd_ok \ |
474 | 24 | "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \ | 22 | "grep -q 'Hello world C!' $TEST_PT_TMPDIR/log" \ |
475 | 25 | "warn msg" | 23 | "warn msg" |
476 | 26 | 24 | ||
478 | 27 | warn "Hello" "world!" 2> $TEST_PT_TMPDIR/log | 25 | warn "Hello" "world D!" 2> $TEST_PT_TMPDIR/log |
479 | 28 | cmd_ok \ | 26 | cmd_ok \ |
481 | 29 | "grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \ | 27 | "grep -q 'Hello world D!' $TEST_PT_TMPDIR/log" \ |
482 | 30 | "warn msg msg" | 28 | "warn msg msg" |
483 | 31 | 29 | ||
484 | 32 | is \ | 30 | is \ |
485 | @@ -34,6 +32,81 @@ | |||
486 | 34 | "1" \ | 32 | "1" \ |
487 | 35 | "Exit status 1" | 33 | "Exit status 1" |
488 | 36 | 34 | ||
489 | 35 | OPT_VERBOSE=1 | ||
490 | 36 | |||
491 | 37 | info "Hello world 1!" > $TEST_PT_TMPDIR/log | ||
492 | 38 | file_is_empty \ | ||
493 | 39 | $TEST_PT_TMPDIR/log \ | ||
494 | 40 | "verbose=1 info" | ||
495 | 41 | |||
496 | 42 | log "Hello world 2!" > $TEST_PT_TMPDIR/log | ||
497 | 43 | file_is_empty \ | ||
498 | 44 | $TEST_PT_TMPDIR/log \ | ||
499 | 45 | "verbose=1 log" | ||
500 | 46 | |||
501 | 47 | warn "Hello world 3!" > $TEST_PT_TMPDIR/log 2>&1 | ||
502 | 48 | file_contains \ | ||
503 | 49 | $TEST_PT_TMPDIR/log \ | ||
504 | 50 | "Hello world 3!" \ | ||
505 | 51 | "verbose=1 warn" | ||
506 | 52 | |||
507 | 53 | OPT_VERBOSE=2 | ||
508 | 54 | |||
509 | 55 | info "Hello world 4!" > $TEST_PT_TMPDIR/log | ||
510 | 56 | file_is_empty \ | ||
511 | 57 | $TEST_PT_TMPDIR/log \ | ||
512 | 58 | "verbose=2 info" | ||
513 | 59 | |||
514 | 60 | log "Hello world 5!" > $TEST_PT_TMPDIR/log | ||
515 | 61 | file_contains \ | ||
516 | 62 | $TEST_PT_TMPDIR/log \ | ||
517 | 63 | "Hello world 5!" \ | ||
518 | 64 | "verbose=2 log" | ||
519 | 65 | |||
520 | 66 | warn "Hello world 6!" > $TEST_PT_TMPDIR/log 2>&1 | ||
521 | 67 | file_contains \ | ||
522 | 68 | $TEST_PT_TMPDIR/log \ | ||
523 | 69 | "Hello world 6!" \ | ||
524 | 70 | "verbose=2 warn" | ||
525 | 71 | |||
526 | 72 | OPT_VERBOSE=3 | ||
527 | 73 | |||
528 | 74 | info "Hello world 7!" > $TEST_PT_TMPDIR/log | ||
529 | 75 | file_contains \ | ||
530 | 76 | $TEST_PT_TMPDIR/log \ | ||
531 | 77 | "Hello world 7!" \ | ||
532 | 78 | "verbose=3 info" | ||
533 | 79 | |||
534 | 80 | log "Hello world 8!" > $TEST_PT_TMPDIR/log | ||
535 | 81 | file_contains \ | ||
536 | 82 | $TEST_PT_TMPDIR/log \ | ||
537 | 83 | "Hello world 8!" \ | ||
538 | 84 | "verbose=3 log" | ||
539 | 85 | |||
540 | 86 | warn "Hello world 9!" > $TEST_PT_TMPDIR/log 2>&1 | ||
541 | 87 | file_contains \ | ||
542 | 88 | $TEST_PT_TMPDIR/log \ | ||
543 | 89 | "Hello world 9!" \ | ||
544 | 90 | "verbose=3 warn" | ||
545 | 91 | |||
546 | 92 | OPT_VERBOSE=0 | ||
547 | 93 | |||
548 | 94 | info "Hello world 10!" > $TEST_PT_TMPDIR/log | ||
549 | 95 | file_is_empty \ | ||
550 | 96 | $TEST_PT_TMPDIR/log \ | ||
551 | 97 | "verbose=0 info" | ||
552 | 98 | |||
553 | 99 | log "Hello world 11!" > $TEST_PT_TMPDIR/log | ||
554 | 100 | file_is_empty \ | ||
555 | 101 | $TEST_PT_TMPDIR/log \ | ||
556 | 102 | "verbose=0 log" | ||
557 | 103 | |||
558 | 104 | warn "Hello world 12!" > $TEST_PT_TMPDIR/log 2>&1 | ||
559 | 105 | file_is_empty \ | ||
560 | 106 | $TEST_PT_TMPDIR/log \ | ||
561 | 107 | "verbose=0 warn" | ||
562 | 108 | |||
563 | 37 | # ########################################################################### | 109 | # ########################################################################### |
564 | 38 | # Done | 110 | # Done |
565 | 39 | # ########################################################################### | 111 | # ########################################################################### |
566 | 112 | done_testing | ||
567 | 40 | 113 | ||
568 | === added file 't/pt-stalk/option_sanity.t' | |||
569 | --- t/pt-stalk/option_sanity.t 1970-01-01 00:00:00 +0000 | |||
570 | +++ t/pt-stalk/option_sanity.t 2013-01-24 19:10:25 +0000 | |||
571 | @@ -0,0 +1,24 @@ | |||
572 | 1 | #!/usr/bin/env perl | ||
573 | 2 | |||
574 | 3 | BEGIN { | ||
575 | 4 | die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" | ||
576 | 5 | unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; | ||
577 | 6 | unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; | ||
578 | 7 | }; | ||
579 | 8 | |||
580 | 9 | use strict; | ||
581 | 10 | use warnings FATAL => 'all'; | ||
582 | 11 | use English qw(-no_match_vars); | ||
583 | 12 | use Test::More; | ||
584 | 13 | |||
585 | 14 | use PerconaTest; | ||
586 | 15 | |||
587 | 16 | my $output = `$trunk/bin/pt-stalk --help`; | ||
588 | 17 | |||
589 | 18 | like( | ||
590 | 19 | $output, | ||
591 | 20 | qr/^\s+--verbose\s+2/m, | ||
592 | 21 | "Default --verbose=2" | ||
593 | 22 | ); | ||
594 | 23 | |||
595 | 24 | done_testing; | ||
596 | 0 | 25 | ||
597 | === modified file 't/pt-stalk/pt-stalk.t' | |||
598 | --- t/pt-stalk/pt-stalk.t 2012-10-23 23:51:59 +0000 | |||
599 | +++ t/pt-stalk/pt-stalk.t 2013-01-24 19:10:25 +0000 | |||
600 | @@ -28,11 +28,28 @@ | |||
601 | 28 | my $pid_file = "/tmp/pt-stalk.pid.$PID"; | 28 | my $pid_file = "/tmp/pt-stalk.pid.$PID"; |
602 | 29 | my $log_file = "/tmp/pt-stalk.log.$PID"; | 29 | my $log_file = "/tmp/pt-stalk.log.$PID"; |
603 | 30 | my $dest = "/tmp/pt-stalk.collect.$PID"; | 30 | my $dest = "/tmp/pt-stalk.collect.$PID"; |
604 | 31 | my $int_file = "/tmp/pt-stalk-after-interval-sleep"; | ||
605 | 31 | my $pid; | 32 | my $pid; |
606 | 32 | 33 | ||
610 | 33 | diag(`rm $pid_file 2>/dev/null`); | 34 | sub cleanup { |
611 | 34 | diag(`rm $log_file 2>/dev/null`); | 35 | diag(`rm $pid_file $log_file $int_file 2>/dev/null`); |
612 | 35 | diag(`rm -rf $dest 2>/dev/null`); | 36 | diag(`rm -rf $dest 2>/dev/null`); |
613 | 37 | } | ||
614 | 38 | |||
615 | 39 | sub wait_n_cycles { | ||
616 | 40 | my ($n) = @_; | ||
617 | 41 | PerconaTest::wait_until( | ||
618 | 42 | sub { | ||
619 | 43 | return 0 unless -f "$dest/after_interval_sleep"; | ||
620 | 44 | my $n_cycles = `wc -l "$dest/after_interval_sleep" | awk '{print \$1}'`; | ||
621 | 45 | $n_cycles ||= ''; | ||
622 | 46 | chomp($n_cycles); | ||
623 | 47 | return ($n_cycles || 0) >= $n; | ||
624 | 48 | }, | ||
625 | 49 | 1.5, | ||
626 | 50 | 15 | ||
627 | 51 | ); | ||
628 | 52 | } | ||
629 | 36 | 53 | ||
630 | 37 | # ########################################################################### | 54 | # ########################################################################### |
631 | 38 | # Test that it won't run if can't connect to MySQL. | 55 | # Test that it won't run if can't connect to MySQL. |
632 | @@ -56,11 +73,14 @@ | |||
633 | 56 | # ########################################################################### | 73 | # ########################################################################### |
634 | 57 | # Test that it runs and dies normally. | 74 | # Test that it runs and dies normally. |
635 | 58 | # ########################################################################### | 75 | # ########################################################################### |
641 | 59 | diag(`rm $pid_file 2>/dev/null`); | 76 | |
642 | 60 | diag(`rm $log_file 2>/dev/null`); | 77 | cleanup(); |
643 | 61 | diag(`rm -rf $dest 2>/dev/null`); | 78 | |
644 | 62 | 79 | # As of v2.1.9 when --verbose was added, non-matching checks are not | |
645 | 63 | $retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest -- --defaults-file=$cnf"); | 80 | # printed by default. So we use the --plugin to tell us when the tool |
646 | 81 | # has completed a cycle. | ||
647 | 82 | |||
648 | 83 | $retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf"); | ||
649 | 64 | 84 | ||
650 | 65 | is( | 85 | is( |
651 | 66 | $retval >> 8, | 86 | $retval >> 8, |
652 | @@ -94,21 +114,16 @@ | |||
653 | 94 | "pt-stalk is running" | 114 | "pt-stalk is running" |
654 | 95 | ); | 115 | ); |
655 | 96 | 116 | ||
657 | 97 | PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null"); | 117 | wait_n_cycles(2); |
658 | 118 | PerconaTest::kill_program(pid_file => $pid_file); | ||
659 | 119 | |||
660 | 98 | $output = `cat $log_file 2>/dev/null`; | 120 | $output = `cat $log_file 2>/dev/null`; |
662 | 99 | like( | 121 | unlike( |
663 | 100 | $output, | 122 | $output, |
664 | 101 | qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/, | 123 | qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/, |
666 | 102 | "Check results logged" | 124 | "Non-matching results not logged because --verbose=2" |
667 | 103 | ) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`); | 125 | ) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`); |
668 | 104 | 126 | ||
669 | 105 | $retval = system("kill $pid 2>/dev/null"); | ||
670 | 106 | is( | ||
671 | 107 | $retval >> 0, | ||
672 | 108 | 0, | ||
673 | 109 | "Killed pt-stalk" | ||
674 | 110 | ); | ||
675 | 111 | |||
676 | 112 | PerconaTest::wait_until(sub { !-f $pid_file }); | 127 | PerconaTest::wait_until(sub { !-f $pid_file }); |
677 | 113 | 128 | ||
678 | 114 | ok( | 129 | ok( |
679 | @@ -123,12 +138,56 @@ | |||
680 | 123 | "Caught signal logged" | 138 | "Caught signal logged" |
681 | 124 | ) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`); | 139 | ) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`); |
682 | 125 | 140 | ||
683 | 141 | # ############################################################################# | ||
684 | 142 | # --verbose 3 (non-matching results) | ||
685 | 143 | # ############################################################################# | ||
686 | 144 | |||
687 | 145 | cleanup(); | ||
688 | 146 | |||
689 | 147 | $retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 3 -- --defaults-file=$cnf"); | ||
690 | 148 | |||
691 | 149 | PerconaTest::wait_for_files($pid_file, $log_file); | ||
692 | 150 | PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null"); | ||
693 | 151 | PerconaTest::kill_program(pid_file => $pid_file); | ||
694 | 152 | |||
695 | 153 | $output = `cat $log_file 2>/dev/null`; | ||
696 | 154 | like( | ||
697 | 155 | $output, | ||
698 | 156 | qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/, | ||
699 | 157 | "Matching results logged with --verbose 3" | ||
700 | 158 | ) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`); | ||
701 | 159 | |||
702 | 160 | # ############################################################################# | ||
703 | 161 | # --verbose 1 (just errors and warnings) | ||
704 | 162 | # ############################################################################# | ||
705 | 163 | |||
706 | 164 | cleanup(); | ||
707 | 165 | |||
708 | 166 | $retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 1 --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf"); | ||
709 | 167 | |||
710 | 168 | PerconaTest::wait_for_files($pid_file, $log_file); | ||
711 | 169 | wait_n_cycles(2); | ||
712 | 170 | PerconaTest::kill_program(pid_file => $pid_file); | ||
713 | 171 | |||
714 | 172 | $output = `cat $log_file 2>/dev/null`; | ||
715 | 173 | |||
716 | 174 | like( | ||
717 | 175 | $output, | ||
718 | 176 | qr/Caught signal, exiting/, | ||
719 | 177 | "Warning logged (--verbose 1)" | ||
720 | 178 | ); | ||
721 | 179 | |||
722 | 180 | unlike( | ||
723 | 181 | $output, | ||
724 | 182 | qr/Start|Collect|Check/i, | ||
725 | 183 | "No run info log (--verbose 1)" | ||
726 | 184 | ); | ||
727 | 185 | |||
728 | 126 | # ########################################################################### | 186 | # ########################################################################### |
729 | 127 | # Test collect. | 187 | # Test collect. |
730 | 128 | # ########################################################################### | 188 | # ########################################################################### |
734 | 129 | diag(`rm $pid_file 2>/dev/null`); | 189 | |
735 | 130 | diag(`rm $log_file 2>/dev/null`); | 190 | cleanup(); |
733 | 131 | diag(`rm $dest/* 2>/dev/null`); | ||
736 | 132 | 191 | ||
737 | 133 | # We'll have to watch Uptime since it's the only status var that's going | 192 | # We'll have to watch Uptime since it's the only status var that's going |
738 | 134 | # to be predictable. | 193 | # to be predictable. |
739 | @@ -180,10 +239,10 @@ | |||
740 | 180 | "Trigger file logs how pt-stalk was ran" | 239 | "Trigger file logs how pt-stalk was ran" |
741 | 181 | ); | 240 | ); |
742 | 182 | 241 | ||
744 | 183 | chomp($output = `cat $log_file 2>/dev/null | grep 'Collector PID'`); | 242 | chomp($output = `cat $log_file 2>/dev/null | grep 'Collect [0-9] PID'`); |
745 | 184 | like( | 243 | like( |
746 | 185 | $output, | 244 | $output, |
748 | 186 | qr/Collector PID \d+/, | 245 | qr/Collect 1 PID \d+/, |
749 | 187 | "Collector PID logged" | 246 | "Collector PID logged" |
750 | 188 | ) | 247 | ) |
751 | 189 | or diag( | 248 | or diag( |
752 | @@ -195,9 +254,8 @@ | |||
753 | 195 | # ########################################################################### | 254 | # ########################################################################### |
754 | 196 | # Triggered but --no-collect. | 255 | # Triggered but --no-collect. |
755 | 197 | # ########################################################################### | 256 | # ########################################################################### |
759 | 198 | diag(`rm $pid_file 2>/dev/null`); | 257 | |
760 | 199 | diag(`rm $log_file 2>/dev/null`); | 258 | cleanup(); |
758 | 200 | diag(`rm $dest/* 2>/dev/null`); | ||
761 | 201 | 259 | ||
762 | 202 | (undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'"); | 260 | (undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'"); |
763 | 203 | $threshold = $uptime + 2; | 261 | $threshold = $uptime + 2; |
764 | @@ -209,7 +267,7 @@ | |||
765 | 209 | $output = `cat $log_file 2>/dev/null`; | 267 | $output = `cat $log_file 2>/dev/null`; |
766 | 210 | like( | 268 | like( |
767 | 211 | $output, | 269 | $output, |
769 | 212 | qr/Collect triggered/, | 270 | qr/Collect 1 triggered/, |
770 | 213 | "Collect triggered" | 271 | "Collect triggered" |
771 | 214 | ); | 272 | ); |
772 | 215 | 273 | ||
773 | @@ -227,6 +285,8 @@ | |||
774 | 227 | # --config | 285 | # --config |
775 | 228 | # ############################################################################# | 286 | # ############################################################################# |
776 | 229 | 287 | ||
777 | 288 | cleanup(); | ||
778 | 289 | |||
779 | 230 | diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`); | 290 | diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`); |
780 | 231 | diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`); | 291 | diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`); |
781 | 232 | 292 | ||
782 | @@ -254,9 +314,8 @@ | |||
783 | 254 | # ############################################################################# | 314 | # ############################################################################# |
784 | 255 | # Don't stalk, just collect. | 315 | # Don't stalk, just collect. |
785 | 256 | # ############################################################################# | 316 | # ############################################################################# |
789 | 257 | diag(`rm $pid_file 2>/dev/null`); | 317 | |
790 | 258 | diag(`rm $log_file 2>/dev/null`); | 318 | cleanup(); |
788 | 259 | diag(`rm $dest/* 2>/dev/null`); | ||
791 | 260 | 319 | ||
792 | 261 | $retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1"); | 320 | $retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1"); |
793 | 262 | 321 | ||
794 | @@ -343,9 +402,7 @@ | |||
795 | 343 | # ############################################################################# | 402 | # ############################################################################# |
796 | 344 | # Done. | 403 | # Done. |
797 | 345 | # ############################################################################# | 404 | # ############################################################################# |
800 | 346 | diag(`rm $pid_file 2>/dev/null`); | 405 | cleanup(); |
799 | 347 | diag(`rm $log_file 2>/dev/null`); | ||
801 | 348 | diag(`rm -rf $dest 2>/dev/null`); | 406 | diag(`rm -rf $dest 2>/dev/null`); |
802 | 349 | ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); | 407 | ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); |
803 | 350 | |||
804 | 351 | done_testing; | 408 | done_testing; |
805 | 352 | 409 | ||
806 | === added file 't/pt-stalk/samples/plugin002.sh' | |||
807 | --- t/pt-stalk/samples/plugin002.sh 1970-01-01 00:00:00 +0000 | |||
808 | +++ t/pt-stalk/samples/plugin002.sh 2013-01-24 19:10:25 +0000 | |||
809 | @@ -0,0 +1,5 @@ | |||
810 | 1 | #!/bin/sh | ||
811 | 2 | |||
812 | 3 | after_interval_sleep() { | ||
813 | 4 | date >> "$OPT_DEST/after_interval_sleep" | ||
814 | 5 | } | ||
815 | 0 | 6 | ||
816 | === modified file 'util/test-bash-functions' | |||
817 | --- util/test-bash-functions 2012-08-22 20:50:11 +0000 | |||
818 | +++ util/test-bash-functions 2013-01-24 19:10:25 +0000 | |||
819 | @@ -100,6 +100,7 @@ | |||
820 | 100 | result() { | 100 | result() { |
821 | 101 | local result=$1 | 101 | local result=$1 |
822 | 102 | local test_name=${2:-""} | 102 | local test_name=${2:-""} |
823 | 103 | testno=$((testno + 1)) | ||
824 | 103 | if [ $result -eq 0 ]; then | 104 | if [ $result -eq 0 ]; then |
825 | 104 | echo "ok $testno - $TEST_FILE $test_name" | 105 | echo "ok $testno - $TEST_FILE $test_name" |
826 | 105 | else | 106 | else |
827 | @@ -110,7 +111,6 @@ | |||
828 | 110 | cat $TEST_PT_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2 | 111 | cat $TEST_PT_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2 |
829 | 111 | fi | 112 | fi |
830 | 112 | fi | 113 | fi |
831 | 113 | testno=$((testno + 1)) | ||
832 | 114 | return $result | 114 | return $result |
833 | 115 | } | 115 | } |
834 | 116 | 116 | ||
835 | @@ -121,19 +121,21 @@ | |||
836 | 121 | fi | 121 | fi |
837 | 122 | } | 122 | } |
838 | 123 | 123 | ||
839 | 124 | done_testing() { | ||
840 | 125 | echo "1..$testno" | ||
841 | 126 | } | ||
842 | 127 | |||
843 | 124 | # | 128 | # |
844 | 125 | # The following subs are for the test files to call. | 129 | # The following subs are for the test files to call. |
845 | 126 | # | 130 | # |
846 | 127 | 131 | ||
847 | 128 | pass() { | 132 | pass() { |
848 | 129 | local reason="${1:-""}" | 133 | local reason="${1:-""}" |
849 | 130 | |||
850 | 131 | result 0 "$reason" | 134 | result 0 "$reason" |
851 | 132 | } | 135 | } |
852 | 133 | 136 | ||
853 | 134 | fail() { | 137 | fail() { |
854 | 135 | local reason="${1:-""}" | 138 | local reason="${1:-""}" |
855 | 136 | |||
856 | 137 | result 1 "$reason" | 139 | result 1 "$reason" |
857 | 138 | } | 140 | } |
858 | 139 | 141 | ||
859 | @@ -177,6 +179,42 @@ | |||
860 | 177 | result $? "$test_name" | 179 | result $? "$test_name" |
861 | 178 | } | 180 | } |
862 | 179 | 181 | ||
863 | 182 | file_is_empty() { | ||
864 | 183 | local file=$1 | ||
865 | 184 | local test_name=${2:-""} | ||
866 | 185 | test_command="-s $file" | ||
867 | 186 | if [ ! -f "$file" ]; then | ||
868 | 187 | echo "$file does not exist" > $TEST_PT_TMPDIR/failed_result | ||
869 | 188 | result 1 "$test_name" | ||
870 | 189 | fi | ||
871 | 190 | if [ -s "$file" ]; then | ||
872 | 191 | echo "$file is not empty:" > $TEST_PT_TMPDIR/failed_result | ||
873 | 192 | cat "$file" >> $TEST_PT_TMPDIR/failed_result | ||
874 | 193 | result 1 "$test_name" | ||
875 | 194 | else | ||
876 | 195 | result 0 "$test_name" | ||
877 | 196 | fi | ||
878 | 197 | } | ||
879 | 198 | |||
880 | 199 | file_contains() { | ||
881 | 200 | local file="$1" | ||
882 | 201 | local pat="$2" | ||
883 | 202 | local test_name=${3:-""} | ||
884 | 203 | test_command="grep -q '$pat' '$file'" | ||
885 | 204 | if [ ! -f "$file" ]; then | ||
886 | 205 | echo "$file does not exist" > $TEST_PT_TMPDIR/failed_result | ||
887 | 206 | result 1 "$test_name" | ||
888 | 207 | fi | ||
889 | 208 | grep -q "$pat" $file | ||
890 | 209 | if [ $? -ne 0 ]; then | ||
891 | 210 | echo "$file does not contain '$pat':" > $TEST_PT_TMPDIR/failed_result | ||
892 | 211 | cat "$file" >> $TEST_PT_TMPDIR/failed_result | ||
893 | 212 | result 1 "$test_name" | ||
894 | 213 | else | ||
895 | 214 | result 0 "$test_name" | ||
896 | 215 | fi | ||
897 | 216 | } | ||
898 | 217 | |||
899 | 180 | cmd_ok() { | 218 | cmd_ok() { |
900 | 181 | local test_command=$1 | 219 | local test_command=$1 |
901 | 182 | local test_name=${2:-""} | 220 | local test_name=${2:-""} |
902 | @@ -226,7 +264,7 @@ | |||
903 | 226 | # Script starts here | 264 | # Script starts here |
904 | 227 | # ############################################################################ | 265 | # ############################################################################ |
905 | 228 | 266 | ||
907 | 229 | testno=1 | 267 | testno=0 |
908 | 230 | failed_tests=0 | 268 | failed_tests=0 |
909 | 231 | 269 | ||
910 | 232 | if [ $# -eq 0 ]; then | 270 | if [ $# -eq 0 ]; then |