xref: /openbmc/openbmc-test-automation/redfish/managers/test_bmc_protocol_settings.robot (revision ff3879e015e38f8161b5ad019f2eee569ba992f0)
1*** Settings ***
2Documentation  Test BMC manager protocol enable/disable functionality.
3
4Resource   ../../lib/resource.robot
5Resource   ../../lib/bmc_redfish_resource.robot
6Resource   ../../lib/openbmc_ffdc.robot
7
8Suite Setup     Redfish.Login
9Suite Teardown  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 ${OPENBMC_USERNAME} -P ${OPENBMC_PASSWORD}
16
17
18*** Test Cases ***
19
20Verify SSH Is Enabled By Default
21    [Documentation]  Verify SSH is enabled by default.
22    [Tags]  Verify_SSH_Is_Enabled_By_Default
23
24    # Check if SSH is enabled by default.
25    Verify SSH Protocol State  ${True}
26
27
28Enable SSH Protocol And Verify
29    [Documentation]  Enable SSH protocol and verify.
30    [Tags]  Enable_SSH_Protocol_And_Verify
31
32    Enable SSH Protocol  ${True}
33
34    # Check if SSH is really enabled via Redfish.
35    Verify SSH Protocol State  ${True}
36
37    # Check if SSH login and commands on SSH session work.
38    Verify SSH Login And Commands Work
39
40
41Disable SSH Protocol And Verify
42    [Documentation]  Disable SSH protocol and verify.
43    [Teardown]  Enable SSH Protocol  ${True}
44
45    # Disable SSH interface.
46    Enable SSH Protocol  ${False}
47
48    # Check if SSH is really disabled via Redfish.
49    Verify SSH Protocol State  ${False}
50
51    # Check if SSH login and commands fail.
52    ${status}=  Run Keyword And Return Status
53    ...  Verify SSH Login And Commands Work
54
55    Should Be Equal As Strings  ${status}  False
56    ...  msg=SSH Login and commands are working after disabling SSH.
57
58
59Enable SSH Protocol And Check Persistency On BMC Reboot
60    [Documentation]  Enable SSH protocol and verify persistency.
61
62    Enable SSH Protocol  ${True}
63
64    # Reboot BMC and verify persistency.
65    OBMC Reboot (off)
66
67    # Check if SSH is really enabled via Redfish.
68    Verify SSH Protocol State  ${True}
69
70    # Check if SSH login and commands on SSH session work.
71    Verify SSH Login And Commands Work
72
73
74Disable SSH Protocol And Check Persistency On BMC Reboot
75    [Documentation]  Disable SSH protocol and verify persistency.
76    [Teardown]  Enable SSH Protocol  ${True}
77
78    # Disable SSH interface.
79    Enable SSH Protocol  ${False}
80
81    # Reboot BMC and verify persistency.
82    OBMC Reboot (off)
83
84    # Check if SSH is really disabled via Redfish.
85    Verify SSH Protocol State  ${False}
86
87    # Check if SSH login and commands fail.
88    ${status}=  Run Keyword And Return Status
89    ...  Verify SSH Login And Commands Work
90
91    Should Be Equal As Strings  ${status}  False
92    ...  msg=SSH Login and commands are working after disabling SSH.
93
94
95Verify Disabling SSH Port Does Not Disable Serial Console Port
96    [Documentation]  Verify disabling SSH does not disable serial console port.
97    [Tags]  Verify_Disabling_SSH_Port_Does_Not_Disable_Serial_Console_Port
98    [Teardown]  Enable SSH Protocol  ${True}
99
100    # Disable SSH interface.
101    Enable SSH Protocol  ${False}
102
103    # Check able to establish connection with serial port console.
104    Open Connection And Log In  host=${OPENBMC_HOST}  port=2200
105    Close All Connections
106
107
108Verify Existing SSH Session Gets Closed On Disabling SSH
109    [Documentation]  Verify existing SSH session gets closed on disabling ssh.
110    [Tags]  Verify_Existing_SSH_Session_Gets_Closed_On_Disabling_SSH
111    [Teardown]  Enable SSH Protocol  ${True}
112
113    # Open SSH connection.
114    Open Connection And Login
115
116    # Disable SSH interface.
117    Enable SSH Protocol  ${False}
118
119    # Check if SSH is really disabled via Redfish.
120    Verify SSH Protocol State  ${False}
121
122    # Try to execute CLI command on SSH connection.
123    # It should fail as disable SSH will close pre existing sessions.
124    ${status}=  Run Keyword And Return Status
125    ...  BMC Execute Command  /sbin/ip addr
126
127    Should Be Equal As Strings  ${status}  False
128    ...  msg=Disabling SSH has not closed existing SSH sessions.
129
130
131Enable IPMI Protocol And Verify
132    [Documentation]  Enable IPMI protocol and verify.
133    [Tags]  Enable_IPMI_Protocol_And_Verify
134    [Teardown]  Enable IPMI Protocol  ${False}
135
136    Enable IPMI Protocol  ${True}
137
138    # Check if IPMI is really enabled via Redfish.
139    Verify IPMI Protocol State  ${True}
140
141    # Check if IPMI commands starts working.
142    Verify IPMI Works  lan print
143
144
145Disable IPMI Protocol And Verify
146    [Documentation]  Disable IPMI protocol and verify.
147    [Tags]  Disable_IPMI_Protocol_And_Verify
148
149    # Disable IPMI interface.
150    Enable IPMI Protocol  ${False}
151
152    # Check if IPMI is really disabled via Redfish.
153    Verify IPMI Protocol State  ${False}
154
155    # Check if IPMI commands fail.
156    ${status}=  Run Keyword And Return Status
157    ...  Verify IPMI Works  lan print
158
159    Should Be Equal As Strings  ${status}  False
160    ...  msg=IPMI commands are working after disabling IPMI.
161
162
163*** Keywords ***
164
165Enable SSH Protocol
166    [Documentation]  Enable or disable SSH protocol.
167    [Arguments]  ${enable_value}=${True}
168
169    # Description of argument(s}:
170    # enable_value  Enable or disable SSH, e.g. (true, false).
171
172    ${ssh_state}=  Create Dictionary  ProtocolEnabled=${enable_value}
173    ${data}=  Create Dictionary  SSH=${ssh_state}
174
175    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}
176    ...  valid_status_codes=[${HTTP_NO_CONTENT}]
177
178    # Wait for timeout for new values to take effect.
179    Sleep  ${NETWORK_TIMEOUT}s
180
181
182Verify SSH Login And Commands Work
183    [Documentation]  Verify if SSH connection works and able to run command on SSH session.
184    [Teardown]  Close All Connections
185
186    # Check if we can open SSH connection and login.
187    Open Connection And Login
188
189    # Check if we can run command successfully on SSH session.
190    BMC Execute Command  /sbin/ip addr
191
192
193Verify SSH Protocol State
194    [Documentation]  verify SSH protocol state.
195    [Arguments]  ${state}=${True}
196
197    # Description of argument(s}:
198    # state  Enable or disable SSH, e.g. (true, false)
199
200    # Sample output:
201    # {
202    #   "@odata.id": "/redfish/v1/Managers/bmc/NetworkProtocol",
203    #   "@odata.type": "#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol",
204    #   "Description": "Manager Network Service",
205    #   "FQDN": "bmc",
206    #  "HTTP": {
207    #    "Port": 0,
208    #    "ProtocolEnabled": false
209    #  },
210    #  "HTTPS": {
211    #    "Certificates": {
212    #      "@odata.id": "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"
213    #    },
214    #    "Port": xxx,
215    #    "ProtocolEnabled": true
216    #  },
217    #  "HostName": "xxxxbmc",
218    #  "IPMI": {
219    #    "Port": xxx,
220    #    "ProtocolEnabled": true
221    #  },
222    #  "Id": "NetworkProtocol",
223    #  "NTP": {
224    #    "NTPServers": [
225    #      "xx.xx.xx.xx",
226    #      "xx.xx.xx.xx",
227    #      "xx.xx.xx.xx"
228    #    ],
229    #    "ProtocolEnabled": true
230    #  },
231    #  "Name": "Manager Network Protocol",
232    #  "SSH": {
233    #    "Port": xx,
234    #    "ProtocolEnabled": true
235    #  },
236    #  "Status": {
237    #    "Health": "OK",
238    #    "HealthRollup": "OK",
239    #    "State": "Enabled"
240    #  }
241    # }
242
243    ${resp}=  Redfish.Get  ${REDFISH_NW_PROTOCOL_URI}
244    Should Be Equal As Strings  ${resp.dict['SSH']['ProtocolEnabled']}  ${state}
245    ...  msg=Protocol states are not matching.
246
247
248Enable IPMI Protocol
249    [Documentation]  Enable or disable IPMI protocol.
250    [Arguments]  ${enable_value}=${True}
251
252    # Description of argument(s}:
253    # enable_value  Enable or disable IPMI, e.g. (true, false).
254
255    ${ipmi_state}=  Create Dictionary  ProtocolEnabled=${enable_value}
256    ${data}=  Create Dictionary  IPMI=${ipmi_state}
257
258    Redfish.Patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}
259    ...  valid_status_codes=[${HTTP_NO_CONTENT}]
260
261    # Wait for timeout for new values to take effect.
262    Sleep  ${NETWORK_TIMEOUT}s
263
264
265Verify IPMI Works
266    [Documentation]  Run IPMI command and return status.
267    [Arguments]  ${sub_cmd}  ${host}=${OPENBMC_HOST}
268
269    # Description of argument(s):
270    # host         BMC host name or IP address.
271    # sub_cmd      The IPMI command string to be executed.
272
273    ${rc}=  Run And Return Rc  ${cmd_prefix} -H ${host} ${sub_cmd}
274    Should Be Equal As Strings  ${rc}  0
275    ...  msg=IPMI is not enabled and commands are failing.
276
277
278Verify IPMI Protocol State
279    [Documentation]  Verify IPMI protocol state.
280    [Arguments]  ${state}=${True}
281
282    # Description of argument(s}:
283    # state  Enable or disable IPMI, e.g. (true, false)
284
285    ${resp}=  Redfish.Get  ${REDFISH_NW_PROTOCOL_URI}
286    Should Be Equal As Strings  ${resp.dict['IPMI']['ProtocolEnabled']}  ${state}
287    ...  msg=Protocol states are not matching.
288