mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-28 08:51:44 +00:00
v-c: Re-enable https by default, make --version-check take an optional protocol argument
This commit is contained in:
@@ -9,7 +9,7 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 151;
|
||||
use Test::More;
|
||||
|
||||
use OptionParser;
|
||||
use DSNParser;
|
||||
@@ -145,6 +145,7 @@ is_deeply(
|
||||
type => 's',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'port' => {
|
||||
spec => 'port|p=i',
|
||||
@@ -158,6 +159,7 @@ is_deeply(
|
||||
type => 'i',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'price' => {
|
||||
spec => 'price=f',
|
||||
@@ -171,6 +173,7 @@ is_deeply(
|
||||
type => 'f',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'hash-req' => {
|
||||
spec => 'hash-req=s',
|
||||
@@ -184,6 +187,7 @@ is_deeply(
|
||||
type => 'H',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'hash-opt' => {
|
||||
spec => 'hash-opt=s',
|
||||
@@ -197,6 +201,7 @@ is_deeply(
|
||||
type => 'h',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'array-req' => {
|
||||
spec => 'array-req=s',
|
||||
@@ -210,6 +215,7 @@ is_deeply(
|
||||
type => 'A',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'array-opt' => {
|
||||
spec => 'array-opt=s',
|
||||
@@ -223,6 +229,7 @@ is_deeply(
|
||||
type => 'a',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'host' => {
|
||||
spec => 'host=s',
|
||||
@@ -236,6 +243,7 @@ is_deeply(
|
||||
type => 'd',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'chunk-size' => {
|
||||
spec => 'chunk-size=s',
|
||||
@@ -249,6 +257,7 @@ is_deeply(
|
||||
type => 'z',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'time' => {
|
||||
spec => 'time=s',
|
||||
@@ -262,6 +271,7 @@ is_deeply(
|
||||
type => 'm',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'help' => {
|
||||
spec => 'help+',
|
||||
@@ -275,6 +285,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'other' => {
|
||||
spec => 'other!',
|
||||
@@ -288,6 +299,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
}
|
||||
},
|
||||
'Parse opt specs'
|
||||
@@ -508,6 +520,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'defaultset' => {
|
||||
spec => 'defaultset!',
|
||||
@@ -523,6 +536,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'defaults-file' => {
|
||||
spec => 'defaults-file|F=s',
|
||||
@@ -536,6 +550,7 @@ is_deeply(
|
||||
type => 's',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'dog' => {
|
||||
spec => 'dog|D=s',
|
||||
@@ -549,6 +564,7 @@ is_deeply(
|
||||
type => 's',
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
'love' => {
|
||||
spec => 'love|l+',
|
||||
@@ -562,6 +578,7 @@ is_deeply(
|
||||
type => undef,
|
||||
got => 0,
|
||||
value => undef,
|
||||
optional_value => 0,
|
||||
},
|
||||
},
|
||||
'Parse dog specs'
|
||||
@@ -961,6 +978,7 @@ is_deeply(
|
||||
long => 'bar',
|
||||
type => undef,
|
||||
parsed => 1,
|
||||
optional_value=> 0,
|
||||
},
|
||||
'Disabled opt is not destroyed'
|
||||
);
|
||||
@@ -1990,13 +2008,55 @@ $o->get_opts();
|
||||
$output = output(
|
||||
sub { $o->usage_or_errors(undef, 1); },
|
||||
);
|
||||
$synop{usage} =~ s/([\[\]])/\\$1/g;
|
||||
like(
|
||||
$output,
|
||||
qr/^$synop{description} For more details.+\nUsage: $synop{usage}$/m,
|
||||
qr/^$synop{description} For more details.+\nUsage: \Q$synop{usage}\E\n?$/m,
|
||||
"Uses desc and usage from SYNOPSIS for help"
|
||||
);
|
||||
|
||||
# Add a value_is_optional option
|
||||
@ARGV = qw();
|
||||
$o->get_opts();
|
||||
|
||||
ok(
|
||||
!$o->got('version-check'),
|
||||
"version-check is not true by default"
|
||||
);
|
||||
|
||||
is(
|
||||
$o->get('version-check'),
|
||||
"https",
|
||||
"..but it still has a value",
|
||||
);
|
||||
|
||||
@ARGV = qw(--version-check);
|
||||
$o->get_opts();
|
||||
|
||||
ok(
|
||||
$o->got('version-check'),
|
||||
"version-check is true if specified without arguments"
|
||||
);
|
||||
|
||||
is(
|
||||
$o->get('version-check'),
|
||||
"https",
|
||||
"..and has the default value",
|
||||
);
|
||||
|
||||
@ARGV = qw(--version-check http);
|
||||
$o->get_opts();
|
||||
|
||||
ok(
|
||||
$o->got('version-check'),
|
||||
"version-check is true if specified with arguments"
|
||||
);
|
||||
|
||||
is(
|
||||
$o->get('version-check'),
|
||||
"http",
|
||||
"..and has the specified value",
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
@@ -2010,4 +2070,5 @@ like(
|
||||
qr/Complete test coverage/,
|
||||
'_d() works'
|
||||
);
|
||||
exit;
|
||||
|
||||
done_testing;
|
||||
|
@@ -238,20 +238,37 @@ my $file = File::Spec->catfile($dir, 'percona-toolkit-version-check-test');
|
||||
|
||||
unlink $file if -f $file;
|
||||
|
||||
my $time = int(time());
|
||||
|
||||
ok(
|
||||
Pingback::time_to_check($file, []),
|
||||
Pingback::time_to_check($file, [], $time),
|
||||
"time_to_check() returns true if the file doesn't exist",
|
||||
);
|
||||
|
||||
ok(
|
||||
!Pingback::time_to_check($file, []),
|
||||
"...but false if it exists and it's been less than 24 hours",
|
||||
!-f $file,
|
||||
"time_to_check doesn't create the checks file"
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, [], $time);
|
||||
|
||||
ok(
|
||||
-f $file,
|
||||
"...but update_checks_file does"
|
||||
);
|
||||
|
||||
ok(
|
||||
!Pingback::time_to_check($file, [], $time),
|
||||
"...and time_to_check is false if the file exists and it's been less than 24 hours",
|
||||
);
|
||||
|
||||
my $one_day = 60 * 60 * 24;
|
||||
my ($old_atime, $old_mtime) = (stat($file))[8,9];
|
||||
my ($orig_atime, $orig_mtime) = (stat($file))[8,9];
|
||||
|
||||
utime($old_atime - $one_day * 2, $old_mtime - $one_day * 2, $file);
|
||||
my $mod_atime = $orig_atime - $one_day * 2;
|
||||
my $mod_mtime = $orig_mtime - $one_day * 2;
|
||||
|
||||
utime($mod_atime, $mod_mtime, $file);
|
||||
|
||||
cmp_ok(
|
||||
(stat($file))[9],
|
||||
@@ -261,13 +278,24 @@ cmp_ok(
|
||||
);
|
||||
|
||||
ok(
|
||||
Pingback::time_to_check($file, []),
|
||||
Pingback::time_to_check($file, [], $time),
|
||||
"time_to_check true if file exists and mtime < one day", #>"
|
||||
);
|
||||
|
||||
my ($atime, $mtime) = (stat($file))[8,9];
|
||||
|
||||
is($mod_atime, $atime, "time_to_check doesn't update the atime");
|
||||
is($mod_mtime, $mtime, "time_to_check doesn't update the mtime");
|
||||
|
||||
Pingback::update_checks_file($file, [], $time);
|
||||
|
||||
($atime, $mtime) = (stat($file))[8,9];
|
||||
|
||||
ok($orig_atime == $atime && $orig_mtime == $mtime, "but update_checks_file does");
|
||||
|
||||
ok(
|
||||
!Pingback::time_to_check($file, []),
|
||||
"...but fails if tried a second time, as the mtime has been updated",
|
||||
!Pingback::time_to_check($file, [], $time),
|
||||
"...and time_to_check fails after update_checks_file, as the mtime has been updated",
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
@@ -312,7 +340,8 @@ SKIP: {
|
||||
$file,
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
$is_time,
|
||||
"Time to check a new MySQL instance ID",
|
||||
@@ -330,6 +359,8 @@ SKIP: {
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
!$is_time,
|
||||
"...but not the second time around",
|
||||
@@ -344,6 +375,8 @@ SKIP: {
|
||||
[ $master_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
[ $master_inst ],
|
||||
@@ -355,6 +388,8 @@ SKIP: {
|
||||
[ $master_inst, $slave1_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
is_deeply(
|
||||
$check_inst,
|
||||
[ $slave1_inst ],
|
||||
@@ -371,6 +406,8 @@ SKIP: {
|
||||
[ $master_inst, $slave1_inst ],
|
||||
);
|
||||
|
||||
Pingback::update_checks_file($file, $check_inst, int(time()));
|
||||
|
||||
ok(
|
||||
!$is_time,
|
||||
"...and false if there isn't anything to check",
|
||||
|
@@ -40,7 +40,7 @@ unlink $check_time_file if -f $check_time_file;
|
||||
$sb->create_dbs($master_dbh, ['test']);
|
||||
$sb->load_file('master', 't/pt-archiver/samples/tables1-4.sql');
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
@@ -64,7 +64,7 @@ ok(
|
||||
# v-c file should limit checks to 1 per 24 hours
|
||||
# ###########################################################################
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
@@ -80,13 +80,13 @@ unlink $check_time_file if -f $check_time_file;
|
||||
|
||||
my $t0 = time;
|
||||
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
|
||||
my $t = time - $t0;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Error.+?GET http:\/\/x\.percona\.com.+?HTTP status 5\d+/,
|
||||
qr/Error.+?(?:GET http:\/\/x\.percona\.com.+?HTTP status 5\d+|Failed to get any program versions; should have at least gotten Perl)/,
|
||||
"The Percona server didn't respond"
|
||||
);
|
||||
|
||||
@@ -124,7 +124,7 @@ ok(
|
||||
# PERCONA_VERSION_CHECK=0 is handled in Pingback, so it will print a line
|
||||
# for PTVCDEBUG saying why it didn't run. So we just check that it doesn't
|
||||
# create the file which also signifies that it didn't run.
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check http 2>&1`;
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
|
@@ -11,6 +11,8 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use File::Spec::Functions;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use Data::Dumper;
|
||||
@@ -19,14 +21,15 @@ use Time::HiRes qw(time);
|
||||
require "$trunk/bin/pt-query-digest";
|
||||
|
||||
my $output;
|
||||
my $cmd = "$trunk/bin/pt-query-digest --limit 1 $trunk/t/lib/samples/slowlogs/slow001.txt";
|
||||
my $cmd = catfile($trunk, "bin", "pt-query-digest");
|
||||
my @args = (qw(--limit 1), catfile($trunk, qw(t lib samples slowlogs slow001.txt)));
|
||||
|
||||
# Pingback.pm does this too.
|
||||
my $dir = File::Spec->tmpdir();
|
||||
my $check_time_file = File::Spec->catfile($dir,'percona-toolkit-version-check');
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 $cmd @args --version-check http 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
@@ -49,7 +52,7 @@ ok(
|
||||
# v-c file should limit checks to 1 per 24 hours
|
||||
# ###########################################################################
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 $cmd @args --version-check http 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
@@ -65,13 +68,13 @@ unlink $check_time_file if -f $check_time_file;
|
||||
|
||||
my $t0 = time;
|
||||
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK_URL='http://x.percona.com' $cmd @args --version-check http 2>&1`;
|
||||
|
||||
my $t = time - $t0;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Error.+?GET http:\/\/x\.percona\.com.+?HTTP status 5\d+/,
|
||||
qr/Error.+?(?:GET http:\/\/x\.percona\.com.+?HTTP status 5\d+|Failed to get any program versions; should have at least gotten Perl)/,
|
||||
"The Percona server didn't respond"
|
||||
);
|
||||
|
||||
@@ -93,7 +96,7 @@ cmp_ok(
|
||||
|
||||
unlink $check_time_file if -f $check_time_file;
|
||||
|
||||
$output = `PTVCDEBUG=1 $cmd 2>&1`;
|
||||
$output = `PTVCDEBUG=1 $cmd @args 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
@@ -109,7 +112,7 @@ ok(
|
||||
# PERCONA_VERSION_CHECK=0 is handled in Pingback, so it will print a line
|
||||
# for PTVCDEBUG saying why it didn't run. So we just check that it doesn't
|
||||
# create the file which also signifies that it didn't run.
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd --version-check 2>&1`;
|
||||
$output = `PTVCDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd @args --version-check http 2>&1`;
|
||||
|
||||
ok(
|
||||
!-f $check_time_file,
|
||||
|
Reference in New Issue
Block a user