Merge lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 into lp:maas/1.4
- fix_ipmi_lp1234880_1.4
- Merge into 1.4
Status: | Merged |
---|---|
Approved by: | Raphaël Badin |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1716 |
Proposed branch: | lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 |
Merge into: | lp:maas/1.4 |
Diff against target: |
69 lines (+21/-9) 2 files modified
etc/maas/templates/commissioning-user-data/snippets/maas_ipmi_autodetect.py (+18/-7) etc/maas/templates/commissioning-user-data/snippets/maas_signal.py (+3/-2) |
To merge this branch: | bzr merge lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jeroen T. Vermeulen (community) | Approve | ||
Review via email: mp+192791@code.launchpad.net |
Commit message
Fix ipmi version autodetection
Description of the change
Julian Edwards (julian-edwards) wrote : | # |
On 06/11/13 13:20, Jeroen T. Vermeulen wrote:
> return y" that's normal in most languages, we like to do:
>
> if foo:
> return x
> else:
> return y
Actually we don't! The coding standard says to get rid of the "else:".
Jeroen T. Vermeulen (jtv) wrote : | # |
Really!? That's a bit of a change... Which coding standard is this, and where?
Julian Edwards (julian-edwards) wrote : | # |
On 06/11/13 13:32, Jeroen T. Vermeulen wrote:
> Really!? That's a bit of a change... Which coding standard is this, and where?
>
Sorry I can't find it, I thought it was in the LP style guide but it's
not. But I do remember getting berated for the else: when it's totally
unnecessary.
Jeroen T. Vermeulen (jtv) wrote : | # |
My advice was based on the erstwhile LP style guide (which was later eviscerated, of course).
Forgive me for saying this, but could it be that you were berated for the "else" in Go code, where until recently it broke the compiler? Come to think of it, right after we went back to Python from Go, I think I berated you once for *omitting* the "else." Could that be the source of the memory?
Julian Edwards (julian-edwards) wrote : | # |
On 06/11/13 15:51, Jeroen T. Vermeulen wrote:
> My advice was based on the erstwhile LP style guide (which was later eviscerated, of course).
>
> Forgive me for saying this, but could it be that you were berated for the "else" in Go code, where until recently it broke the compiler? Come to think of it, right after we went back to Python from Go, I think I berated you once for *omitting* the "else." Could that be the source of the memory?
>
No - it was very early on in my LP days. The else: clause is simply
redundant and I was told it's clearer to leave it out.
I've done it so much in my own code now (and seen it in LP code) that it
feels better. But perhaps that's confirmation bias? :)
Julian Edwards (julian-edwards) wrote : | # |
Andres, are you going to land this and release to saucy or abandon it?
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 into lp:maas/1.4 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Ign http://
Get:2 http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Hit http://
Get:6 http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Ign http://
Get:9 http://
Get:10 http://
Ign http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Ign http://
Ign http://
Fetched 677 kB in 0s (2,241 kB/s)
Reading package lists...
sudo DEBIAN_
--
Julian Edwards (julian-edwards) wrote : | # |
On Wednesday 29 Jan 2014 01:21:50 you wrote:
> invoke-rc.d: initscript rabbitmq-server, action "start" failed.
> dpkg: error processing rabbitmq-server (--configure):
> subprocess installed post-installation script returned error exit status 1
> Errors were encountered while processing:
> rabbitmq-server
> E: Sub-process /usr/bin/dpkg returned an error code (1)
> make: *** [install-
sigh. This is the bug where rabbit falls over if the hostname got changed
after it is installed. I'll log in to the lander and re-install it.
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 into lp:maas/1.4 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Ign http://
Get:2 http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Hit http://
Get:6 http://
Hit http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Hit http://
Hit http://
Ign http://
Get:9 http://
Get:10 http://
Ign http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Ign http://
Ign http://
Fetched 677 kB in 0s (2,257 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 into lp:maas/1.4 failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Ign http://
Get:2 http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Hit http://
Get:6 http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Hit http://
Hit http://
Ign http://
Get:9 http://
Get:10 http://
Ign http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Ign http://
Ign http://
Fetched 677 kB in 0s (2,058 kB/s)
Reading package lists...
sudo DEBIAN_
--
Preview Diff
1 | === modified file 'etc/maas/templates/commissioning-user-data/snippets/maas_ipmi_autodetect.py' |
2 | --- etc/maas/templates/commissioning-user-data/snippets/maas_ipmi_autodetect.py 2013-10-08 14:43:20 +0000 |
3 | +++ etc/maas/templates/commissioning-user-data/snippets/maas_ipmi_autodetect.py 2013-10-26 17:37:04 +0000 |
4 | @@ -68,18 +68,26 @@ |
5 | def commit_ipmi_settings(config): |
6 | (status, output) = commands.getstatusoutput('bmc-config --commit --filename %s' % config) |
7 | |
8 | -def get_maas_power_settings(user, password, ipaddress): |
9 | - return "%s,%s,%s" % (user, password, ipaddress) |
10 | +def get_maas_power_settings(user, password, ipaddress, version): |
11 | + return "%s,%s,%s,%s" % (user, password, ipaddress, version) |
12 | |
13 | -def get_maas_power_settings_json(user, password, ipaddress): |
14 | - power_params = {"power_address": ipaddress, "power_pass": password, "power_user": user} |
15 | - return json.dumps(power_params) |
16 | +def get_maas_power_settings_json(user, password, ipaddress, version): |
17 | + power_params = {"power_address": ipaddress, "power_pass": password, "power_user": user, "power_driver": version} |
18 | + return json.dumps(power_params) |
19 | |
20 | def generate_random_password(min=8,max=15): |
21 | length=random.randint(min,max) |
22 | letters=string.ascii_letters+string.digits |
23 | return ''.join([random.choice(letters) for _ in range(length)]) |
24 | |
25 | +def get_ipmi_version(): |
26 | + (status, output) = commands.getstatusoutput('ipmi-locate') |
27 | + show_re = re.compile('(IPMI\ Version:) (\d\.\d)') |
28 | + res = show_re.search(output) |
29 | + if res is None: |
30 | + return |
31 | + return res.group(2) |
32 | + |
33 | def main(): |
34 | |
35 | import argparse |
36 | @@ -129,10 +137,13 @@ |
37 | # has been detected |
38 | exit(1) |
39 | |
40 | + IPMI_VERSION = "LAN" |
41 | + if get_ipmi_version() == "2.0": |
42 | + IPMI_VERSION = "LAN_2_0" |
43 | if args.commission_creds: |
44 | - print get_maas_power_settings_json(IPMI_MAAS_USER, IPMI_MAAS_PASSWORD, IPMI_IP_ADDRESS) |
45 | + print get_maas_power_settings_json(IPMI_MAAS_USER, IPMI_MAAS_PASSWORD, IPMI_IP_ADDRESS, IPMI_VERSION) |
46 | else: |
47 | - print get_maas_power_settings(IPMI_MAAS_USER, IPMI_MAAS_PASSWORD, IPMI_IP_ADDRESS) |
48 | + print get_maas_power_settings(IPMI_MAAS_USER, IPMI_MAAS_PASSWORD, IPMI_IP_ADDRESS, IPMI_VERSION) |
49 | |
50 | if __name__ == '__main__': |
51 | main() |
52 | |
53 | === modified file 'etc/maas/templates/commissioning-user-data/snippets/maas_signal.py' |
54 | --- etc/maas/templates/commissioning-user-data/snippets/maas_signal.py 2013-10-09 14:37:13 +0000 |
55 | +++ etc/maas/templates/commissioning-user-data/snippets/maas_signal.py 2013-10-26 17:37:04 +0000 |
56 | @@ -160,11 +160,12 @@ |
57 | power_hwaddress=hwaddress |
58 | ) |
59 | else: |
60 | - user, passwd, address = args.power_parms.split(",") |
61 | + user, passwd, address, driver = args.power_parms.split(",") |
62 | power_parms = dict( |
63 | power_user=user, |
64 | power_pass=passwd, |
65 | - power_address=address |
66 | + power_address=address, |
67 | + power_driver=driver |
68 | ) |
69 | params["power_parameters"] = json.dumps(power_parms) |
70 |
Looks good, thanks! Since the snippets are increasingly "serious" code, I'll give some notes about coding conventions below. No actual complaints, just small tweaks that'll make it fit in more smoothly with the server-side codebase.
.
Make it a habit to run "make lint" before submitting. It would have told you that this line in etc/maas/ templates/ commissioning- user-data/ snippets/ maas_ipmi_ autodetect. py is too long:
power_params = {"power_address": ipaddress, "power_pass": password, "power_user": user, "power_driver": version}
It's line 17 in the diff. By MAAS standards we would format that as:
power_params = {
"power_ address" : ipaddress,
"power_ pass": password,
"power_ user": user,
"power_ driver" : version,
}
.
By the way, it's always good to explain what a function is for. Stating a function's purpose up front can make maintenance a lot easier in the future, when people who are less familiar with the code need to work on it. Even if it all feels obvious to you, chances are that when you stop and ask, you can think of things that a new maintainer will want to know right from the start.
Have a look at the source files anywhere in src/ for examples of docstrings.
.
A few small notes about get_ipmi_version, ll. 25—31 in the diff:
« getstatusoutput ('ipmi- locate' ) search( output)
def get_ipmi_version():
(status, output) = commands.
show_re = re.compile('(IPMI\ Version:) (\d\.\d)')
res = show_re.
if res is None:
return
return res.group(2)
»
It's not important, but just in case it's useful to you: that first assignment (status, output) doesn't need the parentheses. We normally leave them out. Of course if you like them for clarity, I'm not complaining!
Then, at the end of the function, "return" without a value will return None — but making use of that makes it look as if maybe at some point there was confusion about whether the function returns a value. If the function returns a value, better "return None" explicitly!
Also nice to know is that Python has a specific pattern for cases where you return different things based on a condition, but there's no real work to do depending on the condition. Instead of doing the "if foo: return x; return y" that's normal in most languages, we like to do:
if foo:
return x
else:
return y
Putting both returns at the same indentation level makes it instantly clear that these are two alternative exits to the function. Of course if you have lots of "early return" clauses dotted around the function anyway, you may still want to keep the style you used here.
.
The same thing goes for setting IPMI_VERSION. Instead of making a choice and then changing it, it's clearer to put the choice up front:
if get_ipmi_version() == "2.0":
IPMI_VERSION = "LAN_2_0"
IPMI_VERSION = "LAN"
else:
This also makes it clear what to do if there's ever a LAN_3_0 or whatever.
.
I'm not entirely without selfish interest here... At some point we're going to move to Python 3. The more consistent our coding habits are, the easier that will be for us. :-)
Jeroen