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