1*** Settings ***
2Documentation  Test BMC manager protocol enable/disable functionality.
3
4Resource   ../../lib/bmc_redfish_resource.robot
5Resource   ../../lib/openbmc_ffdc.robot
6Resource   ../../lib/protocol_setting_utils.robot
7
8Suite Setup     Suite Setup Execution
9Suite Teardown  Run Keywords  Enable IPMI Protocol  ${initial_ipmi_state}  AND  Redfish.Logout
10Test Teardown   FFDC On Test Case Fail
11
12
13*** Variables ***
14
15${cmd_prefix}            ipmitool -I lanplus -C 17 -p 623 -U ${IPMI_USERNAME} -P ${IPMI_PASSWORD}
16${SETTING_WAIT_TIMEOUT}  30s
17
18
19*** Test Cases ***
20
21Verify SSH Is Enabled By Default
22    [Documentation]  Verify SSH is enabled by default.
23    [Tags]  Verify_SSH_Is_Enabled_By_Default
24
25    # Check if SSH is enabled by default.
26    Verify SSH Protocol State  ${True}
27
28
29Enable SSH Protocol And Verify
30    [Documentation]  Enable SSH protocol and verify.
31    [Tags]  Enable_SSH_Protocol_And_Verify
32
33    Enable SSH Protocol  ${True}
34
35    # Check if SSH is really enabled via Redfish.
36    Verify SSH Protocol State  ${True}
37
38    # Check if SSH login and commands on SSH session work.
39    Verify SSH Login And Commands Work
40
41
42Disable SSH Protocol And Verify
43    [Documentation]  Disable SSH protocol and verify.
44    [Tags]  Disable_SSH_Protocol_And_Verify
45    [Teardown]  Enable SSH Protocol  ${True}
46
47    # Disable SSH interface.
48    Enable SSH Protocol  ${False}
49
50    # Check if SSH is really disabled via Redfish.
51    Verify SSH Protocol State  ${False}
52
53    # Check if SSH login and commands fail.
54    ${status}=  Run Keyword And Return Status
55    ...  Verify SSH Login And Commands Work
56
57    Should Be Equal As Strings  ${status}  False
58    ...  msg=SSH Login and commands are working after disabling SSH.
59
60
61Enable SSH Protocol And Check Persistency On BMC Reboot
62    [Documentation]  Enable SSH protocol and verify persistency.
63    [Tags]  Enable_SSH_Protocol_And_Check_Persistency_On_BMC_Reboot
64
65    Enable SSH Protocol  ${True}
66
67    # Reboot BMC and verify persistency.
68    Redfish OBMC Reboot (off)  stack_mode=skip
69
70    # Check if SSH is really enabled via Redfish.
71    Verify SSH Protocol State  ${True}
72
73    # Check if SSH login and commands on SSH session work.
74    Verify SSH Login And Commands Work
75
76
77Disable SSH Protocol And Check Persistency On BMC Reboot
78    [Documentation]  Disable SSH protocol and verify persistency.
79    [Tags]  Disable_SSH_Protocol_And_Check_Persistency_On_BMC_Reboot
80    [Teardown]  Enable SSH Protocol  ${True}
81
82    # Disable SSH interface.
83    Enable SSH Protocol  ${False}
84
85    # Reboot BMC and verify persistency.
86    Redfish OBMC Reboot (off)  stack_mode=skip
87
88    # Check if SSH is really disabled via Redfish.
89    Verify SSH Protocol State  ${False}
90
91    # Check if SSH login and commands fail.
92    ${status}=  Run Keyword And Return Status
93    ...  Verify SSH Login And Commands Work
94
95    Should Be Equal As Strings  ${status}  False
96    ...  msg=SSH Login and commands are working after disabling SSH.
97
98
99Verify Disabling SSH Port Does Not Disable Serial Console Port
100    [Documentation]  Verify disabling SSH does not disable serial console port.
101    [Tags]  Verify_Disabling_SSH_Port_Does_Not_Disable_Serial_Console_Port
102    [Teardown]  Enable SSH Protocol  ${True}
103
104    # Disable SSH interface.
105    Enable SSH Protocol  ${False}
106
107    # Check able to establish connection with serial port console.
108    Open Connection And Log In  host=${OPENBMC_HOST}  port=2200
109    Close All Connections
110
111
112Verify Existing SSH Session Gets Closed On Disabling SSH
113    [Documentation]  Verify existing SSH session gets closed on disabling ssh.
114    [Tags]  Verify_Existing_SSH_Session_Gets_Closed_On_Disabling_SSH
115    [Teardown]  Enable SSH Protocol  ${True}
116
117    # Open SSH connection.
118    Open Connection And Login
119
120    # Disable SSH interface.
121    Enable SSH Protocol  ${False}
122
123    # Check if SSH is really disabled via Redfish.
124    Verify SSH Protocol State  ${False}
125
126    # Try to execute CLI command on SSH connection.
127    # It should fail as disable SSH will close pre existing sessions.
128    ${status}=  Run Keyword And Return Status
129    ...  BMC Execute Command  /sbin/ip addr
130
131    Should Be Equal As Strings  ${status}  False
132    ...  msg=Disabling SSH has not closed existing SSH sessions.
133
134
135Enable IPMI Protocol And Verify
136    [Documentation]  Enable IPMI protocol and verify.
137    [Tags]  Enable_IPMI_Protocol_And_Verify
138
139    Enable IPMI Protocol  ${True}
140
141    # Check if IPMI is really enabled via Redfish.
142    Verify IPMI Protocol State  ${True}
143
144    # Check if IPMI commands starts working.
145    Verify IPMI Works  lan print
146
147
148Disable IPMI Protocol And Verify
149    [Documentation]  Disable IPMI protocol and verify.
150    [Tags]  Disable_IPMI_Protocol_And_Verify
151
152    # Disable IPMI interface.
153    Enable IPMI Protocol  ${False}
154
155    # Check if IPMI is really disabled via Redfish.
156    Verify IPMI Protocol State  ${False}
157
158    # Check if IPMI commands fail.
159    ${status}=  Run Keyword And Return Status
160    ...  Verify IPMI Works  lan print
161
162    Should Be Equal As Strings  ${status}  False
163    ...  msg=IPMI commands are working after disabling IPMI.
164
165
166Enable IPMI Protocol And Check Persistency On BMC Reboot
167    [Documentation]  Set the IPMI protocol attribute to True, reset BMC, and verify
168    ...              that the setting persists.
169    [Tags]  Enable_IPMI_Protocol_And_Check_Persistency_On_BMC_Reboot
170
171    Enable IPMI Protocol  ${True}
172
173    Redfish OBMC Reboot (off)  stack_mode=skip
174
175    # Check if the IPMI enabled is set.
176    Verify IPMI Protocol State  ${True}
177
178    # Confirm that IPMI commands to access BMC work.
179    Verify IPMI Works  lan print
180
181
182Disable IPMI Protocol And Check Persistency On BMC Reboot
183    [Documentation]  Set the IPMI protocol attribute to False, reset BMC, and verify
184    ...              that the setting persists.
185    [Tags]  Disable_IPMI_Protocol_And_Check_Persistency_On_BMC_Reboot
186
187    # Disable IPMI interface.
188    Enable IPMI Protocol  ${False}
189
190    Redfish OBMC Reboot (off)  stack_mode=skip
191
192    # Check if the IPMI disabled is set.
193    Verify IPMI Protocol State  ${False}
194
195    # Confirm that IPMI connection request fails.
196    ${status}=  Run Keyword And Return Status
197    ...  Verify IPMI Works  lan print
198
199    Should Be Equal As Strings  ${status}  False
200    ...  msg=IPMI commands are working after disabling IPMI.
201
202
203Configure SSH And IPMI Settings And Verify
204    [Documentation]  Set the SSH and IPMI protocol attribute to True/False, and verify.
205    [Tags]  Configure_SSH_And_IPMI_Settings_And_Verify
206    [Template]  Set SSH And IPMI Protocol
207    [Teardown]  Run Keywords  FFDC On Test Case Fail
208    ...  AND  Enable SSH Protocol  ${True}
209
210    # ssh_state  ipmi_state
211    ${True}      ${False}
212    ${True}      ${True}
213    ${False}     ${True}
214    ${False}     ${False}
215
216
217Configure SSH And IPMI Settings And Verify Persistency On BMC Reboot
218    [Documentation]  Set the SSH and IPMI protocol attribute to True/False, and verify
219    ...  it's persistency after BMC reboot.
220    [Tags]  Configure_SSH_And_IPMI_Settings_And_Verify_Persistency_On_BMC_Reboot
221    [Template]  Set SSH And IPMI Protocol
222    [Teardown]  Run Keywords  FFDC On Test Case Fail
223    ...  AND  Enable SSH Protocol  ${True}
224
225    # ssh_state  ipmi_state  persistency_check
226    ${True}      ${False}    ${True}
227    ${True}      ${True}     ${True}
228    ${False}     ${True}     ${True}
229    ${False}     ${False}    ${True}
230
231
232*** Keywords ***
233
234Suite Setup Execution
235    [Documentation]  Do suite setup tasks.
236
237    Redfish.Login
238
239    ${state}=  Run Keyword And Return Status  Verify IPMI Protocol State
240    Set Suite Variable  ${initial_ipmi_state}  ${state}
241    Sleep  ${NETWORK_TIMEOUT}s
242
243
244Set SSH And IPMI Protocol
245    [Documentation]  Set SSH and IPMI protocol state.
246    [Arguments]  ${ssh_state}  ${ipmi_state}  ${persistency_check}=${False}
247
248    # Description of argument(s):
249    # ssh_state     State of SSH to be set (e.g. True, False).
250    # ipmi_state    State of IPMI to be set (e.g. True, False).
251
252    ${ssh_protocol_state}=  Create Dictionary  ProtocolEnabled=${ssh_state}
253    ${ipmi_protocol_state}=  Create Dictionary  ProtocolEnabled=${ipmi_state}
254    ${data}=  Create Dictionary  SSH=${ssh_protocol_state}  IPMI=${ipmi_protocol_state}
255
256    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}
257    ...  valid_status_codes=[${HTTP_NO_CONTENT}]
258
259    # Wait for timeout for new values to take effect.
260    Sleep  ${SETTING_WAIT_TIMEOUT}
261
262    Run Keyword if  ${persistency_check} == ${True}
263    ...  Redfish OBMC Reboot (off)  stack_mode=skip
264    Verify Protocol State  ${ssh_state}  ${ipmi_state}
265
266
267Verify Protocol State
268    [Documentation]  Verify SSH and IPMI protocol state.
269    [Arguments]  ${ssh_state}  ${ipmi_state}
270
271    # Description of argument(s):
272    # ssh_state     State of SSH to be verified (e.g. True, False).
273    # ipmi_state    State of IPMI to be verified (e.g. True, False).
274
275    # Verify SSH state value.
276    ${status}=  Run Keyword And Return Status
277    ...  Verify SSH Login And Commands Work
278    Should Be Equal As Strings  ${status}  ${ssh_state}
279    ...  msg=SSH states are not matching.
280
281    # Verify IPMI state value.
282    ${status}=  Run Keyword And Return Status
283    ...  Verify IPMI Works  lan print
284
285    Should Be Equal As Strings  ${status}  ${ipmi_state}
286    ...  msg=IPMI states are not matching.
287