mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-06 20:38:22 +00:00
Simplify and maybe fix crash in replace_special_vars().
This commit is contained in:
14
bin/pt-agent
14
bin/pt-agent
@@ -7201,17 +7201,8 @@ sub replace_special_vars {
|
||||
$new_cmd = join(' ',
|
||||
map {
|
||||
$word = $_;
|
||||
if ( my ($runno) = $word =~ m/__RUN_(\d+)_OUTPUT__/ ) {
|
||||
if ( $output_files->[$runno] ) {
|
||||
$word = $output_files->[$runno];
|
||||
}
|
||||
else {
|
||||
die "Run$runno has no output for $word to access.\n";
|
||||
}
|
||||
}
|
||||
if ( my ($key) = $word =~ m/__STORE_([\w-]+)__/ ) {
|
||||
$word = $store->{$key};
|
||||
}
|
||||
$word =~ s/__RUN_(\d+)_OUTPUT__/$output_files->[$1]/g;
|
||||
$word =~ s/__STORE_([\w-]+)__/$store->{$1}/g;
|
||||
$word =~ s/__TS__/$ts/g;
|
||||
$word =~ s/__LIB__/$lib_dir/g;
|
||||
$word =~ s/__META__/$meta_dir/g;
|
||||
@@ -7222,7 +7213,6 @@ sub replace_special_vars {
|
||||
$word =~ s/__BIN_DIR__/$bin_dir/g;
|
||||
$word =~ s/__TRASH_FILE__/$spool_dir\/.trash\/$service/g;
|
||||
$word =~ s/__ENV__/$env/g;
|
||||
|
||||
$word;
|
||||
}
|
||||
split(/\s+/, $cmd)
|
||||
|
@@ -19,6 +19,7 @@ require "$trunk/bin/pt-agent";
|
||||
Percona::Toolkit->import(qw(have_required_args Dumper));
|
||||
|
||||
my @output_files = ();
|
||||
my $store = {};
|
||||
|
||||
sub test_replace {
|
||||
my (%args) = @_;
|
||||
@@ -36,6 +37,10 @@ sub test_replace {
|
||||
lib_dir => '/var/lib/pt-agent',
|
||||
meta_dir => '/var/lib/pt-agent/meta',
|
||||
stage_dir => '/var/spool/.tmp',
|
||||
spool_dir => '/var/spool',
|
||||
bin_dir => $trunk,
|
||||
ts => '123',
|
||||
store => $store,
|
||||
);
|
||||
|
||||
is(
|
||||
@@ -51,6 +56,12 @@ test_replace(
|
||||
expect => "pt-query-digest zero",
|
||||
);
|
||||
|
||||
$store->{slow_query_log_file} = 'slow.log';
|
||||
test_replace(
|
||||
cmd => "echo '__STORE_slow_query_log_file__' > /var/spool/pt-agent/.tmp/1371269644.rotate-slow-query-log-all-5.1.slow_query_log_file",
|
||||
expect => "echo 'slow.log' > /var/spool/pt-agent/.tmp/1371269644.rotate-slow-query-log-all-5.1.slow_query_log_file",
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
Reference in New Issue
Block a user