1*** Settings ***
2
3Documentation    Test Save Area feature of Management Console on BMC.
4
5Resource          ../../lib/rest_client.robot
6Resource          ../../lib/openbmc_ffdc.robot
7Resource          ../../lib/resource.robot
8Resource          ../../lib/bmc_redfish_utils.robot
9Resource          ../../lib/utils.robot
10
11Suite Setup       Suite Setup Execution
12Test Teardown     Test Teardown Execution
13Suite Teardown    Suite Teardown Execution
14
15
16*** Variables ***
17
18${MAX_SIZE_MSG}           File size exceeds maximum allowed size[500KB]
19${UPLOADED_MSG}           File Created
20${FORBIDDEN_MSG}          Forbidden
21${FILE_CREATE_ERROR_MSG}  Error while creating the file
22
23@{ADMIN}                  admin_user              TestPwd123
24@{OPERATOR}               operator_user           TestPwd123
25&{USERS}                  Administrator=${ADMIN}  Operator=${OPERATOR}
26
27*** Test Cases ***
28
29Verify Small Partition File Upload And Delete
30    [Documentation]  Verify small partition file upload and delete.
31    [Tags]  Verify_Small_Partition_File_Upload_And_Delete
32    [Template]  Upload File To Create Partition Then Delete Partition
33
34    #                     partition                                         delete
35    # file_name  size_kb  name       expect_resp_code     expected_msg      partition    username
36    501KB_file   501      501KB      ${HTTP_BAD_REQUEST}  ${MAX_SIZE_MSG}   ${True}      ${OPENBMC_USERNAME}
37    15KB_file    15       15KB       ${HTTP_OK}           ${UPLOADED_MSG}   ${True}      ${OPENBMC_USERNAME}
38    500KB_file   500      500KB      ${HTTP_OK}           ${UPLOADED_MSG}   ${True}      ${OPENBMC_USERNAME}
39
40
41Verify Multiple Files Upload
42    [Documentation]  Verify multiple files upload.
43    [Tags]  Verify_Multiple_Files_Upload
44    [Template]  Upload File To Create Partition Then Delete Partition
45
46    #                     partition                                         delete
47    # file_name  size_kb  name       expect_resp_code     expected_msg      partition    username
48    0KB_file     0        0KB        ${HTTP_OK}           ${UPLOADED_MSG}   ${False}     ${OPENBMC_USERNAME}
49    10KB_file    10       10KB       ${HTTP_OK}           ${UPLOADED_MSG}   ${False}     ${OPENBMC_USERNAME}
50    50KB_file    50       50KB       ${HTTP_OK}           ${UPLOADED_MSG}   ${False}     ${OPENBMC_USERNAME}
51    550KB_file   550      550KB      ${HTTP_BAD_REQUEST}  ${MAX_SIZE_MSG}   ${False}     ${OPENBMC_USERNAME}
52    19KB_file    19       19KB       ${HTTP_OK}           ${UPLOADED_MSG}   ${False}     ${OPENBMC_USERNAME}
53    499KB_file   199      499KB      ${HTTP_OK}           ${UPLOADED_MSG}   ${False}     ${OPENBMC_USERNAME}
54
55
56Verify Read Partition
57    [Documentation]  Verify read partition.
58    [Tags]  Verify_Read_Partition
59
60    Set Test Variable  ${file_name}  testfile
61    Set Test Variable  ${partition_name}  part_read
62    Set Test Variable  ${content}  Sample Content to test partition file upload
63
64    Run  echo "${content}" > ${file_name}
65    OperatingSystem.File Should Exist  ${file_name}
66
67    Upload File To Create Partition Then Delete Partition  ${file_name}  1  ${partition_name}
68    ...  delete_partition=${False}
69
70    Read Partition And Verify Content  ${partition_name}  ${content}
71
72
73Verify Non-Admin User Is Forbidden To Upload Partition File
74    [Documentation]  Verify non-admin user is forbidden to upload partition file.
75    [Tags]   Verify_Non-Admin_User_Is_Forbidden_To_Upload_Partition_File
76    [Template]  Upload File To Create Partition Then Delete Partition
77
78    #                     partition                                         delete
79    # file_name  size_kb  name       expect_resp_code     expected_msg      partition    username
80    12KB_file    12       12KB       ${HTTP_FORBIDDEN}    ${FORBIDDEN_MSG}  ${False}     operator_user
81
82
83Verify Partition Update On BMC
84    [Documentation]  Verify partition update on BMC.
85    [Tags]  Verify_Partition_Update_On_BMC
86
87    Set Test Variable  ${file_name}  testfile
88    Set Test Variable  ${partition_name}  part_read
89    Set Test Variable  ${content1}  Sample Content to test partition file upload
90    Set Test Variable  ${content2}  Sample Content to test partition file update
91
92    Upload Partition File With Some Known Contents  ${file_name}  ${partition_name}  ${content1}
93    Read Partition And Verify Content  ${partition_name}  ${content1}
94
95    # Upload the same partition with modified contents to verify update partition feature.
96    Upload Partition File With Some Known Contents  ${file_name}  ${partition_name}  ${content2}
97    Read Partition And Verify Content  ${partition_name}  ${content2}
98
99
100Verify Delete Partition When Partition Does Not Exist
101    [Documentation]  Verify delete partition when partition does not exist.
102    [Tags]  Verify_Delete_Partition_When_Partition_Does_Not_Exist
103    [Template]  Delete Partition And Verify On BMC
104
105    # partition_name    expect_resp_code      username
106    Does_not_exist      ${HTTP_NOT_FOUND}     ${OPENBMC_USERNAME}
107    Does_not_exist      ${HTTP_FORBIDDEN}     operator_user
108
109
110Verify Partition Files Persistency And Re-upload After BMC Reboot
111    [Documentation]  Verify partition files persistency and re-upload after BMC reboot.
112    [Tags]  Verify_Partition_Files_Persistency_And_Re-upload_After_BMC_Reboot
113
114    Set Test Variable  ${file_name}  testfile
115    Set Test Variable  ${partition_name}  part_read
116    Set Test Variable  ${content}  Sample Content to test partition file upload
117
118    Upload Partition File With Some Known Contents
119    ...  ${file_name}_1  ${partition_name}_1  ${content}_${file_name}_1
120    Upload Partition File With Some Known Contents
121    ...  ${file_name}_2  ${partition_name}_2  ${content}_${file_name}_2
122
123    OBMC Reboot (off)
124
125    # Get REST session to BMC.
126    Initialize OpenBMC
127
128    # Checking for the content of uploaded partitions after BMC reboot.
129    Read Partition And Verify Content  ${partition_name}_1  ${content}_${file_name}_1
130    Read Partition And Verify Content  ${partition_name}_2  ${content}_${file_name}_2
131
132    # Upload same partition with different content to test partition update after BMC reboot.
133    Upload Partition File With Some Known Contents
134    ...  ${file_name}_1  ${partition_name}_1  ${content}_${file_name}_2
135
136    # Upload different partition.
137    Upload Partition File With Some Known Contents  ${file_name}  ${partition_name}  ${content}
138
139
140Verify One Thousand Partitions File Upload
141    [Documentation]  Verify One Thousand Partitions File Upload.
142    [Tags]  Verify_One_Thousand_Partitions_File_Upload
143
144    # Note: 1000 Partitions file upload would take 15-20 minutes.
145    FOR  ${INDEX}  IN RANGE  1  1000
146        ${status}=  Run Keyword And Return Status  Upload File To Create Partition Then Delete Partition
147        ...  200KB  200  p${INDEX}  delete_partition=${False}
148        Run Keyword If  ${status} == ${True}  Continue For Loop
149
150        # Check if /var is full on BMC.
151        ${status}  ${stderr}  ${rc}=  BMC Execute Command  df -k | grep \' /var\' | grep -v /var/
152        ${var_size}=  Set Variable  ${status.split('%')[0].split()[1]}
153
154        # Should be a problem if partition file upload request has failed when /var is not full.
155        Exit For Loop If  ${var_size} != ${100}
156
157        # Expect HTTP_INTERNAL_SERVER_ERROR and FILE_CREATE_ERROR_MSG when /var is full.
158        Upload File To Create Partition Then Delete Partition
159        ...  200KB  200  p${INDEX}  ${HTTP_INTERNAL_SERVER_ERROR}  ${FILE_CREATE_ERROR_MSG}  ${False}
160    END
161
162
163*** Keywords ***
164
165Create Partition File
166    [Documentation]  Create partition file.
167    [Arguments]  ${file_name}=dummyfile  ${size_kb}=15
168
169    # Description of argument(s):
170    # file_name           Name of the test file to be created. Examples:  p1.log, part1.txt etc.
171    # size_kb             Size of the test file to be created in KB, default is 15KB.
172    #                     Example : 15, 200 etc.
173
174    ${file_exist}=  Run Keyword And Return Status  OperatingSystem.File Should Exist  ${file_name}
175    Return From Keyword If  ${file_exist}  ${True}
176
177    # Create a partition file if it does not exist locally.
178    Run  dd if=/dev/zero of=${file_name} bs=1 count=0 seek=${size_kb}KB
179    OperatingSystem.File Should Exist  ${file_name}
180
181
182Delete All Sessions And Login Using Given User
183    [Documentation]    Delete all sessions and login using given user.
184    [Arguments]   ${username}=${OPENBMC_USERNAME}
185
186    # Description of argument(s):
187    # username            Username to login. Default is OPENBMC_USERNAME.
188    #                     Ex: root, operator_user, admin_user, readonly_user etc.
189
190    Delete All Sessions
191    ${password}=  Set Variable If  '${username}' == '${OPENBMC_USERNAME}'  ${OPENBMC_PASSWORD}  TestPwd123
192    Initialize OpenBMC  rest_username=${username}  rest_password=${password}
193
194
195Upload File To Create Partition Then Delete Partition
196    [Documentation]  Upload file to create partition the delete partition.
197    [Arguments]  ${file_name}=dummyfile  ${size_kb}=15  ${partition_name}=p1  ${expect_resp_code}=${HTTP_OK}
198    ...  ${expected_msg}=File Created  ${delete_partition}=${True}  ${username}=${OPENBMC_USERNAME}
199
200    # Description of argument(s):
201    # file_name           Name of the test file to be created.
202    # partition_name      Name of the partition on BMC.
203    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
204    # expected_msg        Expected message from file upload, default is 'File Created'.
205    # delete_partition    Partition will be deleted if this is True.
206    # username            Login username
207
208    # Create a session with given user to test upload partition file.
209    Run Keyword If  '${username}' != '${OPENBMC_USERNAME}'
210    ...  Delete All Sessions And Login Using Given User  ${username}
211
212    # Create a partition file.
213    Create Partition File  ${file_name}  ${size_kb}
214
215    # Get the content of the file and upload to BMC.
216    ${image_data}=  OperatingSystem.Get Binary File  ${file_name}
217    ${data}=  Create Dictionary  data  ${image_data}
218    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
219
220    Set To Dictionary  ${data}  headers  ${headers}
221    ${resp}=  Put Request  openbmc  /ibm/v1/Host/ConfigFiles/${partition_name}  &{data}
222    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
223
224    ${description}=  Run Keyword If  ${expect_resp_code} != ${HTTP_FORBIDDEN}
225    ...  Return Description Of REST Response  ${resp.text}
226    ...  ELSE  Set Variable  ${FORBIDDEN_MSG}
227
228    Should Be Equal As Strings  ${description}  ${expected_msg}
229
230    # Cleanup local space after upload attempt.
231    Run Keyword And Ignore Error  Delete Local File Created To Upload  ${file_name}
232
233    ${upload_success}=  Set Variable If   ${expect_resp_code} != ${HTTP_OK}  ${False}  ${True}
234    Verify Partition Available On BMC  ${partition_name}  ${upload_success}  ${username}
235
236    # Delete partition and verify on BMC.
237    ${expect_resp_code}=  Set Variable If  ${expect_resp_code} != ${HTTP_OK}  ${HTTP_NOT_FOUND}  ${HTTP_OK}
238    Run Keyword If  ${delete_partition} == ${True}  Delete Partition And Verify On BMC
239    ...  ${partition_name}  ${expect_resp_code}  ${username}
240
241
242Return Description Of REST Response
243    [Documentation]  Return description of REST response.
244    [Arguments]  ${resp_text}
245
246    # Description of argument(s):
247    # resp_text    REST response body.
248
249    # resp_text after successful partition file upload looks like:
250    #           {
251    #             "Description": "File Created"
252    #           }
253
254    ${message}=  Evaluate  json.loads('''${resp_text}''')  json
255
256    [Return]  ${message["Description"]}
257
258
259Delete Partition And Verify On BMC
260    [Documentation]  Delete partition and verify on BMC.
261    [Arguments]  ${partition_name}  ${expect_resp_code}=${HTTP_OK}  ${username}=${OPENBMC_USERNAME}
262
263    # Description of argument(s):
264    # partition_name      Name of the partition on BMC.
265    # expect_resp_code    Expected REST response code from DELETE request, default is ${HTTP_OK}.
266    # username            Username to login, if other than OPENBMC_USERNAME user.
267
268    # Create a session with given user to test delete operation.
269    # If user is a non-admin user then DELETE request is forbidden for the user.
270    Run Keyword If  '${username}' != '${OPENBMC_USERNAME}'
271    ...  Delete All Sessions And Login Using Given User  ${username}
272
273    Delete Partition  ${partition_name}  ${expect_resp_code}
274    Verify Partition Available On BMC  ${partition_name}  ${False}  ${username}
275
276
277Get List Of Partitions
278    [Documentation]  Get list of partitions.
279    [Arguments]  ${expect_resp_code}=${HTTP_OK}
280
281    # Description of argument(s):
282    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
283
284    ${resp}=  Get Request  openbmc  /ibm/v1/Host/ConfigFiles
285    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
286    Return From Keyword If  ${expect_resp_code} != ${HTTP_OK}
287
288    ${resp_json}=  To JSON  ${resp.content}
289    ${partitions_cnt}=  Get Length  ${resp_json['Members']}
290
291    [Return]  ${resp_json['Members']}  ${partitions_cnt}
292
293
294Verify Partition Available On BMC
295    [Documentation]  Verify partition available on BMC.
296    [Arguments]  ${partition_name}=${EMPTY}  ${operation_status}=${True}  ${username}=${OPENBMC_USERNAME}
297
298    # Description of argument(s):
299    # partition_name     Name of the partition on BMC.
300    # operation_success  Status of the previous operation like upload/delete success or failure.
301    #                    True if operation was a success else False.
302    # username           Username used to upload/delete. Default is ${OPENBMC_USERNAME}.
303
304    # Non admin users will not have an access to do GET list
305    Run Keyword If  '${username}' != '${OPENBMC_USERNAME}'
306    ...  Delete All Sessions And Login Using Given User
307
308    ${partitions}  ${partitions_cnt}=  Get List Of Partitions
309    ${rest_response}=  Run Keyword And Return Status  List Should Contain Value  ${partitions}
310    ...  /ibm/v1/Host/ConfigFiles/${partition_name}
311
312    ${status}  ${stderr}  ${rc}=  BMC Execute Command
313    ...  ls -l /var/lib/obmc/bmc-console-mgmt/save-area/${partition_name} | wc -l
314    ${bmc_response}=  Run Keyword And Return Status  Should Be True  ${status} == ${1}
315
316    Run Keyword If  '${partition_name}' == '${EMPTY}'  Run Keywords
317    ...  Should Be Equal  ${rest_response}  ${False}  AND  Should Be Equal  ${bmc_response}  ${False}
318
319    Run Keyword And Return If  '${partition_name}' != '${EMPTY}'  Run Keywords
320    ...  Should Be True  ${rest_response} == ${operation_status}  AND
321    ...  Should Be True  ${bmc_response} == ${operation_status}
322
323
324Delete Partition
325    [Documentation]  Delete partition.
326    [Arguments]  ${partition_name}='${EMPTY}'  ${expect_resp_code}=${HTTP_OK}
327
328    # Description of argument(s):
329    # partition_name      Name of the partition on BMC.
330    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
331
332    ${data}=  Create Dictionary
333    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
334    Set To Dictionary  ${data}  headers  ${headers}
335
336    ${resp}=  Delete Request  openbmc  /ibm/v1/Host/ConfigFiles/${partition_name}  &{data}
337    ${expect_resp_code}=  Set Variable If  '${partition_name}' == '${EMPTY}'
338    ...  ${HTTP_NOT_FOUND}  ${expect_resp_code}
339    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
340
341
342Delete And Verify All Partitions on BMC
343    [Documentation]  Delete and verify all partitions on BMC.
344    [Arguments]  ${expect_resp_code}=${HTTP_OK}
345
346    # Description of argument(s):
347    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
348
349    ${data}=  Create Dictionary
350    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
351    Set To Dictionary  ${data}  headers  ${headers}
352
353    ${resp}=  Post Request  openbmc  /ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll  &{data}
354    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
355
356    Return From Keyword If  ${expect_resp_code} != ${HTTP_OK}
357    Verify Partition Available On BMC  operation_status=${False}
358
359
360Read Partition And Verify Content
361    [Documentation]  Read partition and verify content.
362    [Arguments]  ${partition_name}=p1  ${content}=${EMPTY}  ${expect_resp_code}=${HTTP_OK}
363
364    # Description of argument(s):
365    # partition_name      Name of the partition on BMC.
366    # content             Content of the partition file uploaded.
367    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
368
369    ${resp}=  Get Request  openbmc  /ibm/v1/Host/ConfigFiles/${partition_name}
370    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
371
372    ${partition_data}=  Remove String  ${resp.text}  \\n
373    ${partition_data}=  Evaluate  json.loads('''${partition_data}''')  json
374    Should Be Equal As Strings  ${partition_data["Data"]}  ${content}
375
376
377Delete Local File Created To Upload
378    [Documentation]  Delete local file created to upload.
379    [Arguments]  ${file_name}
380
381    # Description of argument(s):
382    # file_name       Name of the local file to be deleted.
383
384    Run Keyword And Ignore Error  Run  rm -f ${file_name}
385
386
387Upload Partition File With Some Known Contents
388    [Documentation]  Upload partition file with some known contents.
389    [Arguments]  ${file_name}  ${partition_name}  ${content}
390
391    # Description of argument(s):
392    # file_name           Name of the partition file to be uploaded.
393    # partition_name      Name of the partition on BMC.
394    # content             Content of the partition file to be uploaded.
395
396    Run  echo "${content}" > ${file_name}
397    OperatingSystem.File Should Exist  ${file_name}
398
399    Upload File To Create Partition Then Delete Partition  ${file_name}  1  ${partition_name}
400    ...  delete_partition=${False}
401
402
403Suite Setup Execution
404    [Documentation]  Suite setup execution.
405
406    # Create different user accounts.
407    Redfish.Login
408    Create Users With Different Roles  users=${USERS}  force=${True}
409    # Get REST session to BMC.
410    Initialize OpenBMC
411
412
413Test Teardown Execution
414    [Documentation]  Test teardown execution.
415
416    Delete And Verify All Partitions on BMC
417    FFDC On Test Case Fail
418
419
420Suite Teardown Execution
421    [Documentation]  Suite teardown execution.
422
423    Delete BMC Users Via Redfish  users=${USERS}
424    Delete All Sessions
425