Add and test --config to pt-stalk.

This commit is contained in:
Daniel Nichter
2012-01-24 11:50:48 -07:00
parent 4905e3503c
commit 3c97ae27d1
3 changed files with 79 additions and 17 deletions

View File

@@ -54,12 +54,12 @@ die() {
set -u set -u
ARGV="" # Non-option args (probably input files) ARGV="" # Non-option args (probably input files)
EXT_ARGV="" # Everything after -- (args for an external command) EXT_ARGV="" # Everything after -- (args for an external command)
HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV
OPT_ERRS=0 # How many command line option errors OPT_ERRS=0 # How many command line option errors
OPT_VERSION="no" # If --version was specified OPT_VERSION="" # If --version was specified
OPT_HELP="no" # If --help was specified OPT_HELP="" # If --help was specified
PO_DIR="$TMPDIR/po" # Directory with program option spec files PO_DIR="$TMPDIR/po" # Directory with program option spec files
usage() { usage() {
@@ -74,13 +74,13 @@ usage() {
usage_or_errors() { usage_or_errors() {
local file="$1" local file="$1"
if [ "$OPT_VERSION" = "yes" ]; then if [ "$OPT_VERSION" ]; then
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
echo "$version" echo "$version"
return 1 return 1
fi fi
if [ "$OPT_HELP" = "yes" ]; then if [ "$OPT_HELP" ]; then
usage "$file" usage "$file"
echo echo
echo "Command line options:" echo "Command line options:"
@@ -111,8 +111,8 @@ parse_options() {
EXT_ARGV="" EXT_ARGV=""
HAVE_EXT_ARGV="" HAVE_EXT_ARGV=""
OPT_ERRS=0 OPT_ERRS=0
OPT_VERSION="no" OPT_VERSION=""
OPT_HELP="no" OPT_HELP=""
PO_DIR="$TMPDIR/po" PO_DIR="$TMPDIR/po"
if [ ! -d "$PO_DIR" ]; then if [ ! -d "$PO_DIR" ]; then
@@ -129,9 +129,23 @@ parse_options() {
exit 1 exit 1
fi fi
_parse_pod "$file" _parse_pod "$file" # Parse POD into program option (po) spec files
_eval_po _eval_po # Eval po into existence with default values
_parse_config_files
if [ $# -ge 2 ] && [ "$1" = "--config" ]; then
shift # --config
local user_config_files="$1"
shift # that ^
local old_ifs="$IFS"
IFS=","
for user_config_file in $user_config_files; do
_parse_config_files "$user_config_file"
done
IFS="$old_ifs"
else
_parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
fi
_parse_command_line "$@" _parse_command_line "$@"
} }
@@ -218,8 +232,8 @@ _eval_po() {
} }
_parse_config_files() { _parse_config_files() {
for config_file in "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf"
do for config_file in "$@"; do
test -f "$config_file" || continue test -f "$config_file" || continue
while read config_opt; do while read config_opt; do
@@ -228,12 +242,16 @@ _parse_config_files() {
config_opt="$(echo "$config_opt" | sed -e 's/^[ ]*//' -e 's/[ ]*\$//' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')" config_opt="$(echo "$config_opt" | sed -e 's/^[ ]*//' -e 's/[ ]*\$//' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
[ "$config_opt" = "" ] && continue
if ! [ "$HAVE_EXT_ARGV" ]; then if ! [ "$HAVE_EXT_ARGV" ]; then
config_opt="--$config_opt" config_opt="--$config_opt"
fi fi
_parse_command_line "$config_opt" _parse_command_line "$config_opt"
done < "$config_file" done < "$config_file"
HAVE_EXT_ARGV="" # reset for each file HAVE_EXT_ARGV="" # reset for each file
done done
@@ -1212,6 +1230,13 @@ Collect strace data.
Collect tcpdump data. Collect tcpdump data.
=item --config
type: string
Read this comma-separated list of config files. If specified, this must be the
first option on the command line.
=item --cycles =item --cycles
type: int; default: 5 type: int; default: 5

View File

@@ -10,6 +10,7 @@ use strict;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Test::More; use Test::More;
use Time::HiRes qw(sleep);
use PerconaTest; use PerconaTest;
use DSNParser; use DSNParser;
@@ -23,7 +24,7 @@ if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master'; plan skip_all => 'Cannot connect to sandbox master';
} }
else { else {
plan tests => 15; plan tests => 17;
} }
my $cnf = "/tmp/12345/my.sandbox.cnf"; my $cnf = "/tmp/12345/my.sandbox.cnf";
@@ -168,6 +169,34 @@ like(
"Trigger file logs how pt-stalk was ran" "Trigger file logs how pt-stalk was ran"
); );
# #############################################################################
# --config
# #############################################################################
diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`);
diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`);
system "$trunk/bin/pt-stalk --dest $dest --pid $pid_file >$log_file 2>&1 &";
sleep 1;
chomp($pid = `cat $pid_file`);
$retval = system("kill $pid 2>/dev/null");
is(
$retval >> 0,
0,
"Killed pt-stalk"
);
$output = `cat $log_file`;
like(
$output,
qr/Check results: Aborted_connects=|variable=Aborted_connects/,
"Read default config file"
);
diag(`rm $ENV{HOME}/.pt-stalk.conf`);
diag(`cp $ENV{HOME}/.pt-stalk.conf.original $ENV{HOME}/.pt-stalk.conf 2>/dev/null`);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################

View File

@@ -0,0 +1,8 @@
--iterations=1
--variable=Aborted_connects
--threshold=999999
--
-umsandbox
-pmsandbox
--host 127.1
--port 12345