mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-24 02:01:42 +08:00
Updates per Daniel's review
This commit is contained in:
@@ -55,17 +55,25 @@ eval {
|
||||
};
|
||||
|
||||
sub version_check {
|
||||
my $args = pop @_;
|
||||
my (@instances) = @_;
|
||||
my %args = @_;
|
||||
my @instances = $args{instances} ? @{ $args{instances} } : ();
|
||||
# If this blows up, oh well, don't bother the user about it.
|
||||
# This feature is a "best effort" only; we don't want it to
|
||||
# get in the way of the tool's real work.
|
||||
|
||||
if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
|
||||
print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',
|
||||
warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
|
||||
"environment variable.\n\n";
|
||||
return;
|
||||
}
|
||||
|
||||
# we got here if the protocol wasn't "off", and the values
|
||||
# were validated earlier, so just handle auto
|
||||
# This line is mostly here for the test suite:
|
||||
$args{protocol} ||= 'https';
|
||||
my @protocols = $args{protocol} eq 'auto'
|
||||
? qw(https http)
|
||||
: $args{protocol};
|
||||
|
||||
my $instances_to_check = [];
|
||||
my $time = int(time());
|
||||
@@ -82,18 +90,11 @@ sub version_check {
|
||||
($time_to_check, $instances_to_check)
|
||||
= time_to_check($check_time_file, \@instances, $time);
|
||||
if ( !$time_to_check ) {
|
||||
print STDERR 'It is not time to --version-check again; ',
|
||||
warn 'It is not time to --version-check again; ',
|
||||
"only 1 check per day.\n\n";
|
||||
return;
|
||||
}
|
||||
|
||||
# We got here if the protocol wasn't "off", but we haven't validated
|
||||
# other possible values. I don't want it to die here, so if it isn't
|
||||
# https or http, assume that it's 'auto'.
|
||||
$args->{protocol} ||= 'https';
|
||||
my @protocols = $args->{protocol} ne 'https' && $args->{protocol} ne 'http'
|
||||
? qw(https http)
|
||||
: $args->{protocol};
|
||||
my $advice;
|
||||
my $e;
|
||||
for my $protocol ( @protocols ) {
|
||||
@@ -138,7 +139,7 @@ sub pingback {
|
||||
# Optional args
|
||||
my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
|
||||
|
||||
$ua ||= HTTPMicro->new( timeout => 2 );
|
||||
$ua ||= HTTPMicro->new( timeout => 5 );
|
||||
$vc ||= VersionCheck->new();
|
||||
|
||||
# GET https://upgrade.percona.com, the server will return
|
||||
@@ -407,6 +408,22 @@ sub encode_client_response {
|
||||
return $client_response;
|
||||
}
|
||||
|
||||
sub validate_options {
|
||||
my ($o) = @_;
|
||||
|
||||
# No need to validate anything if we didn't get an explicit v-c
|
||||
return if !$o->got('version-check');
|
||||
|
||||
my $value = $o->get('version-check');
|
||||
my @values = split /, /,
|
||||
$o->read_para_after(__FILE__, qr/MAGIC_version_check/);
|
||||
chomp(@values);
|
||||
|
||||
return if grep { $value eq $_ } @values;
|
||||
$o->save_error("--version-check invalud value $value. Accepted values are "
|
||||
. join(", ", @values[0..$#values-1]) . " and $values[-1]" );
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
|
||||
Reference in New Issue
Block a user