Merge lp:~andreserl/maas/fix_lp1469846 into lp:~maas-committers/maas/trunk
- fix_lp1469846
- Merge into trunk
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 |
Related bugs: |
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.
Description of the change
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 :).
Raphaël Badin (rvb) wrote : | # |
Looks better but some of the new code is still untested.
Andres Rodriguez (andreserl) wrote : | # |
Hi Raphael,
I've addressed your comments other than adding the test for probe_lan_
Thanks
Raphaël Badin (rvb) wrote : | # |
> Hi Raphael,
>
> I've addressed your comments other than adding the test for
> probe_lan_
> 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 ;).
Raphaël Badin (rvb) wrote : | # |
Approved with my change ;)
Andres Rodriguez (andreserl) wrote : | # |
thank you sir!
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~andreserl/maas/fix_lp1469846 into lp:maas failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign 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://
Get:9 http://
Hit http://
Hit http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,848 kB in 3s (563 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~andreserl/maas/fix_lp1469846 into lp:maas failed. Below is the output from the failed tests.
Ign http://
Hit http://
Ign http://
Hit http://
Ign http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~andreserl/maas/fix_lp1469846 into lp:maas failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Hit http://
Hit http://
Get:9 http://
Hit http://
Hit http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,848 kB in 3s (592 kB/s)
Reading package lists...
sudo DEBIAN_
--
Preview Diff
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 |
Looks okay but:
- David suggested a more thorough check, can you explain why you implemented only part of it?
- Missing test(s).