Merge lp:~andreserl/maas/fix_lp1469846 into lp:~maas-committers/maas/trunk

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 4063
Proposed branch: lp:~andreserl/maas/fix_lp1469846
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 113 lines (+66/-1)
2 files modified
src/provisioningserver/drivers/hardware/tests/test_ucsm.py (+46/-0)
src/provisioningserver/drivers/hardware/ucsm.py (+20/-1)
To merge this branch: bzr merge lp:~andreserl/maas/fix_lp1469846
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+263283@code.launchpad.net

Commit message

When probe-and-enlist a UCSM chassis, only probe for servers/blades that have a service profile / MAC address created for them.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks okay but:
- David suggested a more thorough check, can you explain why you implemented only part of it?
- Missing test(s).

review: Needs Fixing
Revision history for this message
Andres Rodriguez (andreserl) wrote :

1. David's suggestion came after this patch.
2. If I have to write tests for this change, that means there's definitely something wrong as I would spend exponentially more time writing tests than the actual code, and that's unproductive :).

Revision history for this message
Raphaël Badin (rvb) wrote :

Looks better but some of the new code is still untested.

review: Needs Fixing
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Raphael,

I've addressed your comments other than adding the test for probe_lan_boot_options. I've spend over an hour trying to get it right, but I couldn't. If you can help with that would be great!

Thanks

Revision history for this message
Raphaël Badin (rvb) wrote :

> Hi Raphael,
>
> I've addressed your comments other than adding the test for
> probe_lan_boot_options. I've spend over an hour trying to get it right, but I
> couldn't. If you can help with that would be great!
>
> Thanks

Yeah, this one is painful because we don't have a proper test double so we're down for some serious patching ;).

http://paste.ubuntu.com/11806452/

Revision history for this message
Raphaël Badin (rvb) wrote :

Approved with my change ;)

review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :

thank you sir!

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

The attempt to merge lp:~andreserl/maas/fix_lp1469846 into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [87.4 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:6 http://security.ubuntu.com trusty-security/universe Sources [28.1 kB]
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [304 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:8 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [212 kB]
Get:9 http://security.ubuntu.com trusty-security/universe amd64 Packages [111 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [123 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [562 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [292 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,848 kB in 3s (563 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 phantomjs postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-n...

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

The attempt to merge lp:~andreserl/maas/fix_lp1469846 into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Hit http://security.ubuntu.com trusty-security Release.gpg
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Hit http://security.ubuntu.com trusty-security Release
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Hit http://nova.clouds.archive.ubuntu.com trusty-updates Release
Hit http://security.ubuntu.com trusty-security/main Sources
Hit http://security.ubuntu.com trusty-security/universe Sources
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 phantomjs postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-nose python-oauth python-openssl python-paramiko python-pexpect python-pip python-pocket-lint python-psycopg2 python-pyinotify python-pyparsing python-seamicroclient python...

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

The attempt to merge lp:~andreserl/maas/fix_lp1469846 into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [87.4 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [28.1 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [304 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [111 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [212 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [123 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [562 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [292 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,848 kB in 3s (592 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 phantomjs postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-n...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/drivers/hardware/tests/test_ucsm.py'
2--- src/provisioningserver/drivers/hardware/tests/test_ucsm.py 2015-05-07 18:14:38 +0000
3+++ src/provisioningserver/drivers/hardware/tests/test_ucsm.py 2015-07-02 04:20:13 +0000
4@@ -38,6 +38,7 @@
5 ANY,
6 call,
7 Mock,
8+ sentinel,
9 )
10 from provisioningserver.drivers.hardware import ucsm
11 from provisioningserver.drivers.hardware.ucsm import (
12@@ -55,6 +56,7 @@
13 power_control_ucsm,
14 power_state_ucsm,
15 probe_and_enlist_ucsm,
16+ probe_lan_boot_options,
17 probe_servers,
18 RO_KEYS,
19 set_lan_boot_default,
20@@ -334,6 +336,30 @@
21 self.assertThat(mock, MockCalledOnceWith('computeItem', ANY))
22
23
24+class TestProbeLanBootOptions(MAASTestCase):
25+ """Tests for ``probe_lan_boot_options``."""
26+
27+ def test_returns_result(self):
28+ api = make_api()
29+ server = sentinel.server
30+ mock_service_profile = Mock()
31+ mock_get_service_profile = self.patch(ucsm, 'get_service_profile')
32+ mock_get_service_profile.return_value = mock_service_profile
33+ mock_service_profile.get.return_value = sentinel.profile_get
34+ fake_result = make_fake_result('tag', 'lsbootLan')
35+ mock_config_resolve_children = self.patch(
36+ api, 'config_resolve_children')
37+ mock_config_resolve_children.return_value = fake_result
38+ self.assertEqual(1, len(probe_lan_boot_options(api, server)))
39+ self.assertThat(
40+ mock_config_resolve_children,
41+ MockCalledOnceWith(sentinel.profile_get))
42+ self.assertThat(
43+ mock_service_profile.get, MockCalledOnceWith('operBootPolicyName'))
44+ self.assertThat(
45+ mock_get_service_profile, MockCalledOnceWith(api, server))
46+
47+
48 class TestGetChildren(MAASTestCase):
49 """Tests for ``get_children``."""
50
51@@ -397,9 +423,29 @@
52 api = make_api()
53 self.patch(ucsm, 'get_servers').return_value = servers
54 self.patch(ucsm, 'get_macs').return_value = [mac]
55+ self.patch(ucsm, 'probe_lan_boot_options').return_value = ['option']
56 server_list = probe_servers(api)
57 self.assertEqual([(servers[0], [mac])], server_list)
58
59+ def test_no_results_with_no_server_macs(self):
60+ servers = [{'uuid': factory.make_UUID()}]
61+ api = make_api()
62+ self.patch(ucsm, 'get_servers').return_value = servers
63+ self.patch(ucsm, 'get_macs').return_value = []
64+ self.patch(ucsm, 'probe_lan_boot_options').return_value = ['option']
65+ server_list = probe_servers(api)
66+ self.assertEqual([], server_list)
67+
68+ def test_no_results_with_no_boot_options(self):
69+ servers = [{'uuid': factory.make_UUID()}]
70+ mac = 'mac'
71+ api = make_api()
72+ self.patch(ucsm, 'get_servers').return_value = servers
73+ self.patch(ucsm, 'get_macs').return_value = mac
74+ self.patch(ucsm, 'probe_lan_boot_options').return_value = []
75+ server_list = probe_servers(api)
76+ self.assertEqual([], server_list)
77+
78
79 class TestGetServerPowerControl(MAASTestCase):
80 """Tests for ``get_server_power_control``."""
81
82=== modified file 'src/provisioningserver/drivers/hardware/ucsm.py'
83--- src/provisioningserver/drivers/hardware/ucsm.py 2015-05-07 18:14:38 +0000
84+++ src/provisioningserver/drivers/hardware/ucsm.py 2015-07-02 04:20:13 +0000
85@@ -260,10 +260,29 @@
86 return macs
87
88
89+def probe_lan_boot_options(api, server):
90+ """Probe for LAN boot options available on a server."""
91+ service_profile = get_service_profile(api, server)
92+ boot_profile_dn = service_profile.get('operBootPolicyName')
93+ response = api.config_resolve_children(boot_profile_dn)
94+ return response.xpath('//outConfigs/lsbootLan')
95+
96+
97 def probe_servers(api):
98 """Retrieve the UUID and MAC addresses for servers from the UCS Manager."""
99 servers = get_servers(api)
100- server_list = [(s, get_macs(api, s)) for s in servers]
101+
102+ server_list = []
103+ for s in servers:
104+ # If the server does not have any MAC, then we don't add it.
105+ if not get_macs(api, s):
106+ continue
107+ # If the server does not have LAN boot option (can't boot from LAN),
108+ # then we don't add it.
109+ if not probe_lan_boot_options(api, s):
110+ continue
111+ server_list.append((s, get_macs(api, s)))
112+
113 return server_list
114
115