~percona-toolkit-dev/percona-toolkit/pxc-pt-slave-find-tests

« back to all changes in this revision

Viewing changes to bin/pt-config-diff

Merged OptionParser-remove-optional_value & updated modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
      'default'    => 1,
86
86
      'cumulative' => 1,
87
87
      'negatable'  => 1,
88
 
      'value_is_optional' => 1,
89
88
   );
90
89
 
91
90
   my $self = {
327
326
            $opt->{short} = undef;
328
327
         }
329
328
 
330
 
         $opt->{is_negatable}   = $opt->{spec} =~ m/!/        ? 1 : 0;
331
 
         $opt->{is_cumulative}  = $opt->{spec} =~ m/\+/       ? 1 : 0;
332
 
         $opt->{optional_value} = $opt->{spec} =~ m/:/        ? 1 : 0;
333
 
         $opt->{is_required}    = $opt->{desc} =~ m/required/ ? 1 : 0;
 
329
         $opt->{is_negatable}  = $opt->{spec} =~ m/!/        ? 1 : 0;
 
330
         $opt->{is_cumulative} = $opt->{spec} =~ m/\+/       ? 1 : 0;
 
331
         $opt->{is_required}   = $opt->{desc} =~ m/required/ ? 1 : 0;
334
332
 
335
333
         $opt->{group} ||= 'default';
336
334
         $self->{groups}->{ $opt->{group} }->{$long} = 1;
466
464
   if ( $opt->{is_cumulative} ) {
467
465
      $opt->{value}++;
468
466
   }
469
 
   elsif ( !($opt->{optional_value} && !$val) ) {
 
467
   else {
470
468
      $opt->{value} = $val;
471
469
   }
472
470
   $opt->{got} = 1;
1007
1005
sub _parse_attribs {
1008
1006
   my ( $self, $option, $attribs ) = @_;
1009
1007
   my $types = $self->{types};
1010
 
   my $eq    = $attribs->{'value_is_optional'} ? ':' : '=';
1011
1008
   return $option
1012
1009
      . ($attribs->{'short form'} ? '|' . $attribs->{'short form'}   : '' )
1013
1010
      . ($attribs->{'negatable'}  ? '!'                              : '' )
1014
1011
      . ($attribs->{'cumulative'} ? '+'                              : '' )
1015
 
      . ($attribs->{'type'}       ? $eq . $types->{$attribs->{type}} : '' );
 
1012
      . ($attribs->{'type'}       ? '=' . $types->{$attribs->{type}} : '' );
1016
1013
}
1017
1014
 
1018
1015
sub _parse_synopsis {
3959
3956
};
3960
3957
 
3961
3958
sub version_check {
3962
 
   my $args        = pop @_;
3963
 
   my (@instances) = @_;
 
3959
   my %args      = @_;
 
3960
   my @instances = $args{instances} ? @{ $args{instances} } : ();
3964
3961
 
3965
3962
   if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
3966
 
      print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',
 
3963
      warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
3967
3964
                   "environment variable.\n\n";
3968
3965
      return;
3969
3966
   }
 
3967
 
 
3968
   $args{protocol} ||= 'https';
 
3969
   my @protocols = $args{protocol} eq 'auto'
 
3970
                 ? qw(https http)
 
3971
                 : $args{protocol};
3970
3972
   
3971
3973
   my $instances_to_check = [];
3972
3974
   my $time               = int(time());
3981
3983
      ($time_to_check, $instances_to_check)
3982
3984
         = time_to_check($check_time_file, \@instances, $time);
3983
3985
      if ( !$time_to_check ) {
3984
 
         print STDERR 'It is not time to --version-check again; ',
 
3986
         warn 'It is not time to --version-check again; ',
3985
3987
                      "only 1 check per day.\n\n";
3986
3988
         return;
3987
3989
      }
3988
3990
 
3989
 
      my $protocol = $args->{protocol} || 'https';
3990
 
      my $advice = pingback(
3991
 
         url       => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
3992
 
         instances => $instances_to_check,
3993
 
         protocol  => $args->{protocol},
3994
 
      );
 
3991
      my $advice;
 
3992
      my $e;
 
3993
      for my $protocol ( @protocols ) {
 
3994
         $advice = eval { pingback(
 
3995
            url       => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
 
3996
            instances => $instances_to_check,
 
3997
            protocol  => $protocol,
 
3998
         ) };
 
3999
         last if !$advice && !$EVAL_ERROR;
 
4000
         $e ||= $EVAL_ERROR;
 
4001
      }
3995
4002
      if ( $advice ) {
3996
4003
         print "# Percona suggests these upgrades:\n";
3997
4004
         print join("\n", map { "#   * $_" } @$advice), "\n\n";
3998
4005
      }
3999
4006
      else {
 
4007
         die $e if $e;
4000
4008
         print "# No suggestions at this time.\n\n";
4001
4009
         ($ENV{PTVCDEBUG} || PTDEBUG )
4002
4010
            && _d('--version-check worked, but there were no suggestions');
4022
4030
 
4023
4031
   my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
4024
4032
 
4025
 
   $ua ||= HTTPMicro->new( timeout => 2 );
 
4033
   $ua ||= HTTPMicro->new( timeout => 5 );
4026
4034
   $vc ||= VersionCheck->new();
4027
4035
 
4028
4036
   my $response = $ua->request('GET', $url);
4238
4246
   return $client_response;
4239
4247
}
4240
4248
 
 
4249
sub validate_options {
 
4250
   my ($o) = @_;
 
4251
 
 
4252
   return if !$o->got('version-check');
 
4253
 
 
4254
   my $value  = $o->get('version-check');
 
4255
   my @values = split /, /,
 
4256
                $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
 
4257
   chomp(@values);
 
4258
                
 
4259
   return if grep { $value eq $_ } @values;
 
4260
   $o->save_error("--version-check invalid value $value.  Accepted values are "
 
4261
                . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
 
4262
}
 
4263
 
4241
4264
sub _d {
4242
4265
   my ($package, undef, $line) = caller 0;
4243
4266
   @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
4290
4313
      if ( @ARGV < 1 ) {
4291
4314
        $o->save_error("Specify at least one file or DSN on the command line");
4292
4315
      }
 
4316
      Pingback::validate_options($o);
4293
4317
   }
4294
4318
 
4295
4319
   $o->usage_or_errors();
4364
4388
   # ########################################################################
4365
4389
   # Do the version-check
4366
4390
   # ########################################################################
4367
 
   if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {
 
4391
   if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4368
4392
      Pingback::version_check(
4369
 
         map({ +{ dbh => $_->dbh, dsn => $_->dsn } } @cxn),
4370
 
         { protocol => $o->get('version-check') },
 
4393
         instances => [ map({ +{ dbh => $_->dbh, dsn => $_->dsn } } @cxn) ],
 
4394
         protocol  => $o->get('version-check'),
4371
4395
      );
4372
4396
   }
4373
4397
 
4651
4675
 
4652
4676
=item --version-check
4653
4677
 
4654
 
type: string; value_is_optional: yes; default: https
 
4678
type: string; default: off
4655
4679
 
4656
4680
Send program versions to Percona and print suggested upgrades and problems.
4657
 
 
4658
 
If specified without a value, it will use https by default; However, this
4659
 
might fail if C<IO::Socket::SSL> is not installed on your system, in which
4660
 
case you may choose to use C<--version-check http>, which will forgo
4661
 
encryption but should work out of the box.
 
4681
Possible values for --version-check:
 
4682
 
 
4683
=for comment ignore-pt-internal-value
 
4684
MAGIC_version_check
 
4685
 
 
4686
https, http, auto, off
 
4687
 
 
4688
C<auto> first tries using C<https>, and resorts to C<http> if that fails.
 
4689
Keep in mind that C<https> might not be available if
 
4690
C<IO::Socket::SSL> is not installed on your system, although
 
4691
C<--version-check http> should work everywhere.
4662
4692
 
4663
4693
The version check feature causes the tool to send and receive data from
4664
4694
Percona over the web.  The data contains program versions from the local