Merge lp:~percona-toolkit-dev/percona-toolkit/not-all-scripts-recognize-no-version-check-1361293 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.12

Proposed by Frank Cizmich
Status: Merged
Merged at revision: 629
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/not-all-scripts-recognize-no-version-check-1361293
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.12
Diff against target: 402 lines (+141/-27)
17 files modified
bin/pt-align (+8/-0)
bin/pt-fifo-split (+8/-0)
bin/pt-fingerprint (+8/-0)
bin/pt-ioprofile (+4/-1)
bin/pt-mext (+29/-23)
bin/pt-mysql-summary (+2/-0)
bin/pt-pmp (+4/-1)
bin/pt-show-grants (+8/-0)
bin/pt-sift (+4/-1)
bin/pt-slave-find (+8/-0)
bin/pt-stalk (+4/-1)
bin/pt-summary (+2/-0)
bin/pt-table-usage (+8/-0)
bin/pt-visual-explain (+8/-0)
lib/OptionParser.pm (+10/-0)
lib/bash/parse_options.sh (+3/-0)
t/lib/OptionParser.t (+23/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/not-all-scripts-recognize-no-version-check-1361293
Reviewer Review Type Date Requested Status
Daniel Nichter Needs Fixing
Review via email: mp+237832@code.launchpad.net

Description of the change

Problem:
When option no-version-check was put in a global configuration file (to avoid unwanted internet connection) , many tools failed as they did not recognize the option.

Fix:
Bash tools were instructed to silently ignore it if it was read from a config file (none does version-check right now)
Perl tools were instructed to ignore it if it was read from a config file AND it was unsupported.

Modification was done on OptionParser.pm and parse_options.sh , and updated to the rest of the tools.

Note:
pt-mext bash script had differences with it's embedded parse_options module ( the _parse_pod function seemed to pipe the source file through a perl code, rather than having the perl code open and read the file ) ... but nevertheless after updating tests ran ok.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

In the comments there's a question and a minor style change for a line in parse_options.sh.

review: Needs Fixing
Revision history for this message
Frank Cizmich (frank-cizmich) wrote :

Answered in the comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-align'
2--- bin/pt-align 2014-09-25 13:48:22 +0000
3+++ bin/pt-align 2014-10-09 17:53:04 +0000
4@@ -901,6 +901,14 @@
5 $parse = 0;
6 next LINE;
7 }
8+
9+ if ( $parse
10+ && !$self->has('version-check')
11+ && $line =~ /version-check/
12+ ) {
13+ next LINE;
14+ }
15+
16 if ( $parse
17 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
18 ) {
19
20=== modified file 'bin/pt-fifo-split'
21--- bin/pt-fifo-split 2014-09-25 13:48:22 +0000
22+++ bin/pt-fifo-split 2014-10-09 17:53:04 +0000
23@@ -902,6 +902,14 @@
24 $parse = 0;
25 next LINE;
26 }
27+
28+ if ( $parse
29+ && !$self->has('version-check')
30+ && $line =~ /version-check/
31+ ) {
32+ next LINE;
33+ }
34+
35 if ( $parse
36 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
37 ) {
38
39=== modified file 'bin/pt-fingerprint'
40--- bin/pt-fingerprint 2014-09-25 13:48:22 +0000
41+++ bin/pt-fingerprint 2014-10-09 17:53:04 +0000
42@@ -903,6 +903,14 @@
43 $parse = 0;
44 next LINE;
45 }
46+
47+ if ( $parse
48+ && !$self->has('version-check')
49+ && $line =~ /version-check/
50+ ) {
51+ next LINE;
52+ }
53+
54 if ( $parse
55 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
56 ) {
57
58=== modified file 'bin/pt-ioprofile'
59--- bin/pt-ioprofile 2014-09-25 13:48:22 +0000
60+++ bin/pt-ioprofile 2014-10-09 17:53:04 +0000
61@@ -86,9 +86,10 @@
62
63 usage_or_errors() {
64 local file="$1"
65+ local version=""
66
67 if [ "$OPT_VERSION" ]; then
68- local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
69+ version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
70 echo "$version"
71 return 1
72 fi
73@@ -310,6 +311,8 @@
74
75 [ "$config_opt" = "" ] && continue
76
77+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
78+
79 if ! [ "$HAVE_EXT_ARGV" ]; then
80 config_opt="--$config_opt"
81 fi
82
83=== modified file 'bin/pt-mext'
84--- bin/pt-mext 2014-09-25 13:48:22 +0000
85+++ bin/pt-mext 2014-10-09 17:53:04 +0000
86@@ -251,34 +251,38 @@
87 _parse_pod() {
88 local file="$1"
89
90- cat "$file" | PO_DIR="$PO_DIR" perl -ne '
91- BEGIN { $/ = ""; }
92- next unless $_ =~ m/^=head1 OPTIONS/;
93- while ( defined(my $para = <>) ) {
94- last if $para =~ m/^=head1/;
95- chomp;
96- if ( $para =~ m/^=item --(\S+)/ ) {
97- my $opt = $1;
98- my $file = "$ENV{PO_DIR}/$opt";
99- open my $opt_fh, ">", $file or die "Cannot open $file: $!";
100- print $opt_fh "long:$opt\n";
101- $para = <>;
102+ PO_FILE="$file" PO_DIR="$PO_DIR" perl -e '
103+ $/ = "";
104+ my $file = $ENV{PO_FILE};
105+ open my $fh, "<", $file or die "Cannot open $file: $!";
106+ while ( defined(my $para = <$fh>) ) {
107+ next unless $para =~ m/^=head1 OPTIONS/;
108+ while ( defined(my $para = <$fh>) ) {
109+ last if $para =~ m/^=head1/;
110 chomp;
111- if ( $para =~ m/^[a-z ]+:/ ) {
112- map {
113+ if ( $para =~ m/^=item --(\S+)/ ) {
114+ my $opt = $1;
115+ my $file = "$ENV{PO_DIR}/$opt";
116+ open my $opt_fh, ">", $file or die "Cannot open $file: $!";
117+ print $opt_fh "long:$opt\n";
118+ $para = <$fh>;
119+ chomp;
120+ if ( $para =~ m/^[a-z ]+:/ ) {
121+ map {
122+ chomp;
123+ my ($attrib, $val) = split(/: /, $_);
124+ print $opt_fh "$attrib:$val\n";
125+ } split(/; /, $para);
126+ $para = <$fh>;
127 chomp;
128- my ($attrib, $val) = split(/: /, $_);
129- print $opt_fh "$attrib:$val\n";
130- } split(/; /, $para);
131- $para = <>;
132- chomp;
133+ }
134+ my ($desc) = $para =~ m/^([^?.]+)/;
135+ print $opt_fh "desc:$desc.\n";
136+ close $opt_fh;
137 }
138- my ($desc) = $para =~ m/^([^?.]+)/;
139- print $opt_fh "desc:$desc.\n";
140- close $opt_fh;
141 }
142+ last;
143 }
144- last;
145 '
146 }
147
148@@ -348,6 +352,8 @@
149
150 [ "$config_opt" = "" ] && continue
151
152+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
153+
154 if ! [ "$HAVE_EXT_ARGV" ]; then
155 config_opt="--$config_opt"
156 fi
157
158=== modified file 'bin/pt-mysql-summary'
159--- bin/pt-mysql-summary 2014-09-25 13:48:22 +0000
160+++ bin/pt-mysql-summary 2014-10-09 17:53:04 +0000
161@@ -313,6 +313,8 @@
162
163 [ "$config_opt" = "" ] && continue
164
165+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
166+
167 if ! [ "$HAVE_EXT_ARGV" ]; then
168 config_opt="--$config_opt"
169 fi
170
171=== modified file 'bin/pt-pmp'
172--- bin/pt-pmp 2014-09-25 13:48:22 +0000
173+++ bin/pt-pmp 2014-10-09 17:53:04 +0000
174@@ -129,9 +129,10 @@
175
176 usage_or_errors() {
177 local file="$1"
178+ local version=""
179
180 if [ "$OPT_VERSION" ]; then
181- local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
182+ version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
183 echo "$version"
184 return 1
185 fi
186@@ -353,6 +354,8 @@
187
188 [ "$config_opt" = "" ] && continue
189
190+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
191+
192 if ! [ "$HAVE_EXT_ARGV" ]; then
193 config_opt="--$config_opt"
194 fi
195
196=== modified file 'bin/pt-show-grants'
197--- bin/pt-show-grants 2014-09-25 13:48:22 +0000
198+++ bin/pt-show-grants 2014-10-09 17:53:04 +0000
199@@ -903,6 +903,14 @@
200 $parse = 0;
201 next LINE;
202 }
203+
204+ if ( $parse
205+ && !$self->has('version-check')
206+ && $line =~ /version-check/
207+ ) {
208+ next LINE;
209+ }
210+
211 if ( $parse
212 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
213 ) {
214
215=== modified file 'bin/pt-sift'
216--- bin/pt-sift 2014-09-25 13:48:22 +0000
217+++ bin/pt-sift 2014-10-09 17:53:04 +0000
218@@ -127,9 +127,10 @@
219
220 usage_or_errors() {
221 local file="$1"
222+ local version=""
223
224 if [ "$OPT_VERSION" ]; then
225- local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
226+ version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
227 echo "$version"
228 return 1
229 fi
230@@ -351,6 +352,8 @@
231
232 [ "$config_opt" = "" ] && continue
233
234+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
235+
236 if ! [ "$HAVE_EXT_ARGV" ]; then
237 config_opt="--$config_opt"
238 fi
239
240=== modified file 'bin/pt-slave-find'
241--- bin/pt-slave-find 2014-09-25 13:48:22 +0000
242+++ bin/pt-slave-find 2014-10-09 17:53:04 +0000
243@@ -911,6 +911,14 @@
244 $parse = 0;
245 next LINE;
246 }
247+
248+ if ( $parse
249+ && !$self->has('version-check')
250+ && $line =~ /version-check/
251+ ) {
252+ next LINE;
253+ }
254+
255 if ( $parse
256 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
257 ) {
258
259=== modified file 'bin/pt-stalk'
260--- bin/pt-stalk 2014-09-25 13:48:22 +0000
261+++ bin/pt-stalk 2014-10-09 17:53:04 +0000
262@@ -140,9 +140,10 @@
263
264 usage_or_errors() {
265 local file="$1"
266+ local version=""
267
268 if [ "$OPT_VERSION" ]; then
269- local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
270+ version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
271 echo "$version"
272 return 1
273 fi
274@@ -364,6 +365,8 @@
275
276 [ "$config_opt" = "" ] && continue
277
278+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
279+
280 if ! [ "$HAVE_EXT_ARGV" ]; then
281 config_opt="--$config_opt"
282 fi
283
284=== modified file 'bin/pt-summary'
285--- bin/pt-summary 2014-09-25 13:48:22 +0000
286+++ bin/pt-summary 2014-10-09 17:53:04 +0000
287@@ -320,6 +320,8 @@
288
289 [ "$config_opt" = "" ] && continue
290
291+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
292+
293 if ! [ "$HAVE_EXT_ARGV" ]; then
294 config_opt="--$config_opt"
295 fi
296
297=== modified file 'bin/pt-table-usage'
298--- bin/pt-table-usage 2014-09-25 13:48:22 +0000
299+++ bin/pt-table-usage 2014-10-09 17:53:04 +0000
300@@ -1340,6 +1340,14 @@
301 $parse = 0;
302 next LINE;
303 }
304+
305+ if ( $parse
306+ && !$self->has('version-check')
307+ && $line =~ /version-check/
308+ ) {
309+ next LINE;
310+ }
311+
312 if ( $parse
313 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
314 ) {
315
316=== modified file 'bin/pt-visual-explain'
317--- bin/pt-visual-explain 2014-09-25 13:48:22 +0000
318+++ bin/pt-visual-explain 2014-10-09 17:53:04 +0000
319@@ -1577,6 +1577,14 @@
320 $parse = 0;
321 next LINE;
322 }
323+
324+ if ( $parse
325+ && !$self->has('version-check')
326+ && $line =~ /version-check/
327+ ) {
328+ next LINE;
329+ }
330+
331 if ( $parse
332 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
333 ) {
334
335=== modified file 'lib/OptionParser.pm'
336--- lib/OptionParser.pm 2014-05-24 21:36:33 +0000
337+++ lib/OptionParser.pm 2014-10-09 17:53:04 +0000
338@@ -1132,6 +1132,16 @@
339 $parse = 0;
340 next LINE;
341 }
342+
343+ # Silently ignore option [no]-version-check if it is unsupported and it comes from a config file
344+ # TODO: Ideally , this should be generalized for all unsupported options that come from global files
345+ if ( $parse
346+ && !$self->has('version-check')
347+ && $line =~ /version-check/
348+ ) {
349+ next LINE;
350+ }
351+
352 if ( $parse
353 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
354 ) {
355
356=== modified file 'lib/bash/parse_options.sh'
357--- lib/bash/parse_options.sh 2014-07-10 20:15:13 +0000
358+++ lib/bash/parse_options.sh 2014-10-09 17:53:04 +0000
359@@ -347,6 +347,9 @@
360 # Skip blank lines.
361 [ "$config_opt" = "" ] && continue
362
363+ # Skip global option [no]version-check which don't apply
364+ echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
365+
366 # Options in a config file are not prefixed with --,
367 # but command line options are, so one or the other has
368 # to add or remove the -- prefix. We add it for config
369
370=== modified file 't/lib/OptionParser.t'
371--- t/lib/OptionParser.t 2014-05-24 21:36:33 +0000
372+++ t/lib/OptionParser.t 2014-10-09 17:53:04 +0000
373@@ -2141,6 +2141,29 @@
374 'prompt_no_echo outputs prompt to STDERR'
375 );
376
377+# #############################################################################
378+# Issue 1361293: Global config file with no-version-check option makes tools
379+# that don't recognize the option fail.
380+# #############################################################################
381+diag(`echo "no-version-check" > ~/.OptionParser.t.conf`);
382+$o = new OptionParser(
383+ description => 'OptionParser.t parses command line options.',
384+ usage => "$PROGRAM_NAME <options>"
385+);
386+$o->get_specs("$trunk/bin/pt-slave-find"), # doesn't have version-check option
387+$output = output(
388+ sub {
389+ $o->get_opts();
390+ },
391+ stderr=>1
392+ );
393+unlike(
394+ $output,
395+ qr/Unknown option: no-version-check/,
396+ 'no-version-check ignored if unsupported and in config file. issue 1361293'
397+);
398+diag(`rm -rf ~/.OptionParser.t.conf`);
399+
400
401
402 # #############################################################################

Subscribers

People subscribed via source and target branches

to all changes: