1*** Settings ***
2Documentation       Test suite for OpenBMC IPMI user management.
3
4Resource            ../lib/ipmi_client.robot
5Resource            ../lib/openbmc_ffdc.robot
6Library             ../lib/ipmi_utils.py
7
8Test Teardown       Test Teardown Execution
9
10
11*** Variables ***
12
13${invalid_username}     user%
14${invalid_password}     abc123
15${root_userid}          1
16${operator_level_priv}  0x3
17${admin_level_priv}     4
18${valid_password}       0penBmc1
19${max_password_length}  20
20${ipmi_setaccess_cmd}   channel setaccess
21
22
23*** Test Cases ***
24
25Verify IPMI User Summary
26    [Documentation]  Verify IPMI maximum supported IPMI user ID and
27    ...  enabled user form user summary
28    [Tags]  Verify_IPMI_User_Summary
29
30    # Delete all non-root IPMI (i.e. except userid 1)
31    Delete All Non Root IPMI User
32
33    # Create a valid user and enable it.
34    ${random_username}=  Generate Random String  8  [LETTERS]
35    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
36    IPMI Create User  ${random_userid}  ${random_username}
37    Run IPMI Standard Command  user enable ${random_userid}
38
39    # Verify maximum user count IPMI local user can have. Also verify
40    # currently enabled users.
41    ${resp}=  Run IPMI Standard Command  user summary
42    ${enabled_user_count}=
43    ...  Get Lines Containing String  ${resp}  Enabled User Count
44    ${maximum_ids}=  Get Lines Containing String  ${resp}  Maximum IDs
45    Should Contain  ${enabled_user_count}  2
46    Should Contain  ${maximum_ids}  15
47
48
49Verify IPMI User Creation With Valid Name And ID
50    [Documentation]  Create user via IPMI and verify.
51    [Tags]  Test_IPMI_User_Creation_With_Valid_Name_And_ID
52
53    ${random_username}=  Generate Random String  8  [LETTERS]
54    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
55    IPMI Create User  ${random_userid}  ${random_username}
56
57
58Verify IPMI User Creation With Invalid Name
59    [Documentation]  Verify error while creating IPMI user with invalid
60    ...  name(e.g. user name with special characters).
61    [Tags]  Verify_IPMI_User_Creation_With_Invalid_Name
62
63    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
64    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
65    ...  user set name ${random_userid} ${invalid_username}
66    Should Contain  ${msg}  Invalid data
67
68
69Verify IPMI User Creation With Invalid ID
70    [Documentation]  Verify error while creating IPMI user with invalid
71    ...  ID(i.e. any number greater than 15 or 0).
72    [Tags]  Verify_IPMI_User_Creation_With_Invalid_ID
73
74    @{id_list}=  Create List
75    ${random_invalid_id}=  Evaluate  random.randint(16, 1000)  modules=random
76    Append To List  ${id_list}  ${random_invalid_id}
77    Append To List  ${id_list}  0
78
79    :FOR  ${id}  IN  @{id_list}
80    \    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
81    \    ...  user set name ${id} newuser
82    \    Should Contain  ${msg}  User ID is limited to range
83
84
85Verify Setting IPMI User With Invalid Password
86    [Documentation]  Verify error while setting IPMI user with invalid
87    ...  password.
88    [Tags]  Verify_Setting_IPMI_User_With_Invalid_Password
89
90    # Create IPMI user.
91    ${random_username}=  Generate Random String  8  [LETTERS]
92    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
93    IPMI Create User  ${random_userid}  ${random_username}
94
95    # Set invalid password for newly created user.
96    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
97    ...  user set password ${random_userid} ${invalid_password}
98
99    Should Contain  ${msg}  Invalid data field in request
100
101
102Verify Setting IPMI Root User With New Name
103    [Documentation]  Verify error while setting IPMI root user with new
104    ...  name.
105    [Tags]  Verify_Setting_IPMI_Root_User_With_New_Name
106
107    # Set invalid password for newly created user.
108    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
109    ...  user set name ${root_userid} abcd
110
111    Should Contain  ${msg}  Set User Name command failed
112
113
114Verify IPMI User Password Via Test Command
115    [Documentation]  Verify IPMI user password using test command.
116    [Tags]  Verify_IPMI_User_Password_Via_Test_Command
117
118    # Create IPMI user.
119    ${random_username}=  Generate Random String  8  [LETTERS]
120    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
121    IPMI Create User  ${random_userid}  ${random_username}
122
123    # Set valid password for newly created user.
124    Run IPMI Standard Command
125    ...  user set password ${random_userid} ${valid_password}
126
127    # Verify newly set password using test command.
128    ${msg}=  Run IPMI Standard Command
129    ...  user test ${random_userid} ${max_password_length} ${valid_password}
130
131    Should Contain  ${msg}  Success
132
133
134Verify Setting Valid Password For IPMI User
135    [Documentation]  Set valid password for IPMI user and verify.
136    [Tags]  Verify_Setting_Valid_Password_For_IPMI_User
137
138    # Create IPMI user.
139    ${random_username}=  Generate Random String  8  [LETTERS]
140    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
141    IPMI Create User  ${random_userid}  ${random_username}
142
143    # Set valid password for newly created user.
144    Run IPMI Standard Command
145    ...  user set password ${random_userid} ${valid_password}
146
147    # Enable IPMI user
148    Run IPMI Standard Command  user enable ${random_userid}
149
150    # Set admin privilege and enable IPMI messaging for newly created user
151    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
152
153    Verify IPMI Username And Password  ${random_username}  ${valid_password}
154
155
156Verify IPMI User Creation With Same Name
157    [Documentation]  Verify error while creating two IPMI user with same name.
158    [Tags]  Verify_IPMI_User_Creation_With_Same_Name
159
160    ${random_username}=  Generate Random String  8  [LETTERS]
161    IPMI Create User  2  ${random_username}
162
163    # Set same username for another IPMI user.
164    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
165    ...  user set name 3 ${random_username}
166    Should Contain  ${msg}  Invalid data field in request
167
168
169Verify Setting IPMI User With Null Password
170    [Documentation]  Verify error while setting IPMI user with null
171    ...  password.
172    [Tags]  Verify_Setting_IPMI_User_With_Null_Password
173
174    # Create IPMI user.
175    ${random_username}=  Generate Random String  8  [LETTERS]
176    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
177    IPMI Create User  ${random_userid}  ${random_username}
178
179    # Set null password for newly created user.
180    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
181    ...  user set password ${random_userid} ""
182
183    Should Contain  ${msg}  Invalid data field in request
184
185
186Verify IPMI User Deletion
187    [Documentation]  Delete user via IPMI and verify.
188    [Tags]  Verify_IPMI_User_Deletion
189
190    ${random_username}=  Generate Random String  8  [LETTERS]
191    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
192    IPMI Create User  ${random_userid}  ${random_username}
193
194    # Delete IPMI User and verify
195    Run IPMI Standard Command  user set name ${random_userid} ""
196    ${user_info}=  Get User Info  ${random_userid}
197    Should Be Equal  ${user_info['user_name']}  ${EMPTY}
198
199
200Enable IPMI User And Verify
201    [Documentation]  Enable IPMI user and verify that the user is able
202    ...  to run IPMI command.
203    [Tags]  Enable_IPMI_User_And_Verify
204
205    # Create IPMI user and set valid password.
206    ${random_username}=  Generate Random String  8  [LETTERS]
207    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
208    IPMI Create User  ${random_userid}  ${random_username}
209    Run IPMI Standard Command
210    ...  user set password ${random_userid} ${valid_password}
211
212    # Set admin privilege and enable IPMI messaging for newly created user.
213    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
214
215    # Enable IPMI user and verify.
216    Run IPMI Standard Command  user enable ${random_userid}
217    ${user_info}=  Get User Info  ${random_userid}
218    Should Be Equal  ${user_info['enable_status']}  enabled
219
220    # Verify that enabled IPMI  user is able to run IPMI command.
221    Verify IPMI Username And Password  ${random_username}  ${valid_password}
222
223
224Disable IPMI User And Verify
225    [Documentation]  Disable IPMI user and verify that that the user
226    ...  is unable to run IPMI command.
227    [Tags]  Disable_IPMI_User_And_Verify
228
229    # Create IPMI user and set valid password.
230    ${random_username}=  Generate Random String  8  [LETTERS]
231    ${random_userid}=  Evaluate  random.randint(2, 15)  modules=random
232    IPMI Create User  ${random_userid}  ${random_username}
233    Run IPMI Standard Command
234    ...  user set password ${random_userid} ${valid_password}
235
236    # Set admin privilege and enable IPMI messaging for newly created user.
237    Set Channel Access  ${random_userid}  ipmi=on privilege=${admin_level_priv}
238
239    # Disable IPMI user and verify.
240    Run IPMI Standard Command  user disable ${random_userid}
241    ${user_info}=  Get User Info  ${random_userid}
242    Should Be Equal  ${user_info['enable_status']}  disabled
243
244    # Verify that disabled IPMI  user is unable to run IPMI command.
245    ${msg}=  Run Keyword And Expect Error  *  Verify IPMI Username And Password
246    ...  ${random_username}  ${valid_password}
247    Should Contain  ${msg}  Unable to establish IPMI
248
249
250Verify IPMI Root User Password Change
251    [Documentation]  Change IPMI root user password and verify that
252    ...  root user is able to run IPMI command.
253    [Tags]  Verify_IPMI_Root_User_Password_Change
254    [Teardown]  Wait Until Keyword Succeeds  15 sec  5 sec
255    ...  Set Default Password For IPMI Root User
256
257    # Set new password for root user.
258    Run IPMI Standard Command
259    ...  user set password ${root_userid} ${valid_password}
260
261    # Verify that root user is able to run IPMI command using new password.
262    Verify IPMI Username And Password  root  ${valid_password}
263
264
265*** Keywords ***
266
267Set Default Password For IPMI Root User
268    [Documentation]  Set default password for IPMI root user (i.e. 0penBmc).
269    # Set default password for root user.
270    ${result}=  Run External IPMI Standard Command
271    ...  user set password ${root_userid} ${OPENBMC_PASSWORD}
272    ...  P=${valid_password}
273    Should Contain  ${result}  Set User Password command successful
274
275    # Verify that root user is able to run IPMI command using default password.
276    Verify IPMI Username And Password  root  ${OPENBMC_PASSWORD}
277
278
279Delete All Non Root IPMI User
280    [Documentation]  Delete all non-root IPMI user.
281
282    :FOR  ${userid}  IN RANGE  2  16
283    \  ${user_info}=  Get User Info  ${userid}
284    \  Run Keyword If  "${user_info['user_name']}" != ""
285    ...  Run IPMI Standard Command  user set name ${userid} ""
286
287
288Test Teardown Execution
289    [Documentation]  Do the test teardown execution.
290
291    FFDC On Test Case Fail
292    Delete All Non Root IPMI User
293
294