Merge ~seyeongkim/maas:lp1979403_to_3.0 into maas:3.0
- Git
- lp:~seyeongkim/maas
- lp1979403_to_3.0
- Merge into 3.0
Proposed by
Seyeong Kim
Status: | Merged |
---|---|
Approved by: | Jack Lloyd-Walters |
Approved revision: | 50e0ae68ae84d31e9cb2ee34362db4730702b92f |
Merge reported by: | MAAS Lander |
Merged at revision: | not available |
Proposed branch: | ~seyeongkim/maas:lp1979403_to_3.0 |
Merge into: | maas:3.0 |
Diff against target: |
374 lines (+123/-95) 3 files modified
creds.yaml (+0/-0) src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py (+56/-41) src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py (+67/-54) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jack Lloyd-Walters | Approve | ||
MAAS Lander | Approve | ||
Review via email: mp+437594@code.launchpad.net |
Commit message
backport fix for lp1979403 to 3.0
Description of the change
To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b lp1979403_to_3.0 lp:~seyeongkim/maas/+git/maas into -b 3.0 lp:~maas-committers/maas
STATUS: SUCCESS
COMMIT: 50e0ae68ae84d31
review:
Approve
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
UNABLE TO START LANDING
STATUS: MISSING COMMIT MESSAGE
Revision history for this message
MAAS Lander (maas-lander) wrote : | # |
LANDING
-b lp1979403_to_3.0 lp:~seyeongkim/maas/+git/maas into -b 3.0 lp:~maas-committers/maas
STATUS: FAILED BUILD
LOG: http://
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/creds.yaml b/creds.yaml |
2 | new file mode 100644 |
3 | index 0000000..e69de29 |
4 | --- /dev/null |
5 | +++ b/creds.yaml |
6 | diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py b/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py |
7 | index 42e4c79..340272e 100755 |
8 | --- a/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py |
9 | +++ b/src/metadataserver/builtin_scripts/commissioning_scripts/bmc_config.py |
10 | @@ -162,7 +162,7 @@ class IPMI(BMCConfig): |
11 | password=None, |
12 | ipmi_k_g="", |
13 | ipmi_privilege_level="", |
14 | - **kwargs |
15 | + **kwargs, |
16 | ): |
17 | self.username = username |
18 | self.password = password |
19 | @@ -174,7 +174,7 @@ class IPMI(BMCConfig): |
20 | def _bmc_get_config(self, section=None): |
21 | """Fetch and cache all BMC settings.""" |
22 | print("INFO: Reading current IPMI BMC values...") |
23 | - cmd = ["bmc-config", "--checkout"] |
24 | + cmd = ["bmc-config", "--checkout", "--verbose"] |
25 | if section: |
26 | cmd += ["-S", section] |
27 | try: |
28 | @@ -438,41 +438,53 @@ class IPMI(BMCConfig): |
29 | def _config_ipmi_lan_channel_settings(self): |
30 | """Enable IPMI-over-Lan (Lan_Channel) if it is disabled""" |
31 | print("INFO: Configuring IPMI Lan_Channel...") |
32 | - lan_channel = self._bmc_config.get("Lan_Channel", {}) |
33 | |
34 | - for key in [ |
35 | - "Volatile_Access_Mode", |
36 | - "Non_Volatile_Access_Mode", |
37 | + for channel in [ |
38 | + "Lan_Channel", |
39 | + "Lan_Channel_Channel_1", |
40 | + "Lan_Channel_Channel_2", |
41 | + "Lan_Channel_Channel_3", |
42 | ]: |
43 | - if lan_channel.get(key) != "Always_Available": |
44 | - print( |
45 | - "INFO: Enabling BMC network access - Lan_Channel:%s" % key |
46 | - ) |
47 | - # Some BMC's don't support setting Lan_Channel (see LP: #1287274). |
48 | - # If that happens, it would cause the script to fail preventing |
49 | - # the script from continuing. To address this, simply catch the |
50 | - # error, return and allow the script to continue. |
51 | - try: |
52 | - self._bmc_set("Lan_Channel", key, "Always_Available") |
53 | - except Exception: |
54 | + lan_channel = self._bmc_config.get(channel, {}) |
55 | + |
56 | + if not lan_channel: |
57 | + continue |
58 | + |
59 | + for key in [ |
60 | + "Volatile_Access_Mode", |
61 | + "Non_Volatile_Access_Mode", |
62 | + ]: |
63 | + if lan_channel.get(key) != "Always_Available": |
64 | print( |
65 | - "WARNING: Unable to set Lan_Channel:%s. " |
66 | - "BMC may be unavailable over the network!" % key |
67 | + "INFO: Enabling BMC network access - %s:%s" |
68 | + % (channel, key) |
69 | ) |
70 | - |
71 | - self._bmc_set_keys( |
72 | - "Lan_Channel", |
73 | - [ |
74 | - "%s_%s" % (auth_type, volatility) |
75 | - for auth_type in [ |
76 | - "Enable_User_Level_Auth", |
77 | - "Enable_Per_Message_Auth", |
78 | - "Enable_Pef_Alerting", |
79 | - ] |
80 | - for volatility in ["Volatile", "Non_Volatile"] |
81 | - ], |
82 | - "Yes", |
83 | - ) |
84 | + # Some BMC's don't support setting Lan_Channel (see LP: #1287274). |
85 | + # If that happens, it would cause the script to fail preventing |
86 | + # the script from continuing. To address this, simply catch the |
87 | + # error, return and allow the script to continue. |
88 | + try: |
89 | + self._bmc_set(channel, key, "Always_Available") |
90 | + except Exception: |
91 | + print( |
92 | + "WARNING: Unable to set %s:%s. " |
93 | + "BMC may be unavailable over the network!" |
94 | + % (channel, key) |
95 | + ) |
96 | + |
97 | + self._bmc_set_keys( |
98 | + channel, |
99 | + [ |
100 | + f"{auth_type}_{volatility}" |
101 | + for auth_type in [ |
102 | + "Enable_User_Level_Auth", |
103 | + "Enable_Per_Message_Auth", |
104 | + "Enable_Pef_Alerting", |
105 | + ] |
106 | + for volatility in ["Volatile", "Non_Volatile"] |
107 | + ], |
108 | + "Yes", |
109 | + ) |
110 | |
111 | def _config_lan_conf_auth(self): |
112 | """Configure Lan_Conf_Auth.""" |
113 | @@ -707,6 +719,9 @@ class IPMI(BMCConfig): |
114 | mac_address = None |
115 | for section_name, key in [ |
116 | ("Lan_Conf", "IP_Address"), |
117 | + ("Lan_Conf_Channel_1", "IP_Address"), |
118 | + ("Lan_Conf_Channel_2", "IP_Address"), |
119 | + ("Lan_Conf_Channel_3", "IP_Address"), |
120 | ("Lan6_Conf", "IPv6_Static_Addresses"), |
121 | ("Lan6_Conf", "IPv6_Dynamic_Addresses"), |
122 | ]: |
123 | @@ -729,28 +744,28 @@ class IPMI(BMCConfig): |
124 | time.sleep(2) |
125 | continue |
126 | if section_name.startswith("Lan6_"): |
127 | - return "[%s]" % ip, mac_address |
128 | - return ip, mac_address |
129 | + return section_name, "[%s]" % ip, mac_address |
130 | + return section_name, ip, mac_address |
131 | # No valid IP address was found. |
132 | - return None, mac_address |
133 | + return None, None, mac_address |
134 | |
135 | def get_bmc_ip(self): |
136 | """Configure and retreive IPMI BMC IP.""" |
137 | - ip_address, mac_address = self._get_bmc_ip() |
138 | + section_name, ip_address, mac_address = self._get_bmc_ip() |
139 | if ip_address: |
140 | return ip_address, mac_address |
141 | print("INFO: Attempting to enable preconfigured static IP on BMC...") |
142 | - self._bmc_set("Lan_Conf", "IP_Address_Source", "Static") |
143 | + self._bmc_set(section_name, "IP_Address_Source", "Static") |
144 | for _ in range(6): |
145 | time.sleep(10) |
146 | - ip_address, mac_address = self._get_bmc_ip(True) |
147 | + _, ip_address, mac_address = self._get_bmc_ip(True) |
148 | if ip_address: |
149 | return ip_address, mac_address |
150 | print("INFO: Attempting to enable DHCP on BMC...") |
151 | - self._bmc_set("Lan_Conf", "IP_Address_Source", "Use_DHCP") |
152 | + self._bmc_set(section_name, "IP_Address_Source", "Use_DHCP") |
153 | for _ in range(6): |
154 | time.sleep(10) |
155 | - ip_address, mac_address = self._get_bmc_ip(True) |
156 | + _, ip_address, mac_address = self._get_bmc_ip(True) |
157 | if ip_address: |
158 | print("WARNING: BMC is configured to use DHCP!") |
159 | return ip_address, mac_address |
160 | diff --git a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py |
161 | index 90f4af1..73e84b0 100644 |
162 | --- a/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py |
163 | +++ b/src/metadataserver/builtin_scripts/commissioning_scripts/tests/test_bmc_config.py |
164 | @@ -538,20 +538,25 @@ EndSection |
165 | self.assertRaises(SystemExit, self.ipmi.add_bmc_user) |
166 | |
167 | def test_set_ipmi_lan_channel_setting_verifies(self): |
168 | - self.ipmi._bmc_config = { |
169 | - "Lan_Channel": { |
170 | - "Volatile_Access_Mode": "Always_Available", |
171 | - "Non_Volatile_Access_Mode": "Always_Available", |
172 | + |
173 | + for channel in [ |
174 | + "Lan_Channel", |
175 | + "Lan_Channel_Channel_1", |
176 | + "Lan_Channel_Channel_2", |
177 | + "Lan_Channel_Channel_3", |
178 | + ]: |
179 | + self.ipmi._bmc_config = { |
180 | + channel: { |
181 | + "Volatile_Access_Mode": "Always_Available", |
182 | + "Non_Volatile_Access_Mode": "Always_Available", |
183 | + }, |
184 | } |
185 | - } |
186 | - mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
187 | - mock_bmc_set_keys = self.patch(self.ipmi, "_bmc_set_keys") |
188 | - self.ipmi._config_ipmi_lan_channel_settings() |
189 | - self.assertThat(mock_bmc_set, MockNotCalled()) |
190 | - self.assertThat( |
191 | - mock_bmc_set_keys, |
192 | - MockCalledOnceWith( |
193 | - "Lan_Channel", |
194 | + mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
195 | + mock_bmc_set_keys = self.patch(self.ipmi, "_bmc_set_keys") |
196 | + self.ipmi._config_ipmi_lan_channel_settings() |
197 | + self.assertFalse(mock_bmc_set.called) |
198 | + mock_bmc_set_keys.assert_called_once_with( |
199 | + channel, |
200 | [ |
201 | "%s_%s" % (auth_type, volatility) |
202 | for auth_type in [ |
203 | @@ -562,36 +567,36 @@ EndSection |
204 | for volatility in ["Volatile", "Non_Volatile"] |
205 | ], |
206 | "Yes", |
207 | - ), |
208 | - ) |
209 | + ) |
210 | |
211 | def test_set_ipmi_lan_channel_setting_enables(self): |
212 | - self.ipmi._bmc_config = { |
213 | - "Lan_Channel": { |
214 | - "Volatile_Access_Mode": "Disabled", |
215 | - "Non_Volatile_Access_Mode": "Pre_Boot_only", |
216 | + for channel in [ |
217 | + "Lan_Channel", |
218 | + "Lan_Channel_Channel_1", |
219 | + "Lan_Channel_Channel_2", |
220 | + "Lan_Channel_Channel_3", |
221 | + ]: |
222 | + self.ipmi._bmc_config = { |
223 | + channel: { |
224 | + "Volatile_Access_Mode": "Disabled", |
225 | + "Non_Volatile_Access_Mode": "Pre_Boot_only", |
226 | + }, |
227 | } |
228 | - } |
229 | - mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
230 | - mock_bmc_set_keys = self.patch(self.ipmi, "_bmc_set_keys") |
231 | - self.ipmi._config_ipmi_lan_channel_settings() |
232 | - self.assertThat( |
233 | - mock_bmc_set, |
234 | - MockCallsMatch( |
235 | - call( |
236 | - "Lan_Channel", "Volatile_Access_Mode", "Always_Available" |
237 | - ), |
238 | - call( |
239 | - "Lan_Channel", |
240 | - "Non_Volatile_Access_Mode", |
241 | - "Always_Available", |
242 | - ), |
243 | - ), |
244 | - ) |
245 | - self.assertThat( |
246 | - mock_bmc_set_keys, |
247 | - MockCalledOnceWith( |
248 | - "Lan_Channel", |
249 | + mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
250 | + mock_bmc_set_keys = self.patch(self.ipmi, "_bmc_set_keys") |
251 | + self.ipmi._config_ipmi_lan_channel_settings() |
252 | + mock_bmc_set.assert_has_calls( |
253 | + ( |
254 | + call(channel, "Volatile_Access_Mode", "Always_Available"), |
255 | + call( |
256 | + channel, |
257 | + "Non_Volatile_Access_Mode", |
258 | + "Always_Available", |
259 | + ), |
260 | + ) |
261 | + ) |
262 | + mock_bmc_set_keys.assert_called_once_with( |
263 | + channel, |
264 | [ |
265 | "%s_%s" % (auth_type, volatility) |
266 | for auth_type in [ |
267 | @@ -602,8 +607,7 @@ EndSection |
268 | for volatility in ["Volatile", "Non_Volatile"] |
269 | ], |
270 | "Yes", |
271 | - ), |
272 | - ) |
273 | + ) |
274 | |
275 | def test_config_lan_conf_auth(self): |
276 | self.ipmi._bmc_config = {"Lan_Channel_Auth": {}} |
277 | @@ -943,7 +947,9 @@ EndSection |
278 | "MAC_Address": mac_address, |
279 | } |
280 | } |
281 | - self.assertEqual((ip, mac_address), self.ipmi._get_bmc_ip()) |
282 | + self.assertEqual( |
283 | + ("Lan_Conf", ip, mac_address), self.ipmi._get_bmc_ip() |
284 | + ) |
285 | |
286 | def test_get_bmc_ipv6_static(self): |
287 | ip = factory.make_ipv6_address() |
288 | @@ -954,7 +960,9 @@ EndSection |
289 | "MAC_Address": mac_address, |
290 | } |
291 | } |
292 | - self.assertEqual((f"[{ip}]", mac_address), self.ipmi._get_bmc_ip()) |
293 | + self.assertEqual( |
294 | + ("Lan6_Conf", f"[{ip}]", mac_address), self.ipmi._get_bmc_ip() |
295 | + ) |
296 | |
297 | def test_get_bmc_ipv6_dynamic(self): |
298 | ip = factory.make_ipv6_address() |
299 | @@ -965,7 +973,9 @@ EndSection |
300 | "MAC_Address": mac_address, |
301 | } |
302 | } |
303 | - self.assertEqual((f"[{ip}]", mac_address), self.ipmi._get_bmc_ip()) |
304 | + self.assertEqual( |
305 | + ("Lan6_Conf", f"[{ip}]", mac_address), self.ipmi._get_bmc_ip() |
306 | + ) |
307 | |
308 | def test_get_bmc_ipv6_gets_mac_From_ipv4(self): |
309 | ip = factory.make_ipv6_address() |
310 | @@ -974,18 +984,20 @@ EndSection |
311 | "Lan_Conf": {"MAC_Address": mac_address}, |
312 | "Lan6_Conf": {"IPv6_Dynamic_Addresses": ip}, |
313 | } |
314 | - self.assertEqual((f"[{ip}]", mac_address), self.ipmi._get_bmc_ip()) |
315 | + self.assertEqual( |
316 | + ("Lan6_Conf", f"[{ip}]", mac_address), self.ipmi._get_bmc_ip() |
317 | + ) |
318 | |
319 | def test_get_bmc_ip_finds_none(self): |
320 | self.patch(self.ipmi, "_bmc_get").return_value = "" |
321 | - self.assertEqual((None, None), self.ipmi._get_bmc_ip()) |
322 | + self.assertEqual((None, None, None), self.ipmi._get_bmc_ip()) |
323 | |
324 | def test_get_bmc_ip(self): |
325 | ip = factory.make_ip_address() |
326 | mac_address = factory.make_mac_address() |
327 | mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
328 | mock_get_bmc_ip = self.patch(self.ipmi, "_get_bmc_ip") |
329 | - mock_get_bmc_ip.return_value = ip, mac_address |
330 | + mock_get_bmc_ip.return_value = None, ip, mac_address |
331 | |
332 | self.assertEqual((ip, mac_address), self.ipmi.get_bmc_ip()) |
333 | self.assertThat(mock_bmc_set, MockNotCalled()) |
334 | @@ -997,9 +1009,9 @@ EndSection |
335 | mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
336 | mock_get_bmc_ip = self.patch(self.ipmi, "_get_bmc_ip") |
337 | mock_get_bmc_ip.side_effect = ( |
338 | - (None, mac_address), |
339 | - (None, mac_address), |
340 | - (ip, mac_address), |
341 | + ("Lan_Conf", None, mac_address), |
342 | + ("Lan_Conf", None, mac_address), |
343 | + ("Lan_Conf", ip, mac_address), |
344 | ) |
345 | |
346 | self.assertEqual((ip, mac_address), self.ipmi.get_bmc_ip()) |
347 | @@ -1017,8 +1029,8 @@ EndSection |
348 | mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
349 | mock_get_bmc_ip = self.patch(self.ipmi, "_get_bmc_ip") |
350 | mock_get_bmc_ip.side_effect = ( |
351 | - *[(None, mac_address) for _ in range(8)], |
352 | - (ip, mac_address), |
353 | + *[("Lan_Conf", None, mac_address) for _ in range(8)], |
354 | + ("Lan_Conf", ip, mac_address), |
355 | ) |
356 | |
357 | self.assertEqual((ip, mac_address), self.ipmi.get_bmc_ip()) |
358 | @@ -1029,6 +1041,7 @@ EndSection |
359 | call("Lan_Conf", "IP_Address_Source", "Use_DHCP"), |
360 | ), |
361 | ) |
362 | + |
363 | self.assertThat( |
364 | mock_get_bmc_ip, |
365 | MockCallsMatch(call(), *[call(True) for _ in range(8)]), |
366 | @@ -1037,7 +1050,7 @@ EndSection |
367 | def test_get_bmc_ip_fails(self): |
368 | mock_bmc_set = self.patch(self.ipmi, "_bmc_set") |
369 | mock_get_bmc_ip = self.patch(self.ipmi, "_get_bmc_ip") |
370 | - mock_get_bmc_ip.return_value = (None, None) |
371 | + mock_get_bmc_ip.return_value = ("Lan_Conf", None, None) |
372 | |
373 | self.assertRaises(SystemExit, self.ipmi.get_bmc_ip) |
374 | self.assertThat( |
UNIT TESTS
-b lp1979403_to_3.0 lp:~seyeongkim/maas/+git/maas into -b 3.0 lp:~maas-committers/maas
STATUS: FAILED maas-ci. internal: 8080/job/ maas-tester/ 2001/consoleTex t 030d7eaa12ae594 8df9425d0c
LOG: http://
COMMIT: 8e96f30e178dbad