Merge lp:~percona-toolkit-dev/percona-toolkit/find_my_cnf_file-bug-1070916 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 429
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/find_my_cnf_file-bug-1070916
Merge into: lp:percona-toolkit/2.1
Diff against target: 250 lines (+93/-46)
6 files modified
bin/pt-mysql-summary (+13/-14)
lib/bash/collect_mysql_info.sh (+16/-15)
t/lib/bash/collect_mysql_info.sh (+53/-11)
t/lib/bash/report_mysql_info.sh (+1/-1)
t/pt-mysql-summary/pt-mysql-summary.t (+6/-5)
t/pt-mysql-summary/samples/ps-mysqld-005.txt (+4/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/find_my_cnf_file-bug-1070916
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+131240@code.launchpad.net
To post a comment you must log in.
430. By Daniel Nichter

Use sys default cnf file since test machines have different ones.

431. By Daniel Nichter

Only cat cnf file > mysql-config-file if it exists.

432. By Daniel Nichter

Update collect_mysql_info in pt-mysql-summary.

433. By Daniel Nichter

Update pt-mysql-summary.t.

434. By Daniel Nichter

Conditionalize the number of files expected: 14 or 15 depending on if the box has a default my.cnf somewhere.

435. By Daniel Nichter

Fix some test plans.

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-mysql-summary'
--- bin/pt-mysql-summary 2012-10-12 20:38:12 +0000
+++ bin/pt-mysql-summary 2012-10-24 19:38:21 +0000
@@ -793,22 +793,21 @@
793 local port="${2:-""}"793 local port="${2:-""}"
794794
795 local cnf_file=""795 local cnf_file=""
796 if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then796
797 cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \797 if [ "$port" ]; then
798 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \798 cnf_file="$(grep --max-count 1 "/mysqld.*--port=$port" "$file" \
799 | head -n1)"799 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
800 else800 else
801 cnf_file="$(grep '/mysqld' "${file}" \801 cnf_file="$(grep --max-count 1 '/mysqld' "$file" \
802 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \802 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
803 | head -n1)"
804 fi803 fi
805804
806 if [ ! -n "${cnf_file}" ]; then805 if [ -z "$cnf_file" ]; then
807 cnf_file="/etc/my.cnf";806 if [ -e "/etc/my.cnf" ]; then
808 if [ ! -e "${cnf_file}" ]; then807 cnf_file="/etc/my.cnf"
809 cnf_file="/etc/mysql/my.cnf";808 elif [ -e "/etc/mysql/my.cnf" ]; then
810 fi809 cnf_file="/etc/mysql/my.cnf"
811 if [ ! -e "${cnf_file}" ]; then810 elif [ -e "/var/db/mysql/my.cnf" ]; then
812 cnf_file="/var/db/mysql/my.cnf";811 cnf_file="/var/db/mysql/my.cnf";
813 fi812 fi
814 fi813 fi
@@ -954,7 +953,7 @@
954 local port="$(get_var port "$dir/mysql-variables")"953 local port="$(get_var port "$dir/mysql-variables")"
955 local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"954 local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"
956955
957 cat "$cnf_file" > "$dir/mysql-config-file"956 [ -e "$cnf_file" ] && cat "$cnf_file" > "$dir/mysql-config-file"
958957
959 local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"958 local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"
960 local pid_file_exists=""959 local pid_file_exists=""
961960
=== modified file 'lib/bash/collect_mysql_info.sh'
--- lib/bash/collect_mysql_info.sh 2012-06-11 20:51:43 +0000
+++ lib/bash/collect_mysql_info.sh 2012-10-24 19:38:21 +0000
@@ -60,23 +60,24 @@
60 local port="${2:-""}"60 local port="${2:-""}"
6161
62 local cnf_file=""62 local cnf_file=""
63 if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then63
64 cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \64 if [ "$port" ]; then
65 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \65 # Find the cnf file for the specific port.
66 | head -n1)"66 cnf_file="$(grep --max-count 1 "/mysqld.*--port=$port" "$file" \
67 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
67 else68 else
68 cnf_file="$(grep '/mysqld' "${file}" \69 # Find the cnf file for the first mysqld instance.
69 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \70 cnf_file="$(grep --max-count 1 '/mysqld' "$file" \
70 | head -n1)"71 | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
71 fi72 fi
7273
73 if [ ! -n "${cnf_file}" ]; then74 if [ -z "$cnf_file" ]; then
74 # "Cannot autodetect config file, trying common locations"75 # Cannot autodetect config file, try common locations.
75 cnf_file="/etc/my.cnf";76 if [ -e "/etc/my.cnf" ]; then
76 if [ ! -e "${cnf_file}" ]; then77 cnf_file="/etc/my.cnf"
77 cnf_file="/etc/mysql/my.cnf";78 elif [ -e "/etc/mysql/my.cnf" ]; then
78 fi79 cnf_file="/etc/mysql/my.cnf"
79 if [ ! -e "${cnf_file}" ]; then80 elif [ -e "/var/db/mysql/my.cnf" ]; then
80 cnf_file="/var/db/mysql/my.cnf";81 cnf_file="/var/db/mysql/my.cnf";
81 fi82 fi
82 fi83 fi
@@ -233,7 +234,7 @@
233 local port="$(get_var port "$dir/mysql-variables")"234 local port="$(get_var port "$dir/mysql-variables")"
234 local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"235 local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"
235236
236 cat "$cnf_file" > "$dir/mysql-config-file"237 [ -e "$cnf_file" ] && cat "$cnf_file" > "$dir/mysql-config-file"
237238
238 local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"239 local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"
239 local pid_file_exists=""240 local pid_file_exists=""
240241
=== modified file 't/lib/bash/collect_mysql_info.sh'
--- t/lib/bash/collect_mysql_info.sh 2012-08-22 20:50:11 +0000
+++ t/lib/bash/collect_mysql_info.sh 2012-10-24 19:38:21 +0000
@@ -1,6 +1,6 @@
1#!/usr/bin/env bash1#!/usr/bin/env bash
22
3plan 203plan 24
44
5PT_TMPDIR="$TEST_PT_TMPDIR"5PT_TMPDIR="$TEST_PT_TMPDIR"
6PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"6PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
@@ -18,6 +18,19 @@
1818
19mkdir "$p"19mkdir "$p"
2020
21# This is mostly for the find_my_cnf_file tests.
22# Test machines may have one of these, and find_my_cnf_file will use
23# the same if the specific port-based cnf file isn't found.
24if [ -e "/etc/my.cnf" ]; then
25 sys_cnf_file="/etc/my.cnf"
26elif [ -e "/etc/mysql/my.cnf" ]; then
27 sys_cnf_file="/etc/mysql/my.cnf"
28elif [ -e "/var/db/mysql/my.cnf" ]; then
29 sys_cnf_file="/var/db/mysql/my.cnf";
30else
31 sys_cnf_file=""
32fi
33
21parse_options "$BIN_DIR/pt-mysql-summary" --sleep 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf34parse_options "$BIN_DIR/pt-mysql-summary" --sleep 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
2235
23CMD_MYSQL="$(_which mysql)"36CMD_MYSQL="$(_which mysql)"
@@ -28,7 +41,13 @@
2841
29file_count=$(ls "$p" | wc -l)42file_count=$(ls "$p" | wc -l)
3043
31is $file_count 14 "Creates the correct number of files (without --databases)"44if [ "$sys_cnf_file" ]; then
45 n_files=14
46else
47 n_files=13
48fi
49
50is $file_count $n_files "Creates the correct number of files (without --databases)"
3251
33awk '{print $1}' "$p/mysqld-instances" > "$PT_TMPDIR/collect_mysqld_instances1.test"52awk '{print $1}' "$p/mysqld-instances" > "$PT_TMPDIR/collect_mysqld_instances1.test"
34pids="$(_pidof mysqld)"53pids="$(_pidof mysqld)"
@@ -79,26 +98,49 @@
79 "collect_internal_vars works"98 "collect_internal_vars works"
8099
81# find_my_cnf_file100# find_my_cnf_file
101
102# We know the port is 12345 (2nd to last test), but the sandbox is started
103# with just --defaults-file, no --port, so find_my_cnf_file isn't going to
104# be able to get the specific cnf file.
82cnf_file=$(find_my_cnf_file "$p/mysqld-instances" ${port});105cnf_file=$(find_my_cnf_file "$p/mysqld-instances" ${port});
83106
84is \107is "$cnf_file" "$sys_cnf_file" "find_my_cnf_file gets the correct file"
85 "$cnf_file" \
86 "/tmp/12345/my.sandbox.cnf" \
87 "find_my_cnf_file gets the correct file"
88[ $? -ne 0 ] && diag "$p/mysqld-instances"108[ $? -ne 0 ] && diag "$p/mysqld-instances"
89109
110# ps-mysqld-001.txt has several instances:
111# port 3306 cnf -
112# port 12345 cnf /tmp/12345/my.sandbox.cnf
113# port 12346 cnf /tmp/12346/my.sandbox.cnf
114
90res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt")115res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt")
91is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt"116is "$res" "$sys_cnf_file" "ps-mysqld-001.txt no port"
117
118res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 3306)
119is "$res" "$sys_cnf_file" "ps-mysqld-001.txt port but no cnf"
120
121res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 999)
122is "$res" "$sys_cnf_file" "ps-mysqld-001.txt nonexistent port"
92123
93res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12346)124res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12346)
94is "$res" "/tmp/12346/my.sandbox.cnf" "ps-mysqld-001.txt with port"125is "$res" "/tmp/12346/my.sandbox.cnf" "ps-mysqld-001.txt port 12346"
126
127res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12345)
128is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt port 12345"
129
130# ps-mysqld-004.txt has 1 instance without --port using
131# --defaults-file=/var/lib/mysql/my.cnf
95132
96res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt")133res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt")
97is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt"134is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt no port"
98135
99res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt" 12345)136res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt" 12345)
100is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt with port"137is "$res" "$sys_cnf_file" "ps-mysqld-004.txt port 12345"
101138
139# ps-mysqld-005.txt has the 3 sandbox instances, but 12347
140# is first, which was causing bug 1070916.
141
142res=$(find_my_cnf_file "$samples/ps-mysqld-005.txt" 12345)
143is "$res" "$sys_cnf_file" "ps-mysqld-005.txt port 12345 (bug 1070916)"
102144
103# collect_mysql_databases145# collect_mysql_databases
104$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW DATABASES' > "$PT_TMPDIR/mysql_collect_databases" 2>/dev/null146$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW DATABASES' > "$PT_TMPDIR/mysql_collect_databases" 2>/dev/null
105147
=== modified file 't/lib/bash/report_mysql_info.sh'
--- t/lib/bash/report_mysql_info.sh 2012-08-24 23:18:36 +0000
+++ t/lib/bash/report_mysql_info.sh 2012-10-24 19:38:21 +0000
@@ -1,6 +1,6 @@
1#!/usr/bin/env bash1#!/usr/bin/env bash
22
3plan 323plan 33
44
5. "$LIB_DIR/alt_cmds.sh"5. "$LIB_DIR/alt_cmds.sh"
6. "$LIB_DIR/log_warn_die.sh"6. "$LIB_DIR/log_warn_die.sh"
77
=== modified file 't/pt-mysql-summary/pt-mysql-summary.t'
--- t/pt-mysql-summary/pt-mysql-summary.t 2012-04-02 22:25:17 +0000
+++ t/pt-mysql-summary/pt-mysql-summary.t 2012-10-24 19:38:21 +0000
@@ -32,13 +32,14 @@
32 "Using --save-samples doesn't mistakenly delete the target dir"32 "Using --save-samples doesn't mistakenly delete the target dir"
33);33);
3434
35# If the box has a default my.cnf (e.g. /etc/my.cnf) there
36# should be 15 files, else 14.
35my @files = glob("$dir/*");37my @files = glob("$dir/*");
3638my $n_files = scalar @files;
37is(39ok(
38 scalar @files,40 $n_files == 15 || $n_files == 14,
39 15,
40 "And leaves all files in there"41 "And leaves all files in there"
41);42) or diag($n_files, `ls -l $dir`);
4243
43undef($dir);44undef($dir);
4445
4546
=== added file 't/pt-mysql-summary/samples/ps-mysqld-005.txt'
--- t/pt-mysql-summary/samples/ps-mysqld-005.txt 1970-01-01 00:00:00 +0000
+++ t/pt-mysql-summary/samples/ps-mysqld-005.txt 2012-10-24 19:38:21 +0000
@@ -0,0 +1,4 @@
1 PID TTY STAT TIME COMMAND
2 1427 ? Sl 0:13 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12347/my.sandbox.cnf
3 20928 ? Sl 0:07 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12345/my.sandbox.cnf
4 29930 ? Sl 0:00 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12346/my.sandbox.cnf

Subscribers

People subscribed via source and target branches