mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Add and test --config to pt-stalk.
This commit is contained in:
47
bin/pt-stalk
47
bin/pt-stalk
@@ -58,8 +58,8 @@ ARGV="" # Non-option args (probably input files)
|
||||
EXT_ARGV="" # Everything after -- (args for an external command)
|
||||
HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV
|
||||
OPT_ERRS=0 # How many command line option errors
|
||||
OPT_VERSION="no" # If --version was specified
|
||||
OPT_HELP="no" # If --help was specified
|
||||
OPT_VERSION="" # If --version was specified
|
||||
OPT_HELP="" # If --help was specified
|
||||
PO_DIR="$TMPDIR/po" # Directory with program option spec files
|
||||
|
||||
usage() {
|
||||
@@ -74,13 +74,13 @@ usage() {
|
||||
usage_or_errors() {
|
||||
local file="$1"
|
||||
|
||||
if [ "$OPT_VERSION" = "yes" ]; then
|
||||
if [ "$OPT_VERSION" ]; then
|
||||
local version=$(grep '^pt-[^ ]\+ [0-9]' "$file")
|
||||
echo "$version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$OPT_HELP" = "yes" ]; then
|
||||
if [ "$OPT_HELP" ]; then
|
||||
usage "$file"
|
||||
echo
|
||||
echo "Command line options:"
|
||||
@@ -111,8 +111,8 @@ parse_options() {
|
||||
EXT_ARGV=""
|
||||
HAVE_EXT_ARGV=""
|
||||
OPT_ERRS=0
|
||||
OPT_VERSION="no"
|
||||
OPT_HELP="no"
|
||||
OPT_VERSION=""
|
||||
OPT_HELP=""
|
||||
PO_DIR="$TMPDIR/po"
|
||||
|
||||
if [ ! -d "$PO_DIR" ]; then
|
||||
@@ -129,9 +129,23 @@ parse_options() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_parse_pod "$file"
|
||||
_eval_po
|
||||
_parse_config_files
|
||||
_parse_pod "$file" # Parse POD into program option (po) spec files
|
||||
_eval_po # Eval po into existence with default values
|
||||
|
||||
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 "$@"
|
||||
}
|
||||
|
||||
@@ -218,8 +232,8 @@ _eval_po() {
|
||||
}
|
||||
|
||||
_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
|
||||
|
||||
while read config_opt; do
|
||||
@@ -228,10 +242,14 @@ _parse_config_files() {
|
||||
|
||||
config_opt="$(echo "$config_opt" | sed -e 's/^[ ]*//' -e 's/[ ]*\$//' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')"
|
||||
|
||||
[ "$config_opt" = "" ] && continue
|
||||
|
||||
if ! [ "$HAVE_EXT_ARGV" ]; then
|
||||
config_opt="--$config_opt"
|
||||
fi
|
||||
|
||||
_parse_command_line "$config_opt"
|
||||
|
||||
done < "$config_file"
|
||||
|
||||
HAVE_EXT_ARGV="" # reset for each file
|
||||
@@ -1212,6 +1230,13 @@ Collect strace 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
|
||||
|
||||
type: int; default: 5
|
||||
|
@@ -10,6 +10,7 @@ use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use Time::HiRes qw(sleep);
|
||||
|
||||
use PerconaTest;
|
||||
use DSNParser;
|
||||
@@ -23,7 +24,7 @@ if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 15;
|
||||
plan tests => 17;
|
||||
}
|
||||
|
||||
my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||
@@ -168,6 +169,34 @@ like(
|
||||
"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.
|
||||
# #############################################################################
|
||||
|
8
t/pt-stalk/samples/config001.conf
Normal file
8
t/pt-stalk/samples/config001.conf
Normal file
@@ -0,0 +1,8 @@
|
||||
--iterations=1
|
||||
--variable=Aborted_connects
|
||||
--threshold=999999
|
||||
--
|
||||
-umsandbox
|
||||
-pmsandbox
|
||||
--host 127.1
|
||||
--port 12345
|
Reference in New Issue
Block a user