From 5ff62d695629adda364f267398ff5abbe073c63e Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 12 Dec 2013 05:49:59 +0000 Subject: [PATCH] Fix tests. --- bin/pt-mysql-summary | 36 +++++++------------ lib/bash/collect_mysql_info.sh | 9 ++--- lib/bash/report_mysql_info.sh | 36 +++++++------------ t/lib/bash/report_mysql_info.sh | 1 + t/pt-mysql-summary/pt-mysql-summary.t | 4 +-- .../samples/expected_output_temp003.txt | 2 +- .../samples/expected_output_temp004.txt | 2 +- 7 files changed, 35 insertions(+), 55 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index bc97e65b..94f3a364 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -1036,9 +1036,10 @@ collect_mysql_info () { echo "pt-summary-internal-Config_File_path $cnf_file" >> "$dir/mysql-variables" collect_internal_vars "$dir/mysqld-executables" >> "$dir/mysql-variables" - if [ -n "${OPT_DATABASES}" ]; then - local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )" - get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump" + if [ "$OPT_DATABASES" -o "$OPT_ALL_DATABASES" ]; then + local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")" + local dbs="${OPT_DATABASES:-""}" + get_mysqldump_for "${trg_arg}" "$dbs" > "$dir/mysqldump" fi ( @@ -2243,27 +2244,16 @@ report_mysql_summary () { fi section "Schema" - if [ "${OPT_DATABASES}" ] \ - || [ "${OPT_ALL_DATABASES}" ] \ - || [ "${OPT_READ_SAMPLES}" ]; then - - if [ -z "$OPT_READ_SAMPLES" ]; then - local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")" - local dbstodump="${OPT_DATABASES:-""}" - get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump" - fi - - if [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ] \ - && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then - format_overall_db_stats "$dir/mysqldump" - elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then - echo "Skipping schema analysis as the directory passed in" \ - "doesn't have a dump file" - else - echo "Skipping schema analysis due to apparent error in dump file" - fi - else + if [ -s "$dir/mysqldump" ] \ + && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then + format_overall_db_stats "$dir/mysqldump" + elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then + echo "Skipping schema analysis because --read-samples $dir/mysqldump " \ + "does not exist" + elif [ -z "$OPT_DATABASES" -a -z "$OPT_ALL_DATABASES" ]; then echo "Specify --databases or --all-databases to dump and summarize schemas" + else + echo "Skipping schema analysis due to apparent error in dump file" fi section "Noteworthy Technologies" diff --git a/lib/bash/collect_mysql_info.sh b/lib/bash/collect_mysql_info.sh index 0be0d352..dd131633 100644 --- a/lib/bash/collect_mysql_info.sh +++ b/lib/bash/collect_mysql_info.sh @@ -250,10 +250,11 @@ collect_mysql_info () { echo "pt-summary-internal-Config_File_path $cnf_file" >> "$dir/mysql-variables" collect_internal_vars "$dir/mysqld-executables" >> "$dir/mysql-variables" - if [ -n "${OPT_DATABASES}" ]; then - # "--dump-schemas passed in, dumping early" - local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )" - get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump" + # mysqldump schemas + if [ "$OPT_DATABASES" -o "$OPT_ALL_DATABASES" ]; then + local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")" + local dbs="${OPT_DATABASES:-""}" + get_mysqldump_for "${trg_arg}" "$dbs" > "$dir/mysqldump" fi # TODO: gather this data in the same format as normal: TS line, stats diff --git a/lib/bash/report_mysql_info.sh b/lib/bash/report_mysql_info.sh index ac3722ae..e5401338 100644 --- a/lib/bash/report_mysql_info.sh +++ b/lib/bash/report_mysql_info.sh @@ -1318,31 +1318,19 @@ report_mysql_summary () { # Schema, databases, data type, other analysis. # ######################################################################## section "Schema" - if [ "${OPT_DATABASES:-""}" ] \ - || [ "${OPT_ALL_DATABASES:-""}" ] \ - || [ "${OPT_READ_SAMPLES:-""}" ]; then - - if [ -z "$OPT_READ_SAMPLES" ]; then - # --databases or --all-databases was specified - local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")" - local dbstodump="${OPT_DATABASES:-""}" - get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump" - fi - - # Test the result by checking the file, not by the exit status, because we - # might get partway through and then die, and the info is worth analyzing - # anyway. - if [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ] \ - && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then - format_overall_db_stats "$dir/mysqldump" - elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then - echo "Skipping schema analysis as the directory passed in" \ - "doesn't have a dump file" - else - echo "Skipping schema analysis due to apparent error in dump file" - fi - else + # Test the result by checking the file, not by the exit status, because we + # might get partway through and then die, and the info is worth analyzing + # anyway. + if [ -s "$dir/mysqldump" ] \ + && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then + format_overall_db_stats "$dir/mysqldump" + elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then + echo "Skipping schema analysis because --read-samples $dir/mysqldump " \ + "does not exist" + elif [ -z "$OPT_DATABASES" -a -z "$OPT_ALL_DATABASES" ]; then echo "Specify --databases or --all-databases to dump and summarize schemas" + else + echo "Skipping schema analysis due to apparent error in dump file" fi # ######################################################################## diff --git a/t/lib/bash/report_mysql_info.sh b/t/lib/bash/report_mysql_info.sh index 68515b9c..47e7c3b6 100644 --- a/t/lib/bash/report_mysql_info.sh +++ b/t/lib/bash/report_mysql_info.sh @@ -715,6 +715,7 @@ no_diff \ OPT_SLEEP=1 OPT_DATABASES="" OPT_READ_SAMPLES="" +OPT_ALL_DATABASES="" NAME_VAL_LEN=25 report_mysql_summary "$samples/tempdir" | tail -n+3 > "$PT_TMPDIR/got" no_diff "$PT_TMPDIR/got" "$samples/expected_result_report_summary.txt" diff --git a/t/pt-mysql-summary/pt-mysql-summary.t b/t/pt-mysql-summary/pt-mysql-summary.t index 520b740a..79e4328b 100644 --- a/t/pt-mysql-summary/pt-mysql-summary.t +++ b/t/pt-mysql-summary/pt-mysql-summary.t @@ -66,12 +66,12 @@ for my $i (2..7) { no_diff( sub { local $ENV{_NO_FALSE_NEGATIVES} = 1; - print `$env $trunk/bin/$tool --read-samples $trunk/t/pt-mysql-summary/samples/temp00$i -- --defaults-file=/tmp/12345/my.sandbox.cnf | tail -n+3 | perl -wlnpe 's/Skipping schema analysis.*/Skipping schema analysis/'` + print `$env $trunk/bin/$tool --read-samples $trunk/t/pt-mysql-summary/samples/temp00$i -- --defaults-file=/tmp/12345/my.sandbox.cnf | tail -n+3 | perl -wlnpe 's/Skipping schema analysis.*/Specify --databases or --all-databases to dump and summarize schemas/'` }, "t/pt-mysql-summary/samples/expected_output_temp00$i.txt", ), "--read-samples works for t/pt-mysql-summary/temp00$i", - ); + ) or diag($test_diff); } # Test that --help works under sh diff --git a/t/pt-mysql-summary/samples/expected_output_temp003.txt b/t/pt-mysql-summary/samples/expected_output_temp003.txt index dd297a63..7e88563b 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp003.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp003.txt @@ -108,7 +108,7 @@ Uptime 90000 1 1 Usage | 0% HitToInsertRatio | 0% # Schema ##################################################### -Skipping schema analysis +Specify --databases or --all-databases to dump and summarize schemas # Noteworthy Technologies #################################### SSL | No Explicit LOCK TABLES | No diff --git a/t/pt-mysql-summary/samples/expected_output_temp004.txt b/t/pt-mysql-summary/samples/expected_output_temp004.txt index da18e588..d38e07e6 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp004.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp004.txt @@ -107,7 +107,7 @@ Uptime 90000 1 1 Usage | 0% HitToInsertRatio | 0% # Schema ##################################################### -Skipping schema analysis +Specify --databases or --all-databases to dump and summarize schemas # Noteworthy Technologies #################################### SSL | No Explicit LOCK TABLES | No