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