Merge lp:~jtv/maas/bug-1359517 into lp:~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 2779
Proposed branch: lp:~jtv/maas/bug-1359517
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 74 lines (+47/-1)
3 files modified
Makefile (+1/-0)
src/provisioningserver/dhcp/detect.py (+1/-1)
utilities/check-maaslog-exception (+45/-0)
To merge this branch: bzr merge lp:~jtv/maas/bug-1359517
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+231670@code.launchpad.net

Commit message

Don't use maaslog.exception; use maaslog.error instead.

Description of the change

Apparently maaslog.exception is a complete no-no. So I added a lint check that forbids it; testing against every possible call is a losing game.

Most lint checks have the logic for finding source files right in the Makefile, but that makes things a bit verbose. Since I needed to customise the set of source files, I hid that part away in my checker script.

Jeroen

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Nice.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

> Nice.

Apart from the fact that it's mostly shell script, of course.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2014-08-18 13:44:26 +0000
3+++ Makefile 2014-08-21 05:24:11 +0000
4@@ -140,6 +140,7 @@
5 lint-py: bin/flake8
6 @find $(sources) -name '*.py' ! -path '*/migrations/*' \
7 -print0 | xargs -r0 bin/flake8 --ignore=E123 --config=/dev/null
8+ @./utilities/check-maaslog-exception
9
10 lint-doc:
11 @./utilities/doc-lint
12
13=== modified file 'src/provisioningserver/dhcp/detect.py'
14--- src/provisioningserver/dhcp/detect.py 2014-08-13 21:49:35 +0000
15+++ src/provisioningserver/dhcp/detect.py 2014-08-21 05:24:11 +0000
16@@ -359,7 +359,7 @@
17 try:
18 servers = probe_interface(interface, ip)
19 except socket.error:
20- maaslog.exception(
21+ maaslog.error(
22 "Failed to probe sockets; did you configure authbind as per "
23 "HACKING.txt?")
24 return
25
26=== added file 'utilities/check-maaslog-exception'
27--- utilities/check-maaslog-exception 1970-01-01 00:00:00 +0000
28+++ utilities/check-maaslog-exception 2014-08-21 05:24:11 +0000
29@@ -0,0 +1,45 @@
30+#!/usr/bin/env bash
31+# Copyright 2014 Canonical Ltd. This software is licensed under the
32+# GNU Affero General Public License version 3 (see the file LICENSE).
33+
34+# Check for use of "maaslog.exception" in the source tree. Code should use
35+# "maaslog.error" instead.
36+#
37+# Usage: check-maaslog-exception [branch]
38+#
39+# Where branch is an optional branch; defaults to the current directory.
40+
41+# Exit immediately if a command exits with a non-zero status.
42+set -o errexit
43+# Treat unset variables as an error when substituting.
44+set -o nounset
45+
46+
47+# Look for use of maaslog.exception in the source tree. Not tests, since
48+# they may also look for this mistake.
49+find_incorrect_usage() {
50+ # Find all Python files in src, except tests,
51+ # which have "maaslog.exception(" on a line that isn't a comment.
52+ find $1/src -name \*.py ! -path '*/tests/*' -print0 |
53+ xargs -r0 grep -n '^[^#]*\<maaslog\.exception('
54+}
55+
56+
57+main() {
58+ local branch="${1:-.}"
59+ local bad_calls="$(find_incorrect_usage "$branch")"
60+ if test -n "${bad_calls}"
61+ then
62+ cat >&2 <<EOF
63+Code appears to call maaslog.exception:
64+
65+${bad_calls}
66+
67+Use maaslog.error instead.
68+EOF
69+ exit 1
70+ fi
71+}
72+
73+
74+main