Merge ~andreserl/maas:lp1664822_2 into maas:master

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: af4666921684840c983209c7b28f0c66237dddb3
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andreserl/maas:lp1664822_2
Merge into: maas:master
Diff against target: 102 lines (+29/-25)
4 files modified
contrib/preseeds_v2/enlist_userdata (+0/-12)
src/metadataserver/user_data/templates/commissioning.template (+0/-12)
src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py (+8/-1)
src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py (+21/-0)
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+327396@code.launchpad.net

Commit message

LP: #1664822 - Ensure failure to set Lan_Channel doesn't cause complete script failure

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good, but missing a unit test for when bmc_set() raises.

review: Needs Fixing
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good; thanks for the fix.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/contrib/preseeds_v2/enlist_userdata b/contrib/preseeds_v2/enlist_userdata
2index 6085775..408a198 100644
3--- a/contrib/preseeds_v2/enlist_userdata
4+++ b/contrib/preseeds_v2/enlist_userdata
5@@ -50,18 +50,6 @@ misc_bucket:
6 chmod "${2:-644}" "${IPMI_CONFIG_D}/$1"
7 }
8
9- # Example config: enable BMC remote access (on some systems.)
10- #add_ipmi_config "02-global-config.ipmi" <<"END_IPMI_CONFIG"
11- #Section Lan_Channel
12- # Volatile_Access_Mode Always_Available
13- # Volatile_Enable_User_Level_Auth Yes
14- # Volatile_Channel_Privilege_Limit Administrator
15- # Non_Volatile_Access_Mode Always_Available
16- # Non_Volatile_Enable_User_Level_Auth Yes
17- # Non_Volatile_Channel_Privilege_Limit Administrator
18- #EndSection
19- #END_IPMI_CONFIG
20-
21 add_bin "maas-ipmi-autodetect-tool" <<"END_MAAS_IPMI_AUTODETECT_TOOL"
22 {{for line in maas_ipmi_autodetect_tool_py.splitlines()}}
23 {{line}}
24diff --git a/src/metadataserver/user_data/templates/commissioning.template b/src/metadataserver/user_data/templates/commissioning.template
25index e29c774..f0d49ab 100644
26--- a/src/metadataserver/user_data/templates/commissioning.template
27+++ b/src/metadataserver/user_data/templates/commissioning.template
28@@ -69,18 +69,6 @@ main() {
29
30 ### begin writing files ###
31
32-# Example config: enable BMC remote access (on some systems.)
33-#add_ipmi_config "02-global-config.ipmi" <<"END_IPMI_CONFIG"
34-#Section Lan_Channel
35-# Volatile_Access_Mode Always_Available
36-# Volatile_Enable_User_Level_Auth Yes
37-# Volatile_Channel_Privilege_Limit Administrator
38-# Non_Volatile_Access_Mode Always_Available
39-# Non_Volatile_Enable_User_Level_Auth Yes
40-# Non_Volatile_Channel_Privilege_Limit Administrator
41-#EndSection
42-#END_IPMI_CONFIG
43-
44 add_bin "maas-ipmi-autodetect-tool" <<"END_MAAS_IPMI_AUTODETECT_TOOL"
45 {{maas_ipmi_autodetect_tool_py}}
46 END_MAAS_IPMI_AUTODETECT_TOOL
47diff --git a/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py b/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
48index 4fbc849..b5e2125 100644
49--- a/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
50+++ b/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
51@@ -242,7 +242,14 @@ def set_ipmi_lan_channel_settings():
52 output = bmc_get(mode)
53 show_re = re.compile('%s\s+Always_Available' % mode.split(':')[1])
54 if show_re.search(output) is None:
55- bmc_set(mode, 'Always_Available')
56+ # Some BMC's don't support setting Lan_Channel (see LP: #1287274).
57+ # If that happens, it would cause the script to fail preventing
58+ # the script from continuing. To address this, simply catch the
59+ # error, return and allow the script to continue.
60+ try:
61+ bmc_set(mode, 'Always_Available')
62+ except subprocess.CalledProcessError:
63+ return
64
65
66 def commit_ipmi_settings(config):
67diff --git a/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py b/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
68index 2252e90..b7d9411 100644
69--- a/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
70+++ b/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
71@@ -16,6 +16,7 @@ from maastesting.matchers import (
72 MockCalledOnceWith,
73 MockCallsMatch,
74 MockNotCalled,
75+ HasLength,
76 )
77 from maastesting.testcase import MAASTestCase
78 from snippets import maas_ipmi_autodetect
79@@ -626,3 +627,23 @@ class TestEnableLanChannel(MAASTestCase):
80 self.assertThat(
81 bmc_set_mock,
82 MockNotCalled())
83+
84+ def test_set_ipmi_lan_channel_handles_calledprocesserror(self):
85+ "Test that set_ipmi_lan_channel handles CalledProcessError"
86+ response = (
87+ "Section Lan_Channel\n"
88+ " Volatile_Access_Mode Always_Available\n"
89+ " Non_Volatile_Access_Mode Always_Available\n"
90+ "EndSection"
91+ )
92+ self.patch(
93+ maas_ipmi_autodetect, 'bmc_get').return_value = response
94+ bmc_set_mock = self.patch(
95+ maas_ipmi_autodetect, 'bmc_set')
96+ bmc_set_mock.side_effect = subprocess.CalledProcessError(
97+ 1, 'bmc-set')
98+ set_ipmi_lan_channel_settings()
99+ self.assertRaises(
100+ subprocess.CalledProcessError, bmc_set_mock)
101+ self.assertThat(
102+ bmc_set_mock.call_args_list, HasLength(1))

Subscribers

People subscribed via source and target branches