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
1=== modified file 'bin/pt-mysql-summary'
2--- bin/pt-mysql-summary 2012-10-12 20:38:12 +0000
3+++ bin/pt-mysql-summary 2012-10-24 19:38:21 +0000
4@@ -793,22 +793,21 @@
5 local port="${2:-""}"
6
7 local cnf_file=""
8- if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then
9- cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \
10- | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
11- | head -n1)"
12+
13+ if [ "$port" ]; then
14+ cnf_file="$(grep --max-count 1 "/mysqld.*--port=$port" "$file" \
15+ | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
16 else
17- cnf_file="$(grep '/mysqld' "${file}" \
18- | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
19- | head -n1)"
20+ cnf_file="$(grep --max-count 1 '/mysqld' "$file" \
21+ | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
22 fi
23
24- if [ ! -n "${cnf_file}" ]; then
25- cnf_file="/etc/my.cnf";
26- if [ ! -e "${cnf_file}" ]; then
27- cnf_file="/etc/mysql/my.cnf";
28- fi
29- if [ ! -e "${cnf_file}" ]; then
30+ if [ -z "$cnf_file" ]; then
31+ if [ -e "/etc/my.cnf" ]; then
32+ cnf_file="/etc/my.cnf"
33+ elif [ -e "/etc/mysql/my.cnf" ]; then
34+ cnf_file="/etc/mysql/my.cnf"
35+ elif [ -e "/var/db/mysql/my.cnf" ]; then
36 cnf_file="/var/db/mysql/my.cnf";
37 fi
38 fi
39@@ -954,7 +953,7 @@
40 local port="$(get_var port "$dir/mysql-variables")"
41 local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"
42
43- cat "$cnf_file" > "$dir/mysql-config-file"
44+ [ -e "$cnf_file" ] && cat "$cnf_file" > "$dir/mysql-config-file"
45
46 local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"
47 local pid_file_exists=""
48
49=== modified file 'lib/bash/collect_mysql_info.sh'
50--- lib/bash/collect_mysql_info.sh 2012-06-11 20:51:43 +0000
51+++ lib/bash/collect_mysql_info.sh 2012-10-24 19:38:21 +0000
52@@ -60,23 +60,24 @@
53 local port="${2:-""}"
54
55 local cnf_file=""
56- if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then
57- cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \
58- | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
59- | head -n1)"
60+
61+ if [ "$port" ]; then
62+ # Find the cnf file for the specific port.
63+ cnf_file="$(grep --max-count 1 "/mysqld.*--port=$port" "$file" \
64+ | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
65 else
66- cnf_file="$(grep '/mysqld' "${file}" \
67- | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
68- | head -n1)"
69+ # Find the cnf file for the first mysqld instance.
70+ cnf_file="$(grep --max-count 1 '/mysqld' "$file" \
71+ | awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
72 fi
73
74- if [ ! -n "${cnf_file}" ]; then
75- # "Cannot autodetect config file, trying common locations"
76- cnf_file="/etc/my.cnf";
77- if [ ! -e "${cnf_file}" ]; then
78- cnf_file="/etc/mysql/my.cnf";
79- fi
80- if [ ! -e "${cnf_file}" ]; then
81+ if [ -z "$cnf_file" ]; then
82+ # Cannot autodetect config file, try common locations.
83+ if [ -e "/etc/my.cnf" ]; then
84+ cnf_file="/etc/my.cnf"
85+ elif [ -e "/etc/mysql/my.cnf" ]; then
86+ cnf_file="/etc/mysql/my.cnf"
87+ elif [ -e "/var/db/mysql/my.cnf" ]; then
88 cnf_file="/var/db/mysql/my.cnf";
89 fi
90 fi
91@@ -233,7 +234,7 @@
92 local port="$(get_var port "$dir/mysql-variables")"
93 local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"
94
95- cat "$cnf_file" > "$dir/mysql-config-file"
96+ [ -e "$cnf_file" ] && cat "$cnf_file" > "$dir/mysql-config-file"
97
98 local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"
99 local pid_file_exists=""
100
101=== modified file 't/lib/bash/collect_mysql_info.sh'
102--- t/lib/bash/collect_mysql_info.sh 2012-08-22 20:50:11 +0000
103+++ t/lib/bash/collect_mysql_info.sh 2012-10-24 19:38:21 +0000
104@@ -1,6 +1,6 @@
105 #!/usr/bin/env bash
106
107-plan 20
108+plan 24
109
110 PT_TMPDIR="$TEST_PT_TMPDIR"
111 PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
112@@ -18,6 +18,19 @@
113
114 mkdir "$p"
115
116+# This is mostly for the find_my_cnf_file tests.
117+# Test machines may have one of these, and find_my_cnf_file will use
118+# the same if the specific port-based cnf file isn't found.
119+if [ -e "/etc/my.cnf" ]; then
120+ sys_cnf_file="/etc/my.cnf"
121+elif [ -e "/etc/mysql/my.cnf" ]; then
122+ sys_cnf_file="/etc/mysql/my.cnf"
123+elif [ -e "/var/db/mysql/my.cnf" ]; then
124+ sys_cnf_file="/var/db/mysql/my.cnf";
125+else
126+ sys_cnf_file=""
127+fi
128+
129 parse_options "$BIN_DIR/pt-mysql-summary" --sleep 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
130
131 CMD_MYSQL="$(_which mysql)"
132@@ -28,7 +41,13 @@
133
134 file_count=$(ls "$p" | wc -l)
135
136-is $file_count 14 "Creates the correct number of files (without --databases)"
137+if [ "$sys_cnf_file" ]; then
138+ n_files=14
139+else
140+ n_files=13
141+fi
142+
143+is $file_count $n_files "Creates the correct number of files (without --databases)"
144
145 awk '{print $1}' "$p/mysqld-instances" > "$PT_TMPDIR/collect_mysqld_instances1.test"
146 pids="$(_pidof mysqld)"
147@@ -79,26 +98,49 @@
148 "collect_internal_vars works"
149
150 # find_my_cnf_file
151+
152+# We know the port is 12345 (2nd to last test), but the sandbox is started
153+# with just --defaults-file, no --port, so find_my_cnf_file isn't going to
154+# be able to get the specific cnf file.
155 cnf_file=$(find_my_cnf_file "$p/mysqld-instances" ${port});
156
157-is \
158- "$cnf_file" \
159- "/tmp/12345/my.sandbox.cnf" \
160- "find_my_cnf_file gets the correct file"
161+is "$cnf_file" "$sys_cnf_file" "find_my_cnf_file gets the correct file"
162 [ $? -ne 0 ] && diag "$p/mysqld-instances"
163
164+# ps-mysqld-001.txt has several instances:
165+# port 3306 cnf -
166+# port 12345 cnf /tmp/12345/my.sandbox.cnf
167+# port 12346 cnf /tmp/12346/my.sandbox.cnf
168+
169 res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt")
170-is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt"
171+is "$res" "$sys_cnf_file" "ps-mysqld-001.txt no port"
172+
173+res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 3306)
174+is "$res" "$sys_cnf_file" "ps-mysqld-001.txt port but no cnf"
175+
176+res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 999)
177+is "$res" "$sys_cnf_file" "ps-mysqld-001.txt nonexistent port"
178
179 res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12346)
180-is "$res" "/tmp/12346/my.sandbox.cnf" "ps-mysqld-001.txt with port"
181+is "$res" "/tmp/12346/my.sandbox.cnf" "ps-mysqld-001.txt port 12346"
182+
183+res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12345)
184+is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt port 12345"
185+
186+# ps-mysqld-004.txt has 1 instance without --port using
187+# --defaults-file=/var/lib/mysql/my.cnf
188
189 res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt")
190-is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt"
191+is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt no port"
192
193 res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt" 12345)
194-is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt with port"
195-
196+is "$res" "$sys_cnf_file" "ps-mysqld-004.txt port 12345"
197+
198+# ps-mysqld-005.txt has the 3 sandbox instances, but 12347
199+# is first, which was causing bug 1070916.
200+
201+res=$(find_my_cnf_file "$samples/ps-mysqld-005.txt" 12345)
202+is "$res" "$sys_cnf_file" "ps-mysqld-005.txt port 12345 (bug 1070916)"
203
204 # collect_mysql_databases
205 $CMD_MYSQL $EXT_ARGV -ss -e 'SHOW DATABASES' > "$PT_TMPDIR/mysql_collect_databases" 2>/dev/null
206
207=== modified file 't/lib/bash/report_mysql_info.sh'
208--- t/lib/bash/report_mysql_info.sh 2012-08-24 23:18:36 +0000
209+++ t/lib/bash/report_mysql_info.sh 2012-10-24 19:38:21 +0000
210@@ -1,6 +1,6 @@
211 #!/usr/bin/env bash
212
213-plan 32
214+plan 33
215
216 . "$LIB_DIR/alt_cmds.sh"
217 . "$LIB_DIR/log_warn_die.sh"
218
219=== modified file 't/pt-mysql-summary/pt-mysql-summary.t'
220--- t/pt-mysql-summary/pt-mysql-summary.t 2012-04-02 22:25:17 +0000
221+++ t/pt-mysql-summary/pt-mysql-summary.t 2012-10-24 19:38:21 +0000
222@@ -32,13 +32,14 @@
223 "Using --save-samples doesn't mistakenly delete the target dir"
224 );
225
226+# If the box has a default my.cnf (e.g. /etc/my.cnf) there
227+# should be 15 files, else 14.
228 my @files = glob("$dir/*");
229-
230-is(
231- scalar @files,
232- 15,
233+my $n_files = scalar @files;
234+ok(
235+ $n_files == 15 || $n_files == 14,
236 "And leaves all files in there"
237-);
238+) or diag($n_files, `ls -l $dir`);
239
240 undef($dir);
241
242
243=== added file 't/pt-mysql-summary/samples/ps-mysqld-005.txt'
244--- t/pt-mysql-summary/samples/ps-mysqld-005.txt 1970-01-01 00:00:00 +0000
245+++ t/pt-mysql-summary/samples/ps-mysqld-005.txt 2012-10-24 19:38:21 +0000
246@@ -0,0 +1,4 @@
247+ PID TTY STAT TIME COMMAND
248+ 1427 ? Sl 0:13 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12347/my.sandbox.cnf
249+ 20928 ? Sl 0:07 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12345/my.sandbox.cnf
250+ 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