Merge ~andreserl/maas:lp1664822 into maas:master

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: 7a8fe325e53407dee090ba0a360c32f9000d294f
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andreserl/maas:lp1664822
Merge into: maas:master
Diff against target: 112 lines (+72/-0)
2 files modified
src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py (+14/-0)
src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py (+58/-0)
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Blake Rouse (community) Needs Information
Review via email: mp+327264@code.launchpad.net

Commit message

LP: #1664822 - Enable IPMI over LAN if disabled

To post a comment you must log in.
~andreserl/maas:lp1664822 updated
631e799... by Andres Rodriguez

Merge branch 'master' of git+ssh://git.launchpad.net/maas into lp1664822

3ba4079... by Andres Rodriguez

Revert removal of blank line

Revision history for this message
Blake Rouse (blake-rouse) wrote :

Is there any tests for this code?

review: Needs Information
~andreserl/maas:lp1664822 updated
7928632... by Andres Rodriguez

Add missing tests

8655ada... by Andres Rodriguez

Fix lint

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

Looks good; thanks for adding the tests! I have some minor nits on the comments in this code, but I won't block you. Ping me if you want me to take another look at them.

review: Approve
~andreserl/maas:lp1664822 updated
7a8fe32... by Andres Rodriguez

Update docstrings

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

Thanks for the fixes!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py b/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
2index 0ab29e7..4fbc849 100644
3--- a/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
4+++ b/src/metadataserver/user_data/templates/snippets/maas_ipmi_autodetect.py
5@@ -235,6 +235,16 @@ def configure_ipmi_user(username, password):
6 apply_ipmi_user_settings(user_settings)
7
8
9+def set_ipmi_lan_channel_settings():
10+ """Enable IPMI-over-Lan (Lan_Channel) if it is disabled"""
11+ for mode in ['Lan_Channel:Volatile_Access_Mode',
12+ 'Lan_Channel:Non_Volatile_Access_Mode']:
13+ output = bmc_get(mode)
14+ show_re = re.compile('%s\s+Always_Available' % mode.split(':')[1])
15+ if show_re.search(output) is None:
16+ bmc_set(mode, 'Always_Available')
17+
18+
19 def commit_ipmi_settings(config):
20 run_command(('bmc-config', '--commit', '--filename', config))
21
22@@ -296,6 +306,10 @@ def main():
23
24 configure_ipmi_user(IPMI_MAAS_USER, IPMI_MAAS_PASSWORD)
25
26+ # Attempt to enable IPMI Over Lan. If it is disabled, MAAS won't
27+ # be able to remotely communicate to the BMC.
28+ set_ipmi_lan_channel_settings()
29+
30 # Commit other IPMI settings
31 if args.configdir:
32 for file in os.listdir(args.configdir):
33diff --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
34index a3b3a9f..2252e90 100644
35--- a/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
36+++ b/src/metadataserver/user_data/templates/snippets/tests/test_maas_ipmi_autodetect.py
37@@ -15,6 +15,7 @@ from maastesting.matchers import (
38 MockAnyCall,
39 MockCalledOnceWith,
40 MockCallsMatch,
41+ MockNotCalled,
42 )
43 from maastesting.testcase import MAASTestCase
44 from snippets import maas_ipmi_autodetect
45@@ -33,6 +34,7 @@ from snippets.maas_ipmi_autodetect import (
46 pick_user_number,
47 pick_user_number_from_list,
48 run_command,
49+ set_ipmi_lan_channel_settings,
50 verify_ipmi_user_settings,
51 )
52
53@@ -568,3 +570,59 @@ class TestGetIPMIIPAddress(MAASTestCase):
54 '_bmc_get_ipmi_addresses').side_effect = ret_val
55 actual = get_ipmi_ip_address()
56 self.assertEqual(self.expected, actual)
57+
58+
59+class TestEnableLanChannel(MAASTestCase):
60+
61+ def test_enable_lan_channel_if_disabled(self):
62+ """Test that Lan_Channel gets enabled if it is disabled"""
63+ # Mock the response of the BMC
64+ response = (
65+ "Section Lan_Channel\n"
66+ " Volatile_Access_Mode Disabled\n"
67+ " Non_Volatile_Access_Mode Disabled\n"
68+ "EndSection"
69+ )
70+ self.patch(
71+ maas_ipmi_autodetect, 'bmc_get').return_value = response
72+
73+ # Mock the function 'bmc_set'
74+ bmc_set_mock = self.patch(
75+ maas_ipmi_autodetect, 'bmc_set')
76+
77+ # Call the function
78+ set_ipmi_lan_channel_settings()
79+
80+ # Check that the 'bmc_set_mock' was called
81+ self.assertThat(
82+ bmc_set_mock,
83+ MockAnyCall(
84+ 'Lan_Channel:Volatile_Access_Mode', 'Always_Available'))
85+ self.assertThat(
86+ bmc_set_mock,
87+ MockAnyCall(
88+ 'Lan_Channel:Non_Volatile_Access_Mode', 'Always_Available'))
89+
90+ def test_dont_enable_lan_channel_if_already_enabled(self):
91+ """Test that Lan_Channel doesn't get enabled if disabled."""
92+ # Mock the response of the BMC
93+ response = (
94+ "Section Lan_Channel\n"
95+ " Volatile_Access_Mode Always_Available\n"
96+ " Non_Volatile_Access_Mode Always_Available\n"
97+ "EndSection"
98+ )
99+ self.patch(
100+ maas_ipmi_autodetect, 'bmc_get').return_value = response
101+
102+ # Mock the function 'bmc_set'
103+ bmc_set_mock = self.patch(
104+ maas_ipmi_autodetect, 'bmc_set')
105+
106+ # Call the function
107+ set_ipmi_lan_channel_settings()
108+
109+ # Check that the 'bmc_set' mock function (bmc_set_mock) was not called.
110+ self.assertThat(
111+ bmc_set_mock,
112+ MockNotCalled())

Subscribers

People subscribed via source and target branches