1*** Settings ***
2Documentation       This suite tests IPMI Payload in OpenBMC.
3
4Resource            ../lib/ipmi_client.robot
5Resource            ../lib/openbmc_ffdc.robot
6Resource            ../lib/bmc_network_utils.robot
7Variables           ../data/ipmi_raw_cmd_table.py
8Library             ../lib/ipmi_utils.py
9
10
11Suite Setup         IPMI Payload Setup Execution
12Test Teardown       FFDC On Test Case Fail
13
14
15*** Variables ***
16${user_priv}                    2
17${operator_priv}                3
18${admin_level_priv}             4
19${no_access_priv}               15
20${new_user_passwd}             0penBmc1
21
22
23*** Test Cases ***
24
25Test Get Payload Activation Status
26    [Documentation]  Test get payload activation status.
27    [Tags]  Test_Get_Payload_Activation_Status
28
29    # SOL is the payload currently supported for payload status.
30    # Currently supports only one SOL session.
31    # Response Data
32    # 01   instance 1 is activated.
33    # 00   instance 1 is deactivated.
34    ${payload_status}=  Get Payload Activation Status
35    Should Contain Any  ${payload_status}  01  00
36
37
38Test Activate Payload
39    [Documentation]  Test activate payload via IPMI raw command.
40    [Tags]  Test_Activate_Payload
41
42    ${payload_status}=  Get Payload Activation Status
43    Run Keyword If  '${payload_status}' == '01'  Deactivate Payload
44
45    Activate Payload
46
47    ${payload_status}=  Get Payload Activation Status
48    Should Contain  ${payload_status}  01
49
50
51Test Deactivate Payload
52    [Documentation]  Test deactivate payload via IPMI raw command.
53    [Tags]  Test_Deactivate_Payload
54
55    ${payload_status}=  Get Payload Activation Status
56    Run Keyword If  '${payload_status}' == '00'  Activate Payload
57
58    Deactivate Payload
59
60    ${payload_status}=  Get Payload Activation Status
61    Should Contain  ${payload_status}  00
62
63
64Test Get Payload Instance Info
65    [Documentation]  Test Get Payload Instance via IPMI raw command.
66    [Tags]  Test_Get_Payload_Instance_Info
67
68    ${payload_status}=  Get Payload Activation Status
69    Run keyword If  '${payload_status}' == '01'
70    ...  Deactivate Payload
71
72    # First four bytes should be 00 if given instance is not activated.
73    ${resp}=  Run IPMI Command
74    ...  ${IPMI_RAW_CMD['Payload']['Get_Payload_Instance_Info'][0]}
75    Should Contain  ${resp}  ${IPMI_RAW_CMD['Payload']['Get_Payload_Instance_Info'][1]}
76    Activate Payload
77
78    # First four bytes should be session ID when payload is activated.
79    ${resp}=  Run IPMI Command
80    ...  ${IPMI_RAW_CMD['Payload']['Get_Payload_Instance_Info'][0]}
81    Should Not Contain  ${resp}  ${IPMI_RAW_CMD['Payload']['Get_Payload_Instance_Info'][1]}
82
83
84Verify Set User Access Payload For Standard Payload SOL
85    [Documentation]  Disable standard payload for SOL and verify IPMI sol activate command does not work.
86    [Tags]  Verify_Set_User_Access_Payload_For_Standard_Payload_SOL
87    [Teardown]  Run Keywords  Set User Access Payload For Given User  ${user_id_in_hex}
88    ...  AND  Delete Created User  ${userid}
89    ...  AND  FFDC On Test Case Fail
90
91    ${userid}  ${username}=  Create And Verify IPMI User
92    ${user_id_in_hex}=  Convert To Hex  ${userid}
93    ${userid_in_hex_format}=  Convert To Hex  ${userid}  prefix=0x  length=2
94
95    # Get default user access payload values.
96    ${default_user_access_payload}=  Get User Access Payload For Given Channel  ${userid_in_hex_format}
97
98    # Disable Standard payload 1 via set user access payload command.
99    Set User Access Payload For Given User  ${user_id_in_hex}  Disable
100
101    Verify Standard Payload  ${userid_in_hex_format}  ${username}  Disabled
102
103
104Verify Set User Access Payload For Operator Privileged User
105    [Documentation]  Try to set user access payload using operator privileged user and expect error.
106    [Tags]  Verify_Set_User_Access_Payload_For_Operator_Privileged_User
107    [Teardown]  Run Keywords  Delete Created User  ${userid}  AND  FFDC On Test Case Fail
108
109    ${userid}  ${username}=  Create And Verify IPMI User  ${operator_priv}  Operator
110
111    ${payload_raw_cmd}=  Catenate  ${IPMI_RAW_CMD['Payload']['Set_User_Access_Payload'][0]}
112    ...  ${CHANNEL_NUMBER} 0x${user_id} 0x02 0x00 0x00 0x00
113
114    Run Keyword and Expect Error  *Unable to establish IPMI*
115    ...  Run External IPMI Raw Command  ${payload_raw_cmd}  U=${userid}  P=${new_user_passwd}  L=Operator
116
117
118Verify Set User Access Payload For Invalid User
119    [Documentation]  Verify set user access payload IPMI command for invalid user.
120    [Tags]  Verify_Set_User_Access_Payload_For_Invalid_User
121
122    # Get Random invalid user ID.
123    ${invalid_userid}=  Get Invalid User ID
124
125    ${raw_cmd}=  Catenate   ${IPMI_RAW_CMD['Payload']['Set_User_Access_Payload'][0]}
126    ...  ${CHANNEL_NUMBER} ${invalid_userid} 0x02 0x00 0x00 0x00
127
128    Verify Invalid IPMI Command  ${raw_cmd}  0xcc
129
130
131Verify Set User Access Payload For Invalid Channel Number
132    [Documentation]  Verify set user access payload IPMI command for invalid channel number.
133    [Tags]  Verify_Set_User_Access_Payload_for_Invalid_Channel_Number
134    [Teardown]  Delete Created User  ${userid}
135
136    ${userid}  ${username}=  Create And Verify IPMI User
137
138    FOR  ${channel}  IN  @{inactive_channel_list}
139
140        Verify Set User Access Payload For Invalid Channel  ${userid}  ${channel}
141    END
142
143
144Verify Get User Access Payload For User Access privilege
145    [Documentation]   Verify get user access payload for user access(Read-only) privileged user.
146    [Tags]  Verify_Get_User_Access_Payload_For_User_Access_privilege
147    [Teardown]  Delete Created User  ${userid}
148
149    ${userid}  ${username}=  Create And Verify IPMI User  ${user_priv}  User
150
151    ${raw_command}=  Catenate  ${IPMI_RAW_CMD['Payload']['Get_User_Access_Payload'][0]}
152    ...  ${CHANNEL_NUMBER} ${user_id}
153
154    Run Keyword and Expect Error  *Unable to establish IPMI*
155    ...  Run External IPMI Raw Command  ${raw_command}  U=${userid}  P=${new_user_passwd}  L=User
156
157
158Verify Get User Access Payload For Invalid User
159    [Documentation]  Verify get user access payload IPMI command for invalid user.
160    [Tags]  Verify_Get_User_Access_Payload_For_Invalid_User
161
162    ${invalid_userid}=  Get Invalid User ID
163
164    Verify Get User Access Payload For Invalid User Or Channel  ${invalid_userid}  ${CHANNEL_NUMBER}
165
166
167Verify Get User Access Payload For Invalid Channel Number
168    [Documentation]  Verify get user access payload IPMI command for invalid channel number.
169    [Tags]  Verify_Get_User_Access_Payload_For_Invalid_Channel_Number
170    [Teardown]  Delete Created User  ${userid}
171
172    ${userid}  ${username}=  Create And Verify IPMI User
173    #${invalid_channels}=  Get Invalid Channel Number
174
175    FOR  ${channel}  IN  @{inactive_channel_list}
176        Verify Get User Access Payload For Invalid User Or Channel  ${userid}  ${channel}
177    END
178
179
180*** Keywords ***
181
182IPMI Payload Setup Execution
183    [Documentation]  Get active and inactive/invalid channels from channel_config.json file
184    ...              in list type and set it as suite variable.
185
186    # Get active channel list and set as a suite variable.
187    @{active_channel_list}=  Get Active Ethernet Channel List  current_channel=1
188    Set Suite Variable  @{active_channel_list}
189
190    # Get Inactive/Invalid channel list and set as a suite variable.
191    @{inactive_channel_list}=  Get Invalid Channel Number List
192    Set Suite Variable  @{inactive_channel_list}
193
194
195Get Payload Activation Status
196    [Documentation]  Get payload activation status.
197
198    ${resp}=  Run IPMI Command
199    ...  ${IPMI_RAW_CMD['Payload']['Get_Payload_Activation_Status'][0]}
200
201    @{resp}=  Split String  ${resp}
202
203    ${payload_status}=  Set Variable  ${resp[1]}
204
205    [return]  ${payload_status}
206
207
208Activate Payload
209    [Documentation]  Activate Payload.
210
211    ${resp}=  Run IPMI Command
212    ...  ${IPMI_RAW_CMD['Payload']['Activate_Payload'][0]}
213    Should Contain  ${resp}  ${IPMI_RAW_CMD['Payload']['Activate_Payload'][1]}
214
215
216Deactivate Payload
217    [Documentation]  Deactivate Payload.
218
219    ${resp}=  Run IPMI Command
220    ...  ${IPMI_RAW_CMD['Payload']['Deactivate_Payload'][0]}
221    Should Be Empty  ${resp}
222
223
224Get User Access Payload For Given Channel
225    [Documentation]  Execute get user access payload IPMI command for given channel
226    ...              and return response.
227    [Arguments]  ${user_id}  ${channel_number}=${CHANNEL_NUMBER}
228
229    # Description of argument(s):
230    # user_id         The user ID (e.g. "1", "2", etc.).
231    # channel_number  Input channel number(e.g. "1", "2").
232
233    ${raw_command}=  Catenate  ${IPMI_RAW_CMD['Payload']['Get_User_Access_Payload'][0]}
234    ...  ${channel_number} ${user_id}
235    ${resp}=  Run External IPMI Raw Command  ${raw_command}
236    [Return]  ${resp}
237
238
239Create And Verify IPMI User
240    [Documentation]  Create IPMI User, set password, set privilege and enable the user.
241    [Arguments]  ${user_privilege_level}=${admin_level_priv}   ${privilege}=Administrator
242
243    # Description of argument(s):
244    # user_privilege_level   User Privilege level in integer.
245    #                        (e.g. 4-Administrator, 3-Operator, 2-Readonly).
246    # privilege              User Privilege in Wordings.
247    #                        (e.g. "Administrator", "Operator", "ReadOnly").
248
249    ${random_user_id}  ${random_user_name}=  Create Random IPMI User
250    Set User Password  ${random_user_id}  ${new_user_passwd}  16
251    Set And Verify User Access Privilege  ${random_user_id}  ${user_privilege_level}
252    Verify Username And Password  ${random_user_name}  ${new_user_passwd}  L=${privilege}
253
254    [Return]  ${random_user_id}  ${random_user_name}
255
256
257Set User Password
258    [Documentation]  Set user password for given user ID.
259    [Arguments]  ${user_id}  ${password}  ${password_option}
260
261    # Description of argument(s):
262    # user_id          The user ID (e.g. "1", "2", etc.).
263    # password         The user password (e.g. "0penBmc", "0penBmc1", etc.).
264    # password_option  Password length option to be given in IPMI command (e.g. "16", "20").
265
266    Run IPMI Standard Command  user set password ${user_id} ${password} ${password_option}
267
268Set And Verify User Access Privilege
269    [Documentation]  Set User Access Privilege, enable and verify user for given user ID.
270    [Arguments]  ${user_id}  ${privilege_level}
271
272    # Description of argument(s):
273    # user_id           The user ID (e.g. "1", "2", etc.).
274    # privilege_level   User Privilege level in hex value.
275    #                   (e.g. 0x04-Administrator, 0x03-Operator, 0x02-Readonly).
276
277    Set Channel Access  ${_user_id}  ipmi=on privilege=${privilege_level}
278
279    # Delay added for user privilege to get set.
280    Sleep  5s
281
282    Enable IPMI User And Verify  ${user_id}
283
284
285Verify Username And Password
286    [Documentation]  Verify that newly created user is able to run IPMI command
287    ...  with given username and password.
288    [Arguments]  ${username}  ${password}  &{options}
289
290    # Description of argument(s):
291    # username    The user name (e.g. "root", "robert", etc.).
292    # password    The user password (e.g. "0penBmc", "0penBmc1", etc.).
293    # options     Additional ipmitool command options  (e.g "-L=Operator","-C=3").
294
295    Wait Until Keyword Succeeds  15 sec  5 sec  Run External IPMI Raw Command
296    ...  ${IPMI_RAW_CMD['Device GUID']['Get'][0]}  U=${username}  P=${password}  &{options}
297
298
299Verify Standard Payload
300    [Documentation]  Verify standard payload is disabled or enabled.
301    [Arguments]  ${user_id}  ${user_name}  ${standard_payload}=Enabled
302
303    # Description of argument(s):
304    # user_id            The user ID (e.g. "1", "2", etc.).
305    # username           The user name (e.g. "root", "robert", etc.).
306    # standard_payload   Enabled or Disabled.
307
308    # Verify the standard payload 1 (sol) is disabled.
309    ${get_user_access_payload}=  Get User Access Payload For Given Channel  ${user_id}
310    @{get_user_access_cmd_resp_list}=  Split String  ${get_user_access_payload}
311
312    Run Keyword If  '${standard_payload}' == 'Disabled'
313    ...  Should Be Equal  ${get_user_access_cmd_resp_list}[0]  00
314    ...  ELSE
315    ...  Should Be Equal  ${get_user_access_cmd_resp_list}[0]  02
316
317    Run Keyword If  '${standard_payload}' == 'Disabled'
318    ...  Verify Sol Activate Disabled  ${user_name}
319
320
321Verify Sol Activate Disabled
322    [Documentation]  Verify SOL activate IPMI command is not working.
323    [Arguments]  ${user_name}
324
325    # Description of argument(s):
326    # username    The user name (e.g. "root", "robert", etc.).
327
328    ${resp}=  Run External IPMI Standard Command
329    ...  sol activate  expected_rc=${1}  U=${username}  P=${new_user_passwd}
330
331    Should Contain  ${resp}  SOL payload disabled
332
333
334Set User Access Payload For Given User
335    [Documentation]  Set the user access payload on given user, channel and return response.
336    [Arguments]  ${user_id}  ${operation_mode}=Enable  ${oempayload_value}=0x00  ${standard_payload_value}=0x02
337
338    # Description of argument(s):
339    # user_id                  The user ID (e.g. "1", "2", etc.).
340    # operation_mode          Enable or Disable payload type.
341    # oempayload_value        Oempayload in hex (e.g. "0x00", "0x01", "0x02", "0x04" etc).
342    # standard_payload_value  Standard payload type IPMI or SOL.
343    #                         (e.g.  0x01 - IPMI, 0x02- SOL).
344
345    # If operation mode is disable 2nd byte of raw command is 4${user_id}.
346    # (e.g) 2n byte will be 0x4a (if user_id is a).
347    # If operation mode is enable 2nd byte of raw command is 0${user_id}.
348    # (e.g.) 3rd byte will be 0x0a (if user_id is a).
349    # 0x02- standard payload for SOL, 0x01 standard payload for IPMI.
350    # 3rd byte represent standard payload enables 1 (SOL).
351    # 4th to 6th byte represent standard payload enables 2 and OEM payload 1 & 2 respectively.
352
353    ${operation_mode_value}=  Set Variable If  '${operation_mode}' == 'Enable'
354    ...  0  4
355    ${set_cmd}=  Catenate  ${IPMI_RAW_CMD['Payload']['Set_User_Access_Payload'][0]}
356    ...  ${CHANNEL_NUMBER} 0x${operation_mode_value}${user_id} ${standard_payload_value} 0x00 ${oempayload_value} 0x00
357
358    ${resp}=  Run IPMI Command  ${set_cmd}
359
360    [Return]  ${resp}
361
362
363Get Invalid User ID
364    [Documentation]  Get random invalid user ID using "channel getaccess" IPMI standard command.
365
366    # Python module:  get_user_info(userid, channel_number=1)
367    ${user_info}=  Get User Info  ${EMPTY}
368    ${user_info}=  Filter Struct  ${user_info}  [('user_name', None)]  invert=1
369    ${empty_user_info}=  Filter Struct  ${user_info}  [('user_name', '')]
370    @{invalid_userid_list}=  Create List
371    FOR  ${user_record}  IN  @{empty_user_info}
372        Append To List  ${invalid_userid_list}  ${user_record['user_id']}
373    END
374    ${invalid_user_id}=  Evaluate  random.choice(${invalid_userid_list})  random
375
376    [Return]  ${invalid_user_id}
377
378
379Verify Set User Access Payload For Invalid Channel
380    [Documentation]  Verify set user payload command for invalid channels.
381    [Arguments]  ${user_id}  ${channel_number}
382
383    # Description of argument(s):
384    # user_id           The user ID (e.g. "1", "2", etc.).
385    # channel_number    Input channel number.
386
387    ${channel_number}=  Convert To Hex  ${channel_number}  prefix=0x
388    ${user_id}=  Convert To Hex  ${user_id}  prefix=0x
389    ${raw_cmd}=  Catenate   ${IPMI_RAW_CMD['Payload']['Set_User_Access_Payload'][0]}
390    ...  ${channel_number} ${user_id} 0x02 0x00 0x00 0x00
391
392    Verify Invalid IPMI Command  ${raw_cmd}  0xcc
393
394
395Verify Get User Access Payload For Invalid User Or Channel
396    [Documentation]  Verify get user payload command for invalid userid or invalid channels.
397    [Arguments]  ${user_id}  ${channel_number}
398
399    # Description of argument(s):
400    # user_id           The user ID (e.g. "1", "2", etc.).
401    # channel_number    Input channel number.
402
403    ${channel_number}=  Convert To Hex  ${channel_number}  prefix=0x
404    ${user_id}=  Convert To Hex  ${user_id}  prefix=0x
405    ${raw_cmd}=  Catenate  ${IPMI_RAW_CMD['Payload']['Get_User_Access_Payload'][0]}
406    ...  ${channel_number} ${user_id}
407
408    Verify Invalid IPMI Command  ${raw_cmd}  0xcc