Merge lp:~andreserl/maas/fix_ipmi_lp1234880_1.4 into lp:maas/1.4

Proposed by Andres Rodriguez
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
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

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

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:

«
def get_ipmi_version():
    (status, output) = commands.getstatusoutput('ipmi-locate')
    show_re = re.compile('(IPMI\ Version:) (\d\.\d)')
    res = show_re.search(output)
    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"
    else:
        IPMI_VERSION = "LAN"

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

review: Approve
Revision history for this message
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:".

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

Really!? That's a bit of a change... Which coding standard is this, and where?

Revision history for this message
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.

Revision history for this message
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?

Revision history for this message
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? :)

Revision history for this message
Julian Edwards (julian-edwards) wrote :

Andres, are you going to land this and release to saucy or abandon it?

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (87.5 KiB)

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://security.ubuntu.com saucy-security InRelease
Get:1 http://security.ubuntu.com saucy-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com saucy InRelease
Get:2 http://security.ubuntu.com saucy-security Release [49.6 kB]
Ign http://nova.clouds.archive.ubuntu.com saucy-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com saucy Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com saucy-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com saucy Release
Get:4 http://nova.clouds.archive.ubuntu.com saucy-updates Release [49.6 kB]
Get:5 http://security.ubuntu.com saucy-security/main Sources [27.2 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/main Sources
Get:6 http://security.ubuntu.com saucy-security/universe Sources [8,363 B]
Get:7 http://security.ubuntu.com saucy-security/main amd64 Packages [76.0 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/universe Sources
Hit http://nova.clouds.archive.ubuntu.com saucy/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com saucy/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com saucy/main Translation-en
Get:8 http://security.ubuntu.com saucy-security/universe amd64 Packages [30.7 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/universe Translation-en
Hit http://security.ubuntu.com saucy-security/main Translation-en
Hit http://security.ubuntu.com saucy-security/universe Translation-en
Ign http://security.ubuntu.com saucy-security/main Translation-en_US
Get:9 http://nova.clouds.archive.ubuntu.com saucy-updates/main Sources [67.7 kB]
Get:10 http://nova.clouds.archive.ubuntu.com saucy-updates/universe Sources [44.2 kB]
Ign http://security.ubuntu.com saucy-security/universe Translation-en_US
Get:11 http://nova.clouds.archive.ubuntu.com saucy-updates/main amd64 Packages [192 kB]
Get:12 http://nova.clouds.archive.ubuntu.com saucy-updates/universe amd64 Packages [130 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com saucy-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com saucy/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy/universe Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy-updates/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy-updates/universe Translation-en_US
Fetched 677 kB in 0s (2,241 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 avahi-daemon avahi-utils bind9 bind9utils build-essential curl daemontools distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make postgresql-9.1 python-amqplib python-avahi python-bzrlib python-celery python-convoy python-cssselect python-curtin python-dbus python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-formencode python-httplib2 python-jinja2 python-lockfile python-lx...

Revision history for this message
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-dependencies] Error 100

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.

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (25.0 KiB)

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://security.ubuntu.com saucy-security InRelease
Get:1 http://security.ubuntu.com saucy-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com saucy InRelease
Get:2 http://security.ubuntu.com saucy-security Release [49.6 kB]
Ign http://nova.clouds.archive.ubuntu.com saucy-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com saucy Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com saucy-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com saucy Release
Get:4 http://nova.clouds.archive.ubuntu.com saucy-updates Release [49.6 kB]
Get:5 http://security.ubuntu.com saucy-security/main Sources [27.2 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/main Sources
Get:6 http://security.ubuntu.com saucy-security/universe Sources [8,363 B]
Hit http://nova.clouds.archive.ubuntu.com saucy/universe Sources
Get:7 http://security.ubuntu.com saucy-security/main amd64 Packages [76.0 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com saucy/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com saucy/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com saucy/universe Translation-en
Get:8 http://security.ubuntu.com saucy-security/universe amd64 Packages [30.7 kB]
Hit http://security.ubuntu.com saucy-security/main Translation-en
Hit http://security.ubuntu.com saucy-security/universe Translation-en
Ign http://security.ubuntu.com saucy-security/main Translation-en_US
Get:9 http://nova.clouds.archive.ubuntu.com saucy-updates/main Sources [67.7 kB]
Get:10 http://nova.clouds.archive.ubuntu.com saucy-updates/universe Sources [44.2 kB]
Ign http://security.ubuntu.com saucy-security/universe Translation-en_US
Get:11 http://nova.clouds.archive.ubuntu.com saucy-updates/main amd64 Packages [192 kB]
Get:12 http://nova.clouds.archive.ubuntu.com saucy-updates/universe amd64 Packages [130 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com saucy-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com saucy/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy/universe Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy-updates/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy-updates/universe Translation-en_US
Fetched 677 kB in 0s (2,257 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 avahi-daemon avahi-utils bind9 bind9utils build-essential curl daemontools distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make postgresql-9.1 python-amqplib python-avahi python-bzrlib python-celery python-convoy python-cssselect python-curtin python-dbus python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-formencode python-httplib2 python-jinja2 python-lockfile python-lx...

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (20.6 KiB)

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://security.ubuntu.com saucy-security InRelease
Get:1 http://security.ubuntu.com saucy-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com saucy InRelease
Get:2 http://security.ubuntu.com saucy-security Release [49.6 kB]
Ign http://nova.clouds.archive.ubuntu.com saucy-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com saucy Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com saucy-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com saucy Release
Get:4 http://nova.clouds.archive.ubuntu.com saucy-updates Release [49.6 kB]
Get:5 http://security.ubuntu.com saucy-security/main Sources [27.2 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/main Sources
Get:6 http://security.ubuntu.com saucy-security/universe Sources [8,363 B]
Get:7 http://security.ubuntu.com saucy-security/main amd64 Packages [76.0 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy/universe Sources
Hit http://nova.clouds.archive.ubuntu.com saucy/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com saucy/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com saucy/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com saucy/universe Translation-en
Get:8 http://security.ubuntu.com saucy-security/universe amd64 Packages [30.7 kB]
Hit http://security.ubuntu.com saucy-security/main Translation-en
Hit http://security.ubuntu.com saucy-security/universe Translation-en
Ign http://security.ubuntu.com saucy-security/main Translation-en_US
Get:9 http://nova.clouds.archive.ubuntu.com saucy-updates/main Sources [67.7 kB]
Get:10 http://nova.clouds.archive.ubuntu.com saucy-updates/universe Sources [44.2 kB]
Ign http://security.ubuntu.com saucy-security/universe Translation-en_US
Get:11 http://nova.clouds.archive.ubuntu.com saucy-updates/main amd64 Packages [192 kB]
Get:12 http://nova.clouds.archive.ubuntu.com saucy-updates/universe amd64 Packages [130 kB]
Hit http://nova.clouds.archive.ubuntu.com saucy-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com saucy-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com saucy/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy/universe Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy-updates/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com saucy-updates/universe Translation-en_US
Fetched 677 kB in 0s (2,058 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 avahi-daemon avahi-utils bind9 bind9utils build-essential curl daemontools distro-info dnsutils firefox freeipmi-tools ipython isc-dhcp-common libjs-raphael libjs-yui3-full libjs-yui3-min libpq-dev make postgresql-9.1 python-amqplib python-avahi python-bzrlib python-celery python-convoy python-cssselect python-curtin python-dbus python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-formencode python-httplib2 python-jinja2 python-lockfile python-lx...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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

Subscribers

People subscribed via source and target branches