diff --git a/.bzrignore b/.bzrignore index fcbf594b..853b28a6 100644 --- a/.bzrignore +++ b/.bzrignore @@ -7,4 +7,3 @@ release snapshot .DS_Store build -special/percona-toolkit/v-c-internal diff --git a/bin/pt-archiver b/bin/pt-archiver index 5618229d..668560ee 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -4697,10 +4697,11 @@ local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Quotekeys = 0; -use Digest::MD5 qw(md5_hex); -use Sys::Hostname qw(hostname); +use Digest::MD5 qw(md5_hex); +use Sys::Hostname qw(hostname); use File::Basename qw(); use File::Spec; +use FindBin qw(); eval { require Percona::Toolkit; @@ -4740,12 +4741,14 @@ sub version_check { my $instances = $args{instances} || []; my $instances_to_check; - eval { - if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) { - PTDEBUG && _d('--version-check disabled by PERCONA_VERSION_CHECK=0'); + if ( !$args{force} ) { + if ( $FindBin::Bin && -d "$FindBin::Bin/../.bzr" ) { + PTDEBUG && _d("$FindBin::Bin/../.bzr disables --version-check"); return; } + } + eval { foreach my $instance ( @$instances ) { my ($name, $id) = get_instance_id($instance); $instance->{name} = $name; @@ -4793,15 +4796,17 @@ sub version_check { PTDEBUG && _d('Version check failed:', $EVAL_ERROR); } - eval { - update_check_times( - instances => $instances_to_check, - vc_file => $args{vc_file}, # testing - now => $args{now}, # testing - ); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR); + if ( @$instances_to_check ) { + eval { + update_check_times( + instances => $instances_to_check, + vc_file => $args{vc_file}, # testing + now => $args{now}, # testing + ); + }; + if ( $EVAL_ERROR ) { + PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR); + } } if ( $ENV{PTDEBUG_VERSION_CHECK} ) { @@ -5770,6 +5775,7 @@ sub main { # ######################################################################## if ( $o->get('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) { VersionCheck::version_check( + force => $o->got('version-check'), instances => [ { dbh => $src->{dbh}, dsn => $src->{dsn} }, ( $dst ? { dbh => $dst->{dbh}, dsn => $dst->{dsn} } : () ), diff --git a/lib/Percona/Toolkit.pm b/lib/Percona/Toolkit.pm index 492c2fce..0bc8c959 100644 --- a/lib/Percona/Toolkit.pm +++ b/lib/Percona/Toolkit.pm @@ -1,4 +1,4 @@ -# This program is copyright 2012 Percona Inc. +# This program is copyright 2012-2013 Percona Ireland Ltd. # Feedback and improvements are welcome. # # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED @@ -21,8 +21,6 @@ package Percona::Toolkit; our $VERSION = '2.1.8'; -sub bzr_repo { q{~percona-toolkit-dev} } - 1; } # ########################################################################### diff --git a/lib/VersionCheck.pm b/lib/VersionCheck.pm index 6f735f90..cea09b68 100644 --- a/lib/VersionCheck.pm +++ b/lib/VersionCheck.pm @@ -37,14 +37,11 @@ local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Quotekeys = 0; -use Digest::MD5 qw(md5_hex); -use Sys::Hostname qw(hostname); +use Digest::MD5 qw(md5_hex); +use Sys::Hostname qw(hostname); use File::Basename qw(); use File::Spec; - -use IPC::Cmd qw(can_run); -use FindBin qw(); -use Cwd qw(); +use FindBin qw(); eval { require Percona::Toolkit; @@ -104,42 +101,19 @@ sub version_check { my $instances = $args{instances} || []; my $instances_to_check; - eval { - if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) { - PTDEBUG && _d('--version-check disabled by PERCONA_VERSION_CHECK=0'); + # This sub should only be called if $o->get('version-check') is true, + # and it is by default because the option is on by default in PT 2.2. + # However, we do not want dev and testing to v-c, so even though this + # sub is called, force should be false because $o->got('version-check') + # is false, then check for a .bzr dir which indicates dev or testing. + if ( !$args{force} ) { + if ( $FindBin::Bin && -d "$FindBin::Bin/../.bzr" ) { + PTDEBUG && _d("$FindBin::Bin/../.bzr disables --version-check"); return; } + } - if ( !$ENV{PERCONA_FORCE_VERSION_CHECK} ) { - # Check if we're running from a bzr repo, and that repo is ours. - if ( my $bzr = can_run('bzr') ) { - my $percona_repo = Percona::Toolkit::bzr_repo(); - my $info = `$bzr info 2>/dev/null`; - if ( $info && $info =~ /\Q$percona_repo/ ) { - PTDEBUG && _d('--version-check disabled by running from a bzr checkout'); - return; - } - } - - # Perhaps bzr isn't available, but we're still running from - # a bzr repo. Brian occasionally does this when running in - # his VMs, since it's usually easier than installing bzr. - # So check if $Cwd/.bzrignore or $FindBin::Bin/../.bzrignore - # exist, and if they do, check if it has this line: - # special/percona-toolkit/v-c-internal - for my $dir ( Cwd::cwd(), File::Spec->updir($FindBin::Bin) ) { - my $ignore = File::Spec->catfile($dir, '.bzrignore'); - next unless -r $ignore; - open my $fh, '<', $ignore or next; - chomp(my $file_contents = do { local $/ = undef; <$fh> }); - close $fh; - if ( $file_contents =~ m{special/percona-toolkit/v-c-internal} ) { - PTDEBUG && _d('--version-check disabled by running from a bzr checkout'); - return; - } - } - } - + eval { # Name and ID the instances. The name is for debugging, # and the ID is what the code uses to prevent double-checking. foreach my $instance ( @$instances ) { @@ -195,17 +169,19 @@ sub version_check { } # Always update the vc file, even if the version check fails. - eval { - # Update the check time for things we checked. I.e. if we - # didn't check it, do _not_ update its time. - update_check_times( - instances => $instances_to_check, - vc_file => $args{vc_file}, # testing - now => $args{now}, # testing - ); - }; - if ( $EVAL_ERROR ) { - PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR); + if ( @$instances_to_check ) { + eval { + # Update the check time for things we checked. I.e. if we + # didn't check it, do _not_ update its time. + update_check_times( + instances => $instances_to_check, + vc_file => $args{vc_file}, # testing + now => $args{now}, # testing + ); + }; + if ( $EVAL_ERROR ) { + PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR); + } } if ( $ENV{PTDEBUG_VERSION_CHECK} ) { diff --git a/sandbox/test-env b/sandbox/test-env index e152a22a..5b0cec82 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -107,31 +107,6 @@ checkconfig() { fi fi - if [ ! -f "/etc/percona-toolkit/percona-toolkit.conf" ]; then - conf_err=1 - stat="DOES NOT EXIST" - else - stat="ok" - fi - if [ $print_conf ]; then - echo "/etc/percona-toolkit/percona-toolkit.conf - $stat" - fi - - if [ -f "/etc/percona-toolkit/percona-toolkit.conf" ]; then - grep "no-version-check" "/etc/percona-toolkit/percona-toolkit.conf" - if [ $? -ne 0 ]; then - conf_err=1 - stat="DOES NOT HAVE no-version-check" - else - stat="ok" - fi - if [ $print_conf ]; then - echo "/etc/percona-toolkit/percona-toolkit.conf - $stat" - fi - else - echo "/etc/percona-toolkit/percona-toolkit.conf - DOES NOT HAVE no-version-check" - fi - return $conf_err } diff --git a/t/pt-archiver/version_check.t b/t/pt-archiver/version_check.t index 31adef4d..7e255f22 100644 --- a/t/pt-archiver/version_check.t +++ b/t/pt-archiver/version_check.t @@ -38,32 +38,37 @@ unlink $vc_file if -f $vc_file; $sb->create_dbs($master_dbh, ['test']); $sb->load_file('master', 't/pt-archiver/samples/tables1-4.sql'); +# Normally --version-check is on by default, but in dev/testing envs, +# there's going to be a .bzr dir that auto-disables --version-check so +# our dev/test boxes don't flood the v-c database. Consequently, +# have have to explicitly give --version-check to force the check. + $output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`; like( $output, - qr/VersionCheck/, + qr/VersionCheck:\d+ \d+ Server response/, "Looks like the version-check happened" ) or diag($output); +ok( + -f $vc_file, + "Version check file was created" +) or diag($output); + $rows = $master_dbh->selectall_arrayref("SELECT * FROM test.table_1"); is_deeply( $rows, [], "Tool ran after version-check" -) or diag(Dumper($rows)); - -ok( - -f $vc_file, - "Created version check file" -); - -my $orig_vc_file = `cat $vc_file 2>/dev/null`; +) or diag(Dumper($rows), $output); # ########################################################################### # v-c file should limit checks to 1 per 24 hours # ########################################################################### +my $orig_vc_file = `cat $vc_file 2>/dev/null`; + $output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`; like( @@ -78,7 +83,7 @@ is( $new_vc_file, $orig_vc_file, "Version check file not changed" -); +) or diag($output); unlink $vc_file if -f $vc_file; @@ -94,7 +99,7 @@ my $t = time - $t0; like( $output, - qr/Error.+?(?:GET on https?:\/\/x\.percona\.com.+?HTTP status 5\d+|Failed to get any program versions; should have at least gotten Perl)/, + qr/Version check failed: GET on \S+x.percona.com returned HTTP status 5../, "The Percona server didn't respond" ); @@ -109,33 +114,46 @@ cmp_ok( "Tool waited a short while for the Percona server to respond" ); +# ########################################################################### +# Disable --version-check. +# ########################################################################### + unlink $vc_file if -f $vc_file; -# ########################################################################### -# Disable the v-c. It's already disabled, actually: test-env requires -# no-version-check in /etc/percona-toolkit/percona-toolkit.conf (to keep -# every test everywhere from version-checking). -# ########################################################################### - -$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge 2>&1`; +$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --no-version-check 2>&1`; unlike( $output, qr/VersionCheck/, - "Looks like no --version-check disabled the version-check" + "Looks like --no-version-check disabled the check" ) or diag($output); ok( !-f $vc_file, - "percona-toolkit-version-check file not created with --no-version-check" -); + "... version check file was not created" +) or diag(`cat $vc_file`); -$output = `PTDEBUG=1 PERCONA_VERSION_CHECK=0 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`; +# Since this is a test, VersionCheck should detect the .bzr dir +# and disble itself even without --no-version-check. + +$output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge 2>&1`; + +like( + $output, + qr/\.bzr disables --version-check/, + "Looks like .bzr disabled the check" +) or diag($output); + +unlike( + $output, + qr/Updating last check time/, + "... version check file was not updated" +) or diag($output); ok( !-f $vc_file, - "Looks like PERCONA_VERSION_CHECK=0 disabled the version-check" -); + "... version check file was not created" +) or diag($output, `cat $vc_file`); # ############################################################################# # Done. @@ -144,4 +162,3 @@ unlink $vc_file if -f $vc_file; $sb->wipe_clean($master_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); done_testing; -exit;