Simplify checking for .bzr/ to auto-disable --version-check in dev and test envs. Update t/pt-archiver/version_check.t. Need to update all other tools...

This commit is contained in:
Daniel Nichter
2013-02-21 15:59:49 -07:00
parent 4534981913
commit fc851caec8
6 changed files with 89 additions and 118 deletions

View File

@@ -7,4 +7,3 @@ release
snapshot snapshot
.DS_Store .DS_Store
build build
special/percona-toolkit/v-c-internal

View File

@@ -4697,10 +4697,11 @@ local $Data::Dumper::Indent = 1;
local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Sortkeys = 1;
local $Data::Dumper::Quotekeys = 0; local $Data::Dumper::Quotekeys = 0;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use Sys::Hostname qw(hostname); use Sys::Hostname qw(hostname);
use File::Basename qw(); use File::Basename qw();
use File::Spec; use File::Spec;
use FindBin qw();
eval { eval {
require Percona::Toolkit; require Percona::Toolkit;
@@ -4740,12 +4741,14 @@ sub version_check {
my $instances = $args{instances} || []; my $instances = $args{instances} || [];
my $instances_to_check; my $instances_to_check;
eval { if ( !$args{force} ) {
if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) { if ( $FindBin::Bin && -d "$FindBin::Bin/../.bzr" ) {
PTDEBUG && _d('--version-check disabled by PERCONA_VERSION_CHECK=0'); PTDEBUG && _d("$FindBin::Bin/../.bzr disables --version-check");
return; return;
} }
}
eval {
foreach my $instance ( @$instances ) { foreach my $instance ( @$instances ) {
my ($name, $id) = get_instance_id($instance); my ($name, $id) = get_instance_id($instance);
$instance->{name} = $name; $instance->{name} = $name;
@@ -4793,15 +4796,17 @@ sub version_check {
PTDEBUG && _d('Version check failed:', $EVAL_ERROR); PTDEBUG && _d('Version check failed:', $EVAL_ERROR);
} }
eval { if ( @$instances_to_check ) {
update_check_times( eval {
instances => $instances_to_check, update_check_times(
vc_file => $args{vc_file}, # testing instances => $instances_to_check,
now => $args{now}, # testing vc_file => $args{vc_file}, # testing
); now => $args{now}, # testing
}; );
if ( $EVAL_ERROR ) { };
PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR); if ( $EVAL_ERROR ) {
PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR);
}
} }
if ( $ENV{PTDEBUG_VERSION_CHECK} ) { if ( $ENV{PTDEBUG_VERSION_CHECK} ) {
@@ -5770,6 +5775,7 @@ sub main {
# ######################################################################## # ########################################################################
if ( $o->get('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) { if ( $o->get('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {
VersionCheck::version_check( VersionCheck::version_check(
force => $o->got('version-check'),
instances => [ instances => [
{ dbh => $src->{dbh}, dsn => $src->{dsn} }, { dbh => $src->{dbh}, dsn => $src->{dsn} },
( $dst ? { dbh => $dst->{dbh}, dsn => $dst->{dsn} } : () ), ( $dst ? { dbh => $dst->{dbh}, dsn => $dst->{dsn} } : () ),

View File

@@ -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. # Feedback and improvements are welcome.
# #
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
@@ -21,8 +21,6 @@
package Percona::Toolkit; package Percona::Toolkit;
our $VERSION = '2.1.8'; our $VERSION = '2.1.8';
sub bzr_repo { q{~percona-toolkit-dev} }
1; 1;
} }
# ########################################################################### # ###########################################################################

View File

@@ -37,14 +37,11 @@ local $Data::Dumper::Indent = 1;
local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Sortkeys = 1;
local $Data::Dumper::Quotekeys = 0; local $Data::Dumper::Quotekeys = 0;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use Sys::Hostname qw(hostname); use Sys::Hostname qw(hostname);
use File::Basename qw(); use File::Basename qw();
use File::Spec; use File::Spec;
use FindBin qw();
use IPC::Cmd qw(can_run);
use FindBin qw();
use Cwd qw();
eval { eval {
require Percona::Toolkit; require Percona::Toolkit;
@@ -104,42 +101,19 @@ sub version_check {
my $instances = $args{instances} || []; my $instances = $args{instances} || [];
my $instances_to_check; my $instances_to_check;
eval { # This sub should only be called if $o->get('version-check') is true,
if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) { # and it is by default because the option is on by default in PT 2.2.
PTDEBUG && _d('--version-check disabled by PERCONA_VERSION_CHECK=0'); # 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; return;
} }
}
if ( !$ENV{PERCONA_FORCE_VERSION_CHECK} ) { eval {
# 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;
}
}
}
# Name and ID the instances. The name is for debugging, # Name and ID the instances. The name is for debugging,
# and the ID is what the code uses to prevent double-checking. # and the ID is what the code uses to prevent double-checking.
foreach my $instance ( @$instances ) { foreach my $instance ( @$instances ) {
@@ -195,17 +169,19 @@ sub version_check {
} }
# Always update the vc file, even if the version check fails. # Always update the vc file, even if the version check fails.
eval { if ( @$instances_to_check ) {
# Update the check time for things we checked. I.e. if we eval {
# didn't check it, do _not_ update its time. # Update the check time for things we checked. I.e. if we
update_check_times( # didn't check it, do _not_ update its time.
instances => $instances_to_check, update_check_times(
vc_file => $args{vc_file}, # testing instances => $instances_to_check,
now => $args{now}, # testing vc_file => $args{vc_file}, # testing
); now => $args{now}, # testing
}; );
if ( $EVAL_ERROR ) { };
PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR); if ( $EVAL_ERROR ) {
PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR);
}
} }
if ( $ENV{PTDEBUG_VERSION_CHECK} ) { if ( $ENV{PTDEBUG_VERSION_CHECK} ) {

View File

@@ -107,31 +107,6 @@ checkconfig() {
fi fi
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 return $conf_err
} }

View File

@@ -38,32 +38,37 @@ unlink $vc_file if -f $vc_file;
$sb->create_dbs($master_dbh, ['test']); $sb->create_dbs($master_dbh, ['test']);
$sb->load_file('master', 't/pt-archiver/samples/tables1-4.sql'); $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`; $output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
like( like(
$output, $output,
qr/VersionCheck/, qr/VersionCheck:\d+ \d+ Server response/,
"Looks like the version-check happened" "Looks like the version-check happened"
) or diag($output); ) 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"); $rows = $master_dbh->selectall_arrayref("SELECT * FROM test.table_1");
is_deeply( is_deeply(
$rows, $rows,
[], [],
"Tool ran after version-check" "Tool ran after version-check"
) or diag(Dumper($rows)); ) or diag(Dumper($rows), $output);
ok(
-f $vc_file,
"Created version check file"
);
my $orig_vc_file = `cat $vc_file 2>/dev/null`;
# ########################################################################### # ###########################################################################
# v-c file should limit checks to 1 per 24 hours # 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`; $output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --version-check 2>&1`;
like( like(
@@ -78,7 +83,7 @@ is(
$new_vc_file, $new_vc_file,
$orig_vc_file, $orig_vc_file,
"Version check file not changed" "Version check file not changed"
); ) or diag($output);
unlink $vc_file if -f $vc_file; unlink $vc_file if -f $vc_file;
@@ -94,7 +99,7 @@ my $t = time - $t0;
like( like(
$output, $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" "The Percona server didn't respond"
); );
@@ -109,33 +114,46 @@ cmp_ok(
"Tool waited a short while for the Percona server to respond" "Tool waited a short while for the Percona server to respond"
); );
# ###########################################################################
# Disable --version-check.
# ###########################################################################
unlink $vc_file if -f $vc_file; unlink $vc_file if -f $vc_file;
# ########################################################################### $output = `PTDEBUG=1 $cmd --source F=$cnf,D=test,t=table_1 --where 1=1 --purge --no-version-check 2>&1`;
# 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`;
unlike( unlike(
$output, $output,
qr/VersionCheck/, qr/VersionCheck/,
"Looks like no --version-check disabled the version-check" "Looks like --no-version-check disabled the check"
) or diag($output); ) or diag($output);
ok( ok(
!-f $vc_file, !-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( ok(
!-f $vc_file, !-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. # Done.
@@ -144,4 +162,3 @@ unlink $vc_file if -f $vc_file;
$sb->wipe_clean($master_dbh); $sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing; done_testing;
exit;