mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-18 09:43:09 +00:00
*-summary tools: Changes from the reviews. Tests for pt-mysql-summary not finished yet
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 15
|
||||
plan 20
|
||||
|
||||
TMPDIR="$TEST_TMPDIR"
|
||||
PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
|
||||
@@ -28,10 +28,10 @@ wait
|
||||
|
||||
file_count=$(ls "$p" | wc -l)
|
||||
|
||||
is $file_count 12 "Creates the correct number of files (without --dump-schemas)"
|
||||
is $file_count 12 "Creates the correct number of files (without --databases)"
|
||||
|
||||
grep -v grep "$p/percona-toolkit-mysqld-instances" | awk '{print $2}' > "$TMPDIR/collect_mysqld_instances1.test"
|
||||
ps auxww 2>/dev/null | grep mysqld | grep -v grep | awk '{print $2}' > "$TMPDIR/collect_mysqld_instances2.test"
|
||||
awk '{print $1}' "$p/percona-toolkit-mysqld-instances" > "$TMPDIR/collect_mysqld_instances1.test"
|
||||
ps ww -p "$(_pidof mysqld | sed -e "s/ /,/g")" | awk '{print $1}' > "$TMPDIR/collect_mysqld_instances2.test"
|
||||
|
||||
no_diff \
|
||||
"$TMPDIR/collect_mysqld_instances1.test" \
|
||||
@@ -40,7 +40,7 @@ no_diff \
|
||||
|
||||
collect_mysqld_instances "$TMPDIR/collect_mysqld_instances3.test"
|
||||
|
||||
grep -v grep "$TMPDIR/collect_mysqld_instances3.test" | awk '{print $2}' > "$TMPDIR/collect_mysqld_instances4.test"
|
||||
awk '{print $1}' "$TMPDIR/collect_mysqld_instances3.test"> "$TMPDIR/collect_mysqld_instances4.test"
|
||||
|
||||
no_diff \
|
||||
"$TMPDIR/collect_mysqld_instances4.test" \
|
||||
@@ -127,3 +127,71 @@ if [ -n "$(get_var log_bin "$p/percona-toolkit-mysql-variables")" ]; then
|
||||
else
|
||||
skip 1 2 "no binlog"
|
||||
fi
|
||||
|
||||
# get_mysqldump_for
|
||||
|
||||
test_get_mysqldump_for () {
|
||||
local dir="$1"
|
||||
# Let's fake mysqldump
|
||||
|
||||
printf '#!/usr/bin/env bash\necho $@\n' > "$TMPDIR/mysqldump_fake.sh"
|
||||
chmod +x "$TMPDIR/mysqldump_fake.sh"
|
||||
local orig_mysqldump="$CMD_MYSQLDUMP"
|
||||
local CMD_MYSQLDUMP="$TMPDIR/mysqldump_fake.sh"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
--defaults-file=/tmp/12345/my.sandbox.cnf --no-data --skip-comments --skip-add-locks --skip-add-drop-table --compact --skip-lock-all-tables --skip-lock-tables --skip-set-charset --databases --all-databases
|
||||
EOF
|
||||
get_mysqldump_for "$dir/mysqldump_test_1" ''
|
||||
no_diff \
|
||||
"$dir/mysqldump_test_1" \
|
||||
"$TMPDIR/expected" \
|
||||
"get_mysqldump_for picks a name default"
|
||||
|
||||
get_mysqldump_for "$dir/mysqldump_test_2" '' '--all-databases'
|
||||
no_diff \
|
||||
"$dir/mysqldump_test_2" \
|
||||
"$TMPDIR/expected" \
|
||||
"..which is the same as if we explicitly set --all-databases"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
--defaults-file=/tmp/12345/my.sandbox.cnf --no-data --skip-comments --skip-add-locks --skip-add-drop-table --compact --skip-lock-all-tables --skip-lock-tables --skip-set-charset --databases a
|
||||
EOF
|
||||
get_mysqldump_for "$dir/mysqldump_test_3" '' 'a'
|
||||
no_diff \
|
||||
"$dir/mysqldump_test_3" \
|
||||
"$TMPDIR/expected" \
|
||||
"get_mysqldump_for: Explicitly setting a database works"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
--defaults-file=/tmp/12345/my.sandbox.cnf --no-data --skip-comments --skip-add-locks --skip-add-drop-table --compact --skip-lock-all-tables --skip-lock-tables --skip-set-charset --databases a b
|
||||
EOF
|
||||
get_mysqldump_for "$dir/mysqldump_test_4" '' 'a,b'
|
||||
no_diff \
|
||||
"$dir/mysqldump_test_4" \
|
||||
"$TMPDIR/expected" \
|
||||
"get_mysqldump_for: Two databases separated by a comma are interpreted correctly"
|
||||
|
||||
if [ -n "$orig_mysqldump" ]; then
|
||||
local CMD_MYSQLDUMP="$orig_mysqldump"
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'CREATE DATABASE collect_mysql_databases_test1;' 1>/dev/null 2>&1
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'CREATE DATABASE collect_mysql_databases_test2;' 1>/dev/null 2>&1
|
||||
|
||||
get_mysqldump_for "$dir/mysqldump_test_5" '' "collect_mysql_databases_test1,collect_mysql_databases_test2"
|
||||
|
||||
like \
|
||||
"$(cat $dir/mysqldump_test_5)" \
|
||||
'use `collect_mysql_databases_test1`.*use `collect_mysql_databases_test2`|use `collect_mysql_databases_test2`.*use `collect_mysql_databases_test1`' \
|
||||
"get_mysqldump_for dumps the dbs we request"
|
||||
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'DROP DATABASE collect_mysql_databases_test1;'
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'DROP DATABASE collect_mysql_databases_test2;'
|
||||
|
||||
else
|
||||
skip 1 1 "No mysqldump"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
mkdir "$TMPDIR/mysqldump"
|
||||
test_get_mysqldump_for "$TMPDIR/mysqldump"
|
||||
|
@@ -10,6 +10,7 @@ TOOL="pt-summary"
|
||||
. "$LIB_DIR/alt_cmds.sh"
|
||||
. "$LIB_DIR/parse_options.sh"
|
||||
. "$LIB_DIR/summary_common.sh"
|
||||
. "$LIB_DIR/parse_options.sh"
|
||||
. "$LIB_DIR/collect_system_info.sh"
|
||||
|
||||
# Prefix (with path) for the collect files.
|
||||
@@ -18,7 +19,8 @@ samples="$PERCONA_TOOLKIT_BRANCH/t/pt-summary/samples"
|
||||
|
||||
mkdir "$p"
|
||||
|
||||
OPT_SLEEP="1"
|
||||
parse_options "$BIN_DIR/pt-summary" --sleep 1
|
||||
|
||||
collect_system_data "$p"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
@@ -106,7 +108,7 @@ no_diff "$TMPDIR/got" "$TMPDIR/expected" "dmesg-007.txt"
|
||||
# raid_controller
|
||||
|
||||
rm "$TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
|
||||
raid_controller "$TMPDIR/raid_controller_outfile.tmp" "" ""
|
||||
raid_controller "" "" > "$TMPDIR/raid_controller_outfile.tmp"
|
||||
|
||||
is \
|
||||
"$(get_var raid_controller "$TMPDIR/raid_controller_outfile.tmp")" \
|
||||
@@ -114,14 +116,14 @@ is \
|
||||
"raid_controller has a sane default"
|
||||
|
||||
rm "$TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
|
||||
raid_controller "$TMPDIR/raid_controller_outfile.tmp" "" "$samples/lspci-001.txt"
|
||||
raid_controller "" "$samples/lspci-001.txt" > "$TMPDIR/raid_controller_outfile.tmp"
|
||||
is \
|
||||
"$(get_var raid_controller "$TMPDIR/raid_controller_outfile.tmp")" \
|
||||
"Fusion-MPT SAS" \
|
||||
"raid_controller gets the correct result from an lspci file"
|
||||
|
||||
rm "$TMPDIR/raid_controller_outfile.tmp" 2>/dev/null
|
||||
raid_controller "$TMPDIR/raid_controller_outfile.tmp" "$samples/dmesg-004.txt" ""
|
||||
raid_controller "$samples/dmesg-004.txt" "" > "$TMPDIR/raid_controller_outfile.tmp"
|
||||
is \
|
||||
"$(get_var raid_controller "$TMPDIR/raid_controller_outfile.tmp")" \
|
||||
"AACRAID" \
|
||||
@@ -157,6 +159,7 @@ test_linux_exclusive_collection () {
|
||||
local PT_SUMMARY_SKIP=""
|
||||
|
||||
mkdir "$dir/1"
|
||||
cp "$dir/sysctl" "$dir/1/"
|
||||
linux_exclusive_collection "$dir/1"
|
||||
|
||||
is \
|
||||
@@ -171,6 +174,7 @@ test_linux_exclusive_collection () {
|
||||
done
|
||||
|
||||
mkdir "$dir/2"
|
||||
cp "$dir/sysctl" "$dir/2/"
|
||||
linux_exclusive_collection "$dir/2"
|
||||
|
||||
is \
|
||||
@@ -192,6 +196,7 @@ platform="$(get_var platform "$p/summary")"
|
||||
|
||||
if [ "$platform" = "Linux" ]; then
|
||||
mkdir "$TMPDIR/linux_data"
|
||||
cp "$p/sysctl" "$TMPDIR/linux_data/sysctl"
|
||||
test_linux_exclusive_collection "$TMPDIR/linux_data"
|
||||
else
|
||||
skip 1 5 "Tests exclusive for Linux"
|
||||
@@ -249,7 +254,7 @@ forked_pid="$!"
|
||||
if [ -e /proc/$forked_pid/oom_adj ] \
|
||||
&& echo "-17" > /proc/$forked_pid/oom_adj 2>/dev/null; then
|
||||
|
||||
notable_processes_info "$TMPDIR/notable_procs"
|
||||
notable_processes_info > "$TMPDIR/notable_procs"
|
||||
like \
|
||||
"$(cat "$TMPDIR/notable_procs")" \
|
||||
"${forked_pid}\\s+-17" \
|
||||
@@ -274,7 +279,7 @@ test_dmidecode_system_info () {
|
||||
cmd_ok '! test -s "$dir/outfile"' "If dmidecode isn't found, produces nothing"
|
||||
|
||||
fake_command dmidecode '[$@]'
|
||||
dmidecode_system_info "$dir/outfile"
|
||||
dmidecode_system_info > "$dir/outfile"
|
||||
|
||||
cat <<EOF >> "$dir/expected"
|
||||
vendor [-s system-manufacturer]
|
||||
|
@@ -273,7 +273,8 @@ cat <<EOF > $TMPDIR/expected
|
||||
12345 /tmp/12345/data ? ? /tmp/12345/mysql_sandbox12345.sock
|
||||
12346 /tmp/12346/data ? ? /tmp/12346/mysql_sandbox12346.sock
|
||||
EOF
|
||||
parse_mysqld_instances "$samples/ps-mysqld-001.txt" > "$TMPDIR/got"
|
||||
touch "$TMPDIR/empty"
|
||||
parse_mysqld_instances "$samples/ps-mysqld-001.txt" "$TMPDIR/empty" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "ps-mysqld-001.txt"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
@@ -281,7 +282,7 @@ cat <<EOF > "$TMPDIR/expected"
|
||||
===== ========================== ==== === ======
|
||||
/var/lib/mysql ? ? /var/lib/mysql/mysql.sock
|
||||
EOF
|
||||
parse_mysqld_instances "$samples/ps-mysqld-002.txt" > "$TMPDIR/got"
|
||||
parse_mysqld_instances "$samples/ps-mysqld-002.txt" "$TMPDIR/empty" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "ps-mysqld-002.txt"
|
||||
|
||||
#parse_mysqld_instances
|
||||
@@ -290,7 +291,7 @@ cat <<EOF > $TMPDIR/expected
|
||||
===== ========================== ==== === ======
|
||||
3306 /mnt/data-store/mysql/data ? ? /tmp/mysql.sock
|
||||
EOF
|
||||
parse_mysqld_instances "$samples/ps-mysqld-003.txt" > "$TMPDIR/got"
|
||||
parse_mysqld_instances "$samples/ps-mysqld-003.txt" "$TMPDIR/empty" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "ps-mysqld-003.txt"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
@@ -303,7 +304,7 @@ cat <<EOF > "$TMPDIR/in"
|
||||
mysql 767 0.0 0.9 3492 1100 v0 I 3:01PM 0:00.07 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/freebsd.hsd1.va.comcast.net..pid
|
||||
mysql 818 0.0 17.4 45292 20584 v0 I 3:01PM 0:02.28 /usr/local/libexec/mysqld --defaults-extra-file=/var/db/mysql/my.cnf --basedir=/usr/local --datadir=/var/db/mysql --user=mysql --log-error=/var/db/mysql/freebsd.hsd1.va.comcast.net..err --pid-file=/var/db/mysql/freebsd.hsd1.va.comcast.net..pid
|
||||
EOF
|
||||
parse_mysqld_instances "$TMPDIR/in" > "$TMPDIR/got"
|
||||
parse_mysqld_instances "$TMPDIR/in" "$TMPDIR/empty" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "parse_mysqld_instances"
|
||||
|
||||
# ###########################################################################
|
||||
@@ -427,7 +428,7 @@ Uptime 90000 1 1
|
||||
Uptime_since_flush_status 90000 1
|
||||
EOF
|
||||
|
||||
join $samples/mysql-status-00{1,2}.txt > "$TMPDIR/in"
|
||||
join "$samples/mysql-status-001.txt" "$samples/mysql-status-002.txt" > "$TMPDIR/in"
|
||||
format_status_variables "$TMPDIR/in" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "format_status_variables"
|
||||
|
||||
@@ -435,7 +436,7 @@ no_diff "$TMPDIR/got" "$TMPDIR/expected" "format_status_variables"
|
||||
# format_overall_db_stats
|
||||
# ###########################################################################
|
||||
|
||||
cat <<EOF > $TMPDIR/expected
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
|
||||
Database Tables Views SPs Trigs Funcs FKs Partn
|
||||
mysql 17
|
||||
@@ -463,9 +464,8 @@ cat <<EOF > $TMPDIR/expected
|
||||
sakila 1 15 1 3 19 26 3 4 1 45 4 1 7 2
|
||||
|
||||
EOF
|
||||
format_overall_db_stats $samples/mysql-schema-001.txt > $TMPDIR/got
|
||||
no_diff $TMPDIR/got $TMPDIR/expected
|
||||
|
||||
format_overall_db_stats "$samples/mysql-schema-001.txt" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected"
|
||||
|
||||
cat <<EOF > $TMPDIR/expected
|
||||
|
||||
@@ -489,8 +489,11 @@ cat <<EOF > $TMPDIR/expected
|
||||
{chosen} 1 1
|
||||
|
||||
EOF
|
||||
format_overall_db_stats $samples/mysql-schema-002.txt > $TMPDIR/got
|
||||
no_diff $TMPDIR/got $TMPDIR/expected
|
||||
format_overall_db_stats "$samples/mysql-schema-002.txt" > "$TMPDIR/got"
|
||||
no_diff \
|
||||
"$TMPDIR/got" \
|
||||
"$TMPDIR/expected" \
|
||||
"format_overall_db_stats: single DB without CREATE DATABASE nor USE db defaults to {chosen}"
|
||||
|
||||
# ###########################################################################
|
||||
# format_innodb_status
|
||||
@@ -700,7 +703,8 @@ format_innodb_filters_test
|
||||
# ###########################################################################
|
||||
|
||||
OPT_SLEEP=1
|
||||
OPT_DUMP_SCHEMAS="mysql"
|
||||
OPT_DATABASES=""
|
||||
OPT_READ_SAMPLES=""
|
||||
NAME_VAL_LEN=25
|
||||
_NO_FALSE_NEGATIVES=1
|
||||
report_mysql_summary "$samples/tempdir" "percona-toolkit" | tail -n+3 > "$TMPDIR/got"
|
||||
|
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 40
|
||||
plan 42
|
||||
|
||||
. "$LIB_DIR/alt_cmds.sh"
|
||||
. "$LIB_DIR/log_warn_die.sh"
|
||||
. "$LIB_DIR/parse_options.sh"
|
||||
. "$LIB_DIR/summary_common.sh"
|
||||
. "$LIB_DIR/report_formatting.sh"
|
||||
. "$LIB_DIR/report_system_info.sh"
|
||||
@@ -1154,7 +1155,7 @@ parse_arcconf "$samples/arcconf-003_900285.txt" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "Bug 900285"
|
||||
|
||||
# report_system_summary
|
||||
PT_SUMMARY_SKIP=""
|
||||
parse_options "$BIN_DIR/pt-summary"
|
||||
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
Hostname |
|
||||
@@ -1430,5 +1431,11 @@ No volume groups found
|
||||
# The End ####################################################
|
||||
EOF
|
||||
|
||||
report_system_summary "$samples/Linux/001" | tail -n +3 > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "report_system_summary works with samples from Linux"
|
||||
report_system_summary "$samples/Linux/001" | tail -n +3 > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "report_system_summary works with samples from Linux (Ubuntu)"
|
||||
|
||||
report_system_summary "$samples/Linux/002" | tail -n +3 > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$samples/Linux/output_002.txt" "report_system_summary works with samples from Linux (CentOS 5.7, as root)"
|
||||
|
||||
report_system_summary "$samples/Linux/003" | tail -n +3 > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$samples/Linux/output_003.txt" "report_system_summary works with samples from Linux (CentOS 5.7, as non-root)"
|
||||
|
Reference in New Issue
Block a user