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
=== modified file 'bin/pt-align'
--- bin/pt-align 2014-09-25 13:48:22 +0000
+++ bin/pt-align 2014-10-09 17:53:04 +0000
@@ -901,6 +901,14 @@
901 $parse = 0;901 $parse = 0;
902 next LINE;902 next LINE;
903 }903 }
904
905 if ( $parse
906 && !$self->has('version-check')
907 && $line =~ /version-check/
908 ) {
909 next LINE;
910 }
911
904 if ( $parse912 if ( $parse
905 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)913 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
906 ) {914 ) {
907915
=== modified file 'bin/pt-fifo-split'
--- bin/pt-fifo-split 2014-09-25 13:48:22 +0000
+++ bin/pt-fifo-split 2014-10-09 17:53:04 +0000
@@ -902,6 +902,14 @@
902 $parse = 0;902 $parse = 0;
903 next LINE;903 next LINE;
904 }904 }
905
906 if ( $parse
907 && !$self->has('version-check')
908 && $line =~ /version-check/
909 ) {
910 next LINE;
911 }
912
905 if ( $parse913 if ( $parse
906 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)914 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
907 ) {915 ) {
908916
=== modified file 'bin/pt-fingerprint'
--- bin/pt-fingerprint 2014-09-25 13:48:22 +0000
+++ bin/pt-fingerprint 2014-10-09 17:53:04 +0000
@@ -903,6 +903,14 @@
903 $parse = 0;903 $parse = 0;
904 next LINE;904 next LINE;
905 }905 }
906
907 if ( $parse
908 && !$self->has('version-check')
909 && $line =~ /version-check/
910 ) {
911 next LINE;
912 }
913
906 if ( $parse914 if ( $parse
907 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)915 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
908 ) {916 ) {
909917
=== modified file 'bin/pt-ioprofile'
--- bin/pt-ioprofile 2014-09-25 13:48:22 +0000
+++ bin/pt-ioprofile 2014-10-09 17:53:04 +0000
@@ -86,9 +86,10 @@
8686
87usage_or_errors() {87usage_or_errors() {
88 local file="$1"88 local file="$1"
89 local version=""
8990
90 if [ "$OPT_VERSION" ]; then91 if [ "$OPT_VERSION" ]; then
91 local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")92 version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
92 echo "$version"93 echo "$version"
93 return 194 return 1
94 fi95 fi
@@ -310,6 +311,8 @@
310311
311 [ "$config_opt" = "" ] && continue312 [ "$config_opt" = "" ] && continue
312313
314 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
315
313 if ! [ "$HAVE_EXT_ARGV" ]; then316 if ! [ "$HAVE_EXT_ARGV" ]; then
314 config_opt="--$config_opt"317 config_opt="--$config_opt"
315 fi318 fi
316319
=== modified file 'bin/pt-mext'
--- bin/pt-mext 2014-09-25 13:48:22 +0000
+++ bin/pt-mext 2014-10-09 17:53:04 +0000
@@ -251,34 +251,38 @@
251_parse_pod() {251_parse_pod() {
252 local file="$1"252 local file="$1"
253253
254 cat "$file" | PO_DIR="$PO_DIR" perl -ne '254 PO_FILE="$file" PO_DIR="$PO_DIR" perl -e '
255 BEGIN { $/ = ""; }255 $/ = "";
256 next unless $_ =~ m/^=head1 OPTIONS/;256 my $file = $ENV{PO_FILE};
257 while ( defined(my $para = <>) ) {257 open my $fh, "<", $file or die "Cannot open $file: $!";
258 last if $para =~ m/^=head1/;258 while ( defined(my $para = <$fh>) ) {
259 chomp;259 next unless $para =~ m/^=head1 OPTIONS/;
260 if ( $para =~ m/^=item --(\S+)/ ) {260 while ( defined(my $para = <$fh>) ) {
261 my $opt = $1;261 last if $para =~ m/^=head1/;
262 my $file = "$ENV{PO_DIR}/$opt";
263 open my $opt_fh, ">", $file or die "Cannot open $file: $!";
264 print $opt_fh "long:$opt\n";
265 $para = <>;
266 chomp;262 chomp;
267 if ( $para =~ m/^[a-z ]+:/ ) {263 if ( $para =~ m/^=item --(\S+)/ ) {
268 map {264 my $opt = $1;
265 my $file = "$ENV{PO_DIR}/$opt";
266 open my $opt_fh, ">", $file or die "Cannot open $file: $!";
267 print $opt_fh "long:$opt\n";
268 $para = <$fh>;
269 chomp;
270 if ( $para =~ m/^[a-z ]+:/ ) {
271 map {
272 chomp;
273 my ($attrib, $val) = split(/: /, $_);
274 print $opt_fh "$attrib:$val\n";
275 } split(/; /, $para);
276 $para = <$fh>;
269 chomp;277 chomp;
270 my ($attrib, $val) = split(/: /, $_);278 }
271 print $opt_fh "$attrib:$val\n";279 my ($desc) = $para =~ m/^([^?.]+)/;
272 } split(/; /, $para);280 print $opt_fh "desc:$desc.\n";
273 $para = <>;281 close $opt_fh;
274 chomp;
275 }282 }
276 my ($desc) = $para =~ m/^([^?.]+)/;
277 print $opt_fh "desc:$desc.\n";
278 close $opt_fh;
279 }283 }
284 last;
280 }285 }
281 last;
282 '286 '
283}287}
284288
@@ -348,6 +352,8 @@
348352
349 [ "$config_opt" = "" ] && continue353 [ "$config_opt" = "" ] && continue
350354
355 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
356
351 if ! [ "$HAVE_EXT_ARGV" ]; then357 if ! [ "$HAVE_EXT_ARGV" ]; then
352 config_opt="--$config_opt"358 config_opt="--$config_opt"
353 fi359 fi
354360
=== modified file 'bin/pt-mysql-summary'
--- bin/pt-mysql-summary 2014-09-25 13:48:22 +0000
+++ bin/pt-mysql-summary 2014-10-09 17:53:04 +0000
@@ -313,6 +313,8 @@
313313
314 [ "$config_opt" = "" ] && continue314 [ "$config_opt" = "" ] && continue
315315
316 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
317
316 if ! [ "$HAVE_EXT_ARGV" ]; then318 if ! [ "$HAVE_EXT_ARGV" ]; then
317 config_opt="--$config_opt"319 config_opt="--$config_opt"
318 fi320 fi
319321
=== modified file 'bin/pt-pmp'
--- bin/pt-pmp 2014-09-25 13:48:22 +0000
+++ bin/pt-pmp 2014-10-09 17:53:04 +0000
@@ -129,9 +129,10 @@
129129
130usage_or_errors() {130usage_or_errors() {
131 local file="$1"131 local file="$1"
132 local version=""
132133
133 if [ "$OPT_VERSION" ]; then134 if [ "$OPT_VERSION" ]; then
134 local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")135 version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
135 echo "$version"136 echo "$version"
136 return 1137 return 1
137 fi138 fi
@@ -353,6 +354,8 @@
353354
354 [ "$config_opt" = "" ] && continue355 [ "$config_opt" = "" ] && continue
355356
357 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
358
356 if ! [ "$HAVE_EXT_ARGV" ]; then359 if ! [ "$HAVE_EXT_ARGV" ]; then
357 config_opt="--$config_opt"360 config_opt="--$config_opt"
358 fi361 fi
359362
=== modified file 'bin/pt-show-grants'
--- bin/pt-show-grants 2014-09-25 13:48:22 +0000
+++ bin/pt-show-grants 2014-10-09 17:53:04 +0000
@@ -903,6 +903,14 @@
903 $parse = 0;903 $parse = 0;
904 next LINE;904 next LINE;
905 }905 }
906
907 if ( $parse
908 && !$self->has('version-check')
909 && $line =~ /version-check/
910 ) {
911 next LINE;
912 }
913
906 if ( $parse914 if ( $parse
907 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)915 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
908 ) {916 ) {
909917
=== modified file 'bin/pt-sift'
--- bin/pt-sift 2014-09-25 13:48:22 +0000
+++ bin/pt-sift 2014-10-09 17:53:04 +0000
@@ -127,9 +127,10 @@
127127
128usage_or_errors() {128usage_or_errors() {
129 local file="$1"129 local file="$1"
130 local version=""
130131
131 if [ "$OPT_VERSION" ]; then132 if [ "$OPT_VERSION" ]; then
132 local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")133 version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
133 echo "$version"134 echo "$version"
134 return 1135 return 1
135 fi136 fi
@@ -351,6 +352,8 @@
351352
352 [ "$config_opt" = "" ] && continue353 [ "$config_opt" = "" ] && continue
353354
355 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
356
354 if ! [ "$HAVE_EXT_ARGV" ]; then357 if ! [ "$HAVE_EXT_ARGV" ]; then
355 config_opt="--$config_opt"358 config_opt="--$config_opt"
356 fi359 fi
357360
=== modified file 'bin/pt-slave-find'
--- bin/pt-slave-find 2014-09-25 13:48:22 +0000
+++ bin/pt-slave-find 2014-10-09 17:53:04 +0000
@@ -911,6 +911,14 @@
911 $parse = 0;911 $parse = 0;
912 next LINE;912 next LINE;
913 }913 }
914
915 if ( $parse
916 && !$self->has('version-check')
917 && $line =~ /version-check/
918 ) {
919 next LINE;
920 }
921
914 if ( $parse922 if ( $parse
915 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)923 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
916 ) {924 ) {
917925
=== modified file 'bin/pt-stalk'
--- bin/pt-stalk 2014-09-25 13:48:22 +0000
+++ bin/pt-stalk 2014-10-09 17:53:04 +0000
@@ -140,9 +140,10 @@
140140
141usage_or_errors() {141usage_or_errors() {
142 local file="$1"142 local file="$1"
143 local version=""
143144
144 if [ "$OPT_VERSION" ]; then145 if [ "$OPT_VERSION" ]; then
145 local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")146 version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
146 echo "$version"147 echo "$version"
147 return 1148 return 1
148 fi149 fi
@@ -364,6 +365,8 @@
364365
365 [ "$config_opt" = "" ] && continue366 [ "$config_opt" = "" ] && continue
366367
368 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
369
367 if ! [ "$HAVE_EXT_ARGV" ]; then370 if ! [ "$HAVE_EXT_ARGV" ]; then
368 config_opt="--$config_opt"371 config_opt="--$config_opt"
369 fi372 fi
370373
=== modified file 'bin/pt-summary'
--- bin/pt-summary 2014-09-25 13:48:22 +0000
+++ bin/pt-summary 2014-10-09 17:53:04 +0000
@@ -320,6 +320,8 @@
320320
321 [ "$config_opt" = "" ] && continue321 [ "$config_opt" = "" ] && continue
322322
323 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
324
323 if ! [ "$HAVE_EXT_ARGV" ]; then325 if ! [ "$HAVE_EXT_ARGV" ]; then
324 config_opt="--$config_opt"326 config_opt="--$config_opt"
325 fi327 fi
326328
=== modified file 'bin/pt-table-usage'
--- bin/pt-table-usage 2014-09-25 13:48:22 +0000
+++ bin/pt-table-usage 2014-10-09 17:53:04 +0000
@@ -1340,6 +1340,14 @@
1340 $parse = 0;1340 $parse = 0;
1341 next LINE;1341 next LINE;
1342 }1342 }
1343
1344 if ( $parse
1345 && !$self->has('version-check')
1346 && $line =~ /version-check/
1347 ) {
1348 next LINE;
1349 }
1350
1343 if ( $parse1351 if ( $parse
1344 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)1352 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
1345 ) {1353 ) {
13461354
=== modified file 'bin/pt-visual-explain'
--- bin/pt-visual-explain 2014-09-25 13:48:22 +0000
+++ bin/pt-visual-explain 2014-10-09 17:53:04 +0000
@@ -1577,6 +1577,14 @@
1577 $parse = 0;1577 $parse = 0;
1578 next LINE;1578 next LINE;
1579 }1579 }
1580
1581 if ( $parse
1582 && !$self->has('version-check')
1583 && $line =~ /version-check/
1584 ) {
1585 next LINE;
1586 }
1587
1580 if ( $parse1588 if ( $parse
1581 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)1589 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
1582 ) {1590 ) {
15831591
=== modified file 'lib/OptionParser.pm'
--- lib/OptionParser.pm 2014-05-24 21:36:33 +0000
+++ lib/OptionParser.pm 2014-10-09 17:53:04 +0000
@@ -1132,6 +1132,16 @@
1132 $parse = 0;1132 $parse = 0;
1133 next LINE;1133 next LINE;
1134 }1134 }
1135
1136 # Silently ignore option [no]-version-check if it is unsupported and it comes from a config file
1137 # TODO: Ideally , this should be generalized for all unsupported options that come from global files
1138 if ( $parse
1139 && !$self->has('version-check')
1140 && $line =~ /version-check/
1141 ) {
1142 next LINE;
1143 }
1144
1135 if ( $parse1145 if ( $parse
1136 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)1146 && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/)
1137 ) {1147 ) {
11381148
=== modified file 'lib/bash/parse_options.sh'
--- lib/bash/parse_options.sh 2014-07-10 20:15:13 +0000
+++ lib/bash/parse_options.sh 2014-10-09 17:53:04 +0000
@@ -347,6 +347,9 @@
347 # Skip blank lines.347 # Skip blank lines.
348 [ "$config_opt" = "" ] && continue348 [ "$config_opt" = "" ] && continue
349349
350 # Skip global option [no]version-check which don't apply
351 echo "$config_opt" | grep -v 'version-check' >/dev/null 2>&1 || continue
352
350 # Options in a config file are not prefixed with --,353 # Options in a config file are not prefixed with --,
351 # but command line options are, so one or the other has354 # but command line options are, so one or the other has
352 # to add or remove the -- prefix. We add it for config355 # to add or remove the -- prefix. We add it for config
353356
=== modified file 't/lib/OptionParser.t'
--- t/lib/OptionParser.t 2014-05-24 21:36:33 +0000
+++ t/lib/OptionParser.t 2014-10-09 17:53:04 +0000
@@ -2141,6 +2141,29 @@
2141 'prompt_no_echo outputs prompt to STDERR'2141 'prompt_no_echo outputs prompt to STDERR'
2142);2142);
21432143
2144# #############################################################################
2145# Issue 1361293: Global config file with no-version-check option makes tools
2146# that don't recognize the option fail.
2147# #############################################################################
2148diag(`echo "no-version-check" > ~/.OptionParser.t.conf`);
2149$o = new OptionParser(
2150 description => 'OptionParser.t parses command line options.',
2151 usage => "$PROGRAM_NAME <options>"
2152);
2153$o->get_specs("$trunk/bin/pt-slave-find"), # doesn't have version-check option
2154$output = output(
2155 sub {
2156 $o->get_opts();
2157 },
2158 stderr=>1
2159 );
2160unlike(
2161 $output,
2162 qr/Unknown option: no-version-check/,
2163 'no-version-check ignored if unsupported and in config file. issue 1361293'
2164);
2165diag(`rm -rf ~/.OptionParser.t.conf`);
2166
21442167
21452168
2146# #############################################################################2169# #############################################################################

Subscribers

People subscribed via source and target branches

to all changes: