Merge lp:~smoser/maas/lp-1305282 into lp:~maas-committers/maas/trunk

Proposed by Scott Moser
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 2282
Proposed branch: lp:~smoser/maas/lp-1305282
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 14 lines (+2/-1)
1 file modified
contrib/preseeds_v2/enlist_userdata (+2/-1)
To merge this branch: bzr merge lp:~smoser/maas/lp-1305282
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+215341@code.launchpad.net

Commit message

enlist_userdata: fix issue if dig fails to reach a dns server

dig exits non-zero and writes a failure message to stdout if it fails to
reach dnsserver. If that occurred, we were assigning that output to
the host variable, and then trying to register the node with that host.

The fix here is to only assign host if the dig command was successful.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Please make the name of that variable a little bit clearer, e.g. dig_output. The “digout” is easy enough to figure out on its own, but when it comes to things that take just a little bit of figuring out, we've got an ocean of drops here. The cumulative effect is a substantial maintenance hazard.

In general, please try to write code for both audiences: future maintainers as well as computers. Especially when under pressure and sleep-deprived, it is really really easy to screw up when working with code like this. There is no shame in writing functions or “if” statements.

For example, what happens if ‘dig’ can reach the DNS server but the hostname lookup produces nothing? The ‘dig’ succeeds, ‘host’ remains empty... and then what? Things get a lot easier when the code is explicit about these things.

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

Oh, also: set a commit message saying what the change means and what it's for. Without a commit message, the branch simply won't land, without any explanation.

Revision history for this message
Scott Moser (smoser) wrote :

If dig succeeds and produces nothing to stdout (as in it didn't find anything) then host does not get assigned, and 'maas-enlist' will be called with no '--hostname' argument.

Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/preseeds_v2/enlist_userdata'
2--- contrib/preseeds_v2/enlist_userdata 2014-03-04 22:27:55 +0000
3+++ contrib/preseeds_v2/enlist_userdata 2014-04-11 13:59:28 +0000
4@@ -83,8 +83,9 @@
5 # thanks to 'IPAPPEND' (http://www.syslinux.org/wiki/index.php/SYSLINUX)
6 url="{{server_url}}"
7 host=""
8+ dig_output=""
9 ip=$(ifconfig eth0 | awk '$1 == "inet" { sub("addr:","",$2); print $2; }') &&
10- [ -n "${ip}" ] && host=$(dig +short -x $ip) && host=${host%.}
11+ [ -n "${ip}" ] && dig_output=$(dig +short -x $ip) && host=${dig_output%.}
12 # load ipmi modules
13 load_modules
14 pargs=""