xref: /openbmc/openbmc-test-automation/openpower/ext_interfaces/test_savearea_management.robot (revision 4081fca72d6581b4c12178362e4e08eaa30f9ae9)
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
10Resource          ../../lib/bmc_redfish_resource.robot
11
12Suite Setup       Suite Setup Execution
13Test Teardown     Test Teardown Execution
14Suite Teardown    Suite Teardown Execution
15
16*** Variables ***
17
18${MAXIMUM_FILE_SIZE_MESSAGE}        File size exceeds maximum allowed size[10MB]
19${MAXIMUM_DIR_SIZE_MESSAGE}
20...   File size does not fit in the savearea directory maximum allowed size[10MB]
21${FILE_UPLOAD_MESSAGE}              File Created
22${FILE_DELETED_MESSAGE}             File Deleted
23${FILE_UPDATED_MESSAGE}             File Updated
24${FORBIDDEN_MESSAGE}                Forbidden
25${ERROR_MESSAGE}                    Error while creating the file
26${RESOURCE_NOT_FOUND_MESSAGE}       Resource Not Found
27${MINIMUM_FILE_SIZE_MESSAGE}        File size is less than minimum allowed size[100B]
28${MAXIMUM_FILE_NAME_MESSAGE}        Filename must be maximum 20 characters
29${UNSUPPORTED_FILE_NAME_MESSAGE}    Unsupported character in filename
30
31${content-1}                        Sample Content to test partition file upload
32...  Sample Content to test partition file upload
33...  Sample Content to test partition file upload
34${content-2}                        Sample Content to test partition file upload after reboot
35...  Sample Content to test partition file upload after reboot
36...  Sample Content to test partition file upload after reboot
37
38${LOOP_COUNT}                       10
39
40*** Test Cases ***
41
42Redfish Upload Lower Limit Partition File To BMC
43    [Documentation]  Upload lower limit of allowed partition file to BMC using Redfish.
44    [Tags]  Redfish_Upload_Lower_Limit_Partition_File_To_BMC
45    [Template]  Redfish Upload Partition File
46
47    # file_name
48    100-file
49
50
51Redfish Upload Partition File To BMC
52    [Documentation]  Upload partition file to BMC using Redfish.
53    [Tags]  Redfish_Upload_Partition_File_To_BMC
54    [Template]  Redfish Upload Partition File
55
56    # file_name
57    500KB-file
58    501KB-file
59    550KB-file
60    10000KB-file
61
62
63Test Upload Lower Limit Partition File To BMC And Expect Failure
64    [Documentation]  Fail to upload partition file to BMC with file size
65    ...  below the lower limit of allowed partition file size using Redfish.
66    [Tags]  Test_Upload_Lower_Limit_Partition_File_To_BMC_And_Expect_Failure
67    [Template]  Redfish Fail To Upload Partition File
68
69    # file_name    status_code            partition_status    response_message
70    99-file        ${HTTP_BAD_REQUEST}    0                   ${MINIMUM_FILE_SIZE_MESSAGE}
71
72
73Test Upload Upper Limit Partition File To BMC And Expect Failure
74    [Documentation]  Fail to upload partition file to BMC with file size
75    ...  more than upper limit of allowed partition file size using Redfish.
76    [Tags]  Test_Upload_Upper_Limit_Partition_File_To_BMC_And_Expect_Failure
77    [Template]  Redfish Fail To Upload Partition File
78
79    # file_name     status_code            partition_status    response_message
80    10001KB-file    ${HTTP_BAD_REQUEST}    0                   ${MAXIMUM_FILE_SIZE_MESSAGE}
81
82
83Redfish Upload Multiple Partition File To BMC
84    [Documentation]  Upload multiple partition file to BMC using Redfish.
85    [Tags]  Redfish_Upload_Multiple_Partition_File_To_BMC
86    [Template]  Redfish Upload Partition File
87
88    # file_name
89    250KB-file,500KB-file
90
91
92Redfish Fail To Upload Multiple Partition File To BMC
93    [Documentation]  Fail to upload multiple partition file to BMC using Redfish.
94    [Tags]  Redfish_Fail_To_Upload_Multiple_Partition_File_To_BMC
95    [Template]  Redfish Fail To Upload Partition File
96
97    # file_name     status_code            partition_status    response_message
98    5000KB-file     ${HTTP_OK}             1                   ${FILE_UPLOAD_MESSAGE}
99    6000KB-file     ${HTTP_BAD_REQUEST}    0                   ${MAXIMUM_DIR_SIZE_MESSAGE}
100    10000KB-file    ${HTTP_OK}             1                   ${FILE_UPLOAD_MESSAGE}
101    100-file        ${HTTP_BAD_REQUEST}    0                   ${MAXIMUM_DIR_SIZE_MESSAGE}
102
103
104Redfish Upload Same Partition File To BMC In Loop
105    [Documentation]  Upload same partition file to BMC using Redfish in loop.
106    [Tags]  Redfish_Upload_Same_Partition_File_To_BMC_In_Loop
107    [Template]  Redfish Upload Partition File In Loop
108
109    # file_name
110    500KB-file
111
112
113Redfish Upload And Delete Same Partition File To BMC In Loop
114    [Documentation]  Upload same partition file to BMC using Redfish in loop.
115    [Tags]  Redfish_Upload_And_Delete_Same_Partition_File_To_BMC_In_Loop
116    [Template]  Redfish Upload And Delete Partition File In Loop
117
118    # file_name
119    500KB-file
120
121
122Redfish Partition File Upload Post BMC Reboot
123    [Documentation]  Upload partition file to BMC using Redfish, after the BMC reboot.
124    [Tags]  Redfish_Partition_File_Upload_Post_BMC_Reboot
125    [Template]  Verify Partition File Upload Post BMC Reboot
126
127    # file_name
128    500KB-file
129
130
131Redfish Partition File Persistency On BMC Reboot
132    [Documentation]  Upload partition file to BMC using Redfish and is same after reboot.
133    [Tags]  Redfish_Partition_File_Persistency_On_BMC_Reboot
134    [Template]  Redfish Partition File Persistency
135
136    # file_name
137    500KB-file
138
139
140Redfish Multiple Partition File Persistency On BMC Reboot
141    [Documentation]  Upload multiple partition file to BMC using Redfish and is same after reboot.
142    [Tags]  Redfish_Multiple_Partition_File_Persistency_On_BMC_Reboot
143    [Template]  Redfish Partition File Persistency
144
145    # file_name
146    250KB-file,500KB-file
147
148
149Redfish Read Partition File On BMC
150    [Documentation]  Upload partition file to BMC using Redfish and verify the content.
151    [Tags]  Redfish_Read_Partition_File_On_BMC
152    [Template]  Redfish Read Partition File
153
154    # file_name                      reboot_flag
155    testfile01-file                  False
156    testfile01-file,testfile02-file  False
157
158
159Redfish Read Partition File On BMC Reboot
160    [Documentation]  Upload partition file to BMC using Redfish and verify the content after reboot.
161    [Tags]  Check_Redfish_Read_Partition_File_On_BMC_Reboot
162    [Template]  Redfish Read Partition File
163
164    # file_name                      reboot_flag
165    testfile01-file                  True
166    testfile01-file,testfile02-file  True
167
168
169Redfish Update Partition File On BMC
170    [Documentation]  Upload partition file to BMC using Redfish and verify the content.
171    [Tags]  Redfish_Update_Partition_File_On_BMC
172    [Template]  Redfish Update Partition File With Different Content
173
174    # file_name                 reboot_flag
175    testfile01-file             False
176
177
178Redfish Update Partition File On BMC Reboot
179    [Documentation]  Upload partition file to BMC using Redfish and verify the content after the reboot.
180    [Tags]  Redfish_Update_Partition_File_On_BMC_Reboot
181    [Template]  Redfish Update Partition File With Different Content
182
183    # file_name                 reboot_flag
184    testfile01-file             True
185
186
187Redfish Persistency Update Partition File On BMC
188    [Documentation]  Upload partition file to BMC using Redfish and verify the content.
189    [Tags]  Redfish_Persistency_Update_Partition_File_On_BMC
190    [Template]  Redfish Update Partition File With Same Content
191
192    # file_name                 reboot_flag
193    testfile01-file             False
194
195
196Redfish Persistency Update Partition File On BMC Reboot
197    [Documentation]  Upload partition file to BMC using Redfish and verify the content after the reboot.
198    [Tags]  Redfish_Persistency_Update_Partition_File_On_BMC_Reboot
199    [Template]  Redfish Update Partition File With Same Content
200
201    # file_name                 reboot_flag
202    testfile01-file             True
203
204
205Redfish Delete Non Existence Of Partition File
206    [Documentation]  Delete the partition file if do not exists.
207    [Tags]  Redfish_Delete_Non_Existence_Of_Partition_File
208    [Template]  Redfish Delete Non Existence Partition File
209
210    # file_name
211    testfile01-file
212
213
214Verify One Thousand Partitions File Upload
215    [Documentation]  Upload 1000 partition file to BMC.
216    [Tags]  Verify_One_Thousand_Partitions_File_Upload
217    [Template]  Redfish Upload Partition File With Range
218
219    # range
220    1000
221
222
223Non Admin Users Fail To Upload Partition File
224    [Documentation]  Non admin user will fail to upload the partition file.
225    [Tags]  Non_Admin_Users_Fail_To_Upload_Partition_File
226    [Template]  Non Admin User To Upload Partition File
227
228    # file_name    username         password       role_id
229    500KB-file     operator_user    TestPwd123     Operator
230
231
232Non Admin User Delete Non Existence Of Partition File
233    [Documentation]  Delete the partition file if does not exists.
234    [Tags]  Non_Admin_User_Delete_Non_Existence_Of_Partition_File
235    [Template]  Non Admin Delete Non Existence Partition File
236
237    # file_name    username         password       role_id
238    500KB-file     operator_user    TestPwd123     Operator
239
240
241Redfish Update Wrong Partition File To BMC
242    [Documentation]  Upload partition file to BMC by wrong URI using Redfish.
243    [Tags]  Redfish_Update_Wrong_Partition_File_To_BMC
244    [Template]  Verify Update Wrong Partition File To BMC
245
246    # file_name
247    500KB-file
248
249
250Test Redfish Upload Partition File Name With Character Limit To BMC
251    [Documentation]  Upload partition file to BMC with file name character allowed limit
252    ...  and above allowed limit using Redfish.
253    [Tags]  Test_Redfish_Upload_Partition_File_Name_With_Character_Limit_To_BMC
254    [Template]  Check Redfish Upload Partition File Name With Character Limit To BMC
255
256    # file_name              status_code            message
257    50KB-testfilesavfile     ${HTTP_OK}             ${FILE_UPLOAD_MESSAGE}
258    50KB-testsaveareafile    ${HTTP_BAD_REQUEST}    ${MAXIMUM_FILE_NAME_MESSAGE}
259
260
261Test Redfish Fail To Upload Partition File Name With Special Character To BMC
262    [Documentation]  Upload partition file to BMC with special character file name and
263    ...  Redfish through an error.
264    [Tags]  Test_Redfish_Fail_To_Upload_Partition_File_Name_With_Special_Character_To_BMC
265    [Template]  Check Redfish Fail To Upload Partition File Name With Special Character To BMC
266
267    # file_name      status_code            message
268    1KB-*filename    ${HTTP_BAD_REQUEST}    ${UNSUPPORTED_FILE_NAME_MESSAGE}
269    1KB-!filename    ${HTTP_BAD_REQUEST}    ${UNSUPPORTED_FILE_NAME_MESSAGE}
270    1KB-@filename    ${HTTP_BAD_REQUEST}    ${UNSUPPORTED_FILE_NAME_MESSAGE}
271
272
273Redfish Upload Validated Partition File From Path To BMC
274   [Documentation]  Upload valid partition file to BMC from file path define by user in loop.
275   ...  By default loop count values is 10 times.
276   [Tags]  Redfish_Upload_Validated_Partition_File_From_Path_To_BMC
277
278   Log To Console  ${EMPTY}
279   FOR  ${count}  IN RANGE  1  ${LOOP_COUNT} + 1
280     Log To Console  **************************************
281     Log To Console  * The Current Loop Count is ${count} of ${LOOP_COUNT} *
282     Log To Console  **************************************
283
284     Redfish Upload Partition File From Path  ${PARTITION_FILE_PATH}
285   END
286
287*** Keywords ***
288
289Suite Setup Execution
290    [Documentation]  Suite setup execution.
291
292    Redfish.Login
293
294
295Test Teardown Execution
296    [Documentation]  Test teardown execution.
297
298    Delete All BMC Partition File  ${HTTP_OK}
299    FFDC On Test Case Fail
300
301
302Suite Teardown Execution
303    [Documentation]  Suite teardown execution.
304
305    Delete All Sessions
306
307
308Delete Local Partition File
309    [Documentation]  Delete local partition file.
310    [Arguments]  ${file_name}
311
312    # Description of argument(s):
313    # file_name    Partition file name.
314
315    FOR  ${conf_file}  IN  @{file_name}
316      ${file_exist}=  Run Keyword And Return Status  OperatingSystem.File Should Exist  ${conf_file}
317      Run Keyword If  'True' == '${file_exist}'  Remove File  ${conf_file}
318    END
319
320
321Delete Local Server Partition File
322    [Documentation]  Local partition files which is getting uploaded to BMC,
323    ...  will get deleted after the uploads. If partition file name consist
324    ...  of “-file” then partition file gets deleted.
325
326    @{conf_file_list} =  OperatingSystem.List Files In Directory  ${EXECDIR}
327    ${match_conf_file_list}=  Get Matches  ${conf_file_list}  regexp=.*-file  case_insensitive=${True}
328
329    ${num_records}=  Get Length  ${match_conf_file_list}
330    Return From Keyword If  ${num_records} == ${0}  ${EMPTY}
331
332    FOR  ${conf_file}  IN  @{match_conf_file_list}
333      ${file_exist}=  Run Keyword And Return Status  OperatingSystem.File Should Exist  ${conf_file}
334      Run Keyword If  'True' == '${file_exist}'  Remove File  ${conf_file}
335    END
336
337
338Create Partition File
339    [Documentation]  Create Partition file.
340    [Arguments]  ${file_name}
341
342    # Description of argument(s):
343    # file_name    Partition file name.
344
345    Delete Local Partition File  ${file_name}
346
347    FOR  ${conf_file}  IN  @{file_name}
348      @{words}=  Split String  ${conf_file}  -
349      Run  dd if=/dev/zero of=${conf_file} bs=${words}[-0] count=1
350      OperatingSystem.File Should Exist  ${conf_file}
351    END
352
353
354Delete BMC Partition File
355    [Documentation]  Delete single partition file on BMC via Redfish.
356    [Arguments]  ${file_name}  ${status_code}  ${expected_message}
357
358    # Description of argument(s):
359    # file_name           Partition file name.
360    # status_code         HTTPS status code.
361    # expected_message    Expected message of URI.
362
363    FOR  ${conf_file}  IN  @{file_name}
364      ${data}=  Create Dictionary
365      ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
366      Set To Dictionary  ${data}  headers  ${headers}
367
368      ${resp}=  Delete Request  openbmc  /ibm/v1/Host/ConfigFiles/${conf_file}  &{data}
369      Should Be Equal As Strings  ${resp.status_code}  ${status_code}
370
371      ${description}=  Return Description Of Response  ${resp.text}
372      Should Be Equal As Strings  ${description}  ${expected_message}
373    END
374
375
376Delete All BMC Partition File
377    [Documentation]  Delete multiple partition file on BMC via Redfish.
378    [Arguments]  ${status_code}
379
380    # Description of argument(s):
381    # status_code       HTTPS status code.
382
383    Initialize OpenBMC
384    ${data}=  Create Dictionary
385    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
386    Set To Dictionary  ${data}  headers  ${headers}
387
388    ${resp}=  Post Request  openbmc  /ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll  &{data}
389    Should Be Equal As Strings  ${resp.status_code}  ${status_code}
390
391
392Return Description Of Response
393    [Documentation]  Return description of REST response.
394    [Arguments]  ${resp_text}
395
396    # Description of argument(s):
397    # resp_text    REST response body.
398
399    # resp_text after successful partition file upload looks like:
400    # {
401    #    "Description": "File Created"
402    # }
403
404    ${status}=  Run Keyword And Return Status  Evaluate  isinstance(${resp_text}, dict)
405    Return From Keyword If  '${status}' == 'False'  ${resp_text}
406    ${message}=  Evaluate  json.loads('''${resp_text}''')  json
407
408    [Return]  ${message["Description"]}
409
410
411Upload Partition File To BMC
412    [Documentation]  Upload partition file to BMC.
413    [Arguments]  ${file_name}  ${status_code}  ${expected_message}  ${flag}=${True}  ${path}=${EMPTY}
414
415    # Description of argument(s):
416    # file_name           Partition file name.
417    # status_code         HTTPS status code.
418    # expected_message    Expected message of URI.
419    # flag                If True run part of program, else skip.
420    # path                Partition file path.
421
422    Run Keyword If  '${flag}' == '${True}'  Initialize OpenBMC
423    FOR  ${conf_file}  IN  @{file_name}
424      # Get the content of the file and upload to BMC.
425      ${image_data}=  OperatingSystem.Get Binary File  ${path}${conf_file}
426      ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}  Content-Type=application/octet-stream
427
428      ${kwargs}=  Create Dictionary  data=${image_data}
429      Set To Dictionary  ${kwargs}  headers  ${headers}
430      ${resp}=  Put Request  openbmc  /ibm/v1/Host/ConfigFiles/${conf_file}  &{kwargs}  timeout=10
431      Should Be Equal As Strings  ${resp.status_code}  ${status_code}
432
433      ${description}=  Return Description Of Response  ${resp.text}
434      Should Be Equal As Strings  ${description}  ${expected_message}
435    END
436
437
438Verify Partition File On BMC
439    [Documentation]  Verify partition file on BMC.
440    [Arguments]  ${file_name}  ${Partition_status}
441
442    # Description of argument(s):
443    # file_name           Partition file name.
444    # Partition_status    Partition file status on BMC.
445
446    FOR  ${conf_file}  IN  @{file_name}
447      ${status}  ${stderr}  ${rc}=  BMC Execute Command
448      ...  ls -l /var/lib/bmcweb/ibm-management-console/configfiles/${conf_file} | wc -l
449      Valid Value  ${status}  [${Partition_status}]
450    END
451
452
453Redfish Upload Partition File
454    [Documentation]  Upload the partition file.
455    [Arguments]  ${file_name}  ${file_size}=${EMPTY}
456
457    # Description of argument(s):
458    # file_name    Partition file name.
459    # file_size    By Default is set to EMPTY,
460    #              if user pass small_file_size the create file with small
461    #              size keyword gets executed.
462
463    @{Partition_file_list} =  Split String  ${file_name}  ,
464    ${num_records}=  Get Length  ${Partition_file_list}
465
466    Create Partition File  ${Partition_file_list}
467
468    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
469    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
470    Run Keyword If  ${num_records} == ${1}
471    ...    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
472    ...  ELSE
473    ...    Delete All BMC Partition File  ${HTTP_OK}
474    Delete Local Partition File  ${Partition_file_list}
475
476
477Redfish Fail To Upload Partition File
478    [Documentation]  Fail to upload the partition file.
479    [Arguments]  ${file_name}  ${status_code}  ${partition_status}  ${response_message}=${EMPTY}
480
481    # Description of argument(s):
482    # file_name           Partition file name.
483    # status_code         HTTPS status code.
484    # partition_status    Partition status.
485    # response_message    By default is set to EMPTY,
486    #                     else user provide the information when user upload the partition with file size
487    #                     below lower linit of allowed partition or more than of large allowed partition.
488
489    @{Partition_file_list} =  Split String  ${file_name}  ,
490
491    Create Partition File  ${Partition_file_list}
492    Upload Partition File To BMC  ${Partition_file_list}  ${status_code}  ${response_message}
493    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=${partition_status}
494
495    Run Keyword If  ${partition_status} == 0
496    ...  Run Keywords
497    ...  Delete BMC Partition File
498    ...  ${Partition_file_list}  ${HTTP_NOT_FOUND}  ${RESOURCE_NOT_FOUND_MESSAGE}  AND
499    ...  Delete All BMC Partition File  ${HTTP_OK}  AND
500    ...  Delete Local Server Partition File
501
502    Delete Local Partition File  ${Partition_file_list}
503
504
505Redfish Upload Partition File In Loop
506    [Documentation]  Upload the same partition file multiple times in loop to BMC.
507    [Arguments]  ${file_name}
508
509    # Description of argument(s):
510    # file_name    Partition file name.
511
512    @{Partition_file_list} =  Split String  ${file_name}  ,
513    Create Partition File  ${Partition_file_list}
514
515    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
516    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
517
518    FOR  ${count}  IN RANGE  1  11
519      Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPDATED_MESSAGE}
520      Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
521    END
522
523    Initialize OpenBMC
524    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
525    Delete Local Partition File  ${Partition_file_list}
526
527
528Redfish Upload And Delete Partition File In Loop
529    [Documentation]  Upload the same partition file multiple times in loop to BMC.
530    [Arguments]  ${file_name}
531
532    # Description of argument(s):
533    # file_name    Partition file name.
534
535    FOR  ${count}  IN RANGE  1  11
536      Redfish Upload Partition File  ${file_name}
537    END
538
539
540Verify Partition File Upload Post BMC Reboot
541    [Documentation]  Upload the partition file, after BMC reboot.
542    [Arguments]  ${file_name}
543
544    # Description of argument(s):
545    # file_name    Partition file name.
546
547    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
548    Redfish BMC Reset Operation
549    Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}
550
551    Is BMC Standby
552
553    Redfish Upload Partition File  ${file_name}
554
555
556Redfish Partition File Persistency
557    [Documentation]  Upload the partition file and check for persistency after reboot.
558    [Arguments]  ${file_name}
559
560    # Description of argument(s):
561    # file_name    Partition file name.
562
563    @{Partition_file_list} =  Split String  ${file_name}  ,
564    ${num_records}=  Get Length  ${Partition_file_list}
565    Create Partition File  ${Partition_file_list}
566    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
567    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
568
569    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
570    Redfish BMC Reset Operation
571    Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}
572
573    Is BMC Standby
574
575    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
576    Initialize OpenBMC
577    Run Keyword If  ${num_records} == ${1}
578    ...    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
579    ...  ELSE
580    ...    Delete All BMC Partition File  ${HTTP_OK}
581    Delete Local Partition File  ${Partition_file_list}
582
583
584Verify Redfish Partition File Content
585    [Documentation]  Verify partition file content.
586    [Arguments]  ${file_name}  ${content_dict}  ${status_code}
587
588    # Description of argument(s):
589    # file_name       Partition file name.
590    # content_dict    Dict contain the content.
591    # status_code     HTTPS status code.
592
593    FOR  ${conf_file}  IN  @{file_name}
594      ${resp}=  Get Request  openbmc  /ibm/v1/Host/ConfigFiles/${conf_file}
595      Should Be Equal As Strings  ${resp.status_code}  ${status_code}
596
597      ${Partition_file_data}=  Remove String  ${resp.text}  \\n
598      ${Partition_file_data}=  Evaluate  json.loads('''${Partition_file_data}''')  json
599      Should Be Equal As Strings  ${Partition_file_data["Data"]}  ${content_dict['${conf_file}']}
600    END
601
602
603Add Content To Files
604    [Documentation]  Add defined content in partition file.
605    [Arguments]  ${file_name}  ${index}=${0}
606
607    # Description of argument(s):
608    # file_name    Partition file name.
609    # index        Index
610
611    ${num_records}=  Get Length  ${file_name}
612    &{content_dict}=  Create Dictionary
613
614    FOR  ${conf_file}  IN  @{file_name}
615       ${index}=  Get Index From List  ${file_name}  ${conf_file}
616       ${index}=  Evaluate  ${index} + 1
617
618       Run  echo "${content-${index}}" > ${conf_file}
619       OperatingSystem.File Should Exist  ${conf_file}
620
621       Set To Dictionary  ${content_dict}  ${conf_file}  ${content-${index}}
622    END
623
624    [Return]  &{content_dict}
625
626
627Redfish Read Partition File
628    [Documentation]  Read partition file content.
629    [Arguments]  ${file_name}  ${reboot_flag}=False
630
631    # Description of argument(s):
632    # file_name      Partition file name.
633    # reboot_flag    Reboot flag.
634
635    @{Partition_file_list} =  Split String  ${file_name}  ,
636    ${content_dict}=  Add Content To Files  ${Partition_file_list}
637
638    ${num_records}=  Get Length  ${Partition_file_list}
639
640    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
641    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
642    Verify Redfish Partition File Content  ${Partition_file_list}  ${content_dict}  ${HTTP_OK}
643
644    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
645
646    Run Keyword If  ${True} == ${reboot_flag}
647    ...  Run Keywords  Redfish BMC Reset Operation  AND
648    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
649    ...  Is BMC Standby  AND
650    ...  Initialize OpenBMC  AND
651    ...  Verify Redfish Partition File Content  ${Partition_file_list}  ${content_dict}  ${HTTP_OK}
652
653    Run Keyword If  ${num_records} == ${1}
654    ...    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
655    ...  ELSE
656    ...    Delete All BMC Partition File  ${HTTP_OK}
657
658    Delete Local Partition File  ${Partition_file_list}
659
660
661Redfish Update Partition File With Same Content
662    [Documentation]  Update partition file with same content.
663    [Arguments]  ${file_name}  ${reboot_flag}=False
664
665    # Description of argument(s):
666    # file_name      Partition file name.
667    # reboot_flag    Reboot flag.
668
669    @{Partition_file_list} =  Split String  ${file_name}  ,
670    ${content_dict}=  Add Content To Files  ${Partition_file_list}  ${0}
671
672    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
673    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
674    Verify Redfish Partition File Content  ${Partition_file_list}  ${content_dict}  ${HTTP_OK}
675
676    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
677
678    Run Keyword If  ${True} == ${reboot_flag}
679    ...  Run Keywords  Redfish BMC Reset Operation  AND
680    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
681    ...  Is BMC Standby  AND
682    ...  Initialize OpenBMC
683
684    ${content_dict}=  Add Content To Files  ${Partition_file_list}  ${0}
685    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPDATED_MESSAGE}
686    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
687    Verify Redfish Partition File Content  ${Partition_file_list}  ${content_dict}  ${HTTP_OK}
688
689    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
690    Delete Local Partition File  ${Partition_file_list}
691
692
693Redfish Update Partition File With Different Content
694    [Documentation]  Update partition file with different content.
695    [Arguments]  ${file_name}  ${reboot_flag}=False
696
697    # Description of argument(s):
698    # file_name      Partition file name.
699    # reboot_flag    Reboot flag.
700
701    @{Partition_file_list} =  Split String  ${file_name}  ,
702    ${content_dict}=  Add Content To Files  ${Partition_file_list}  ${0}
703
704    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
705    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
706    Verify Redfish Partition File Content  ${Partition_file_list}  ${content_dict}  ${HTTP_OK}
707
708    ${before_reboot_xauth_token}=  Set Variable  ${XAUTH_TOKEN}
709
710    Run Keyword If  ${True} == ${reboot_flag}
711    ...  Run Keywords  Redfish BMC Reset Operation  AND
712    ...  Set Global Variable  ${XAUTH_TOKEN}  ${before_reboot_xauth_token}  AND
713    ...  Is BMC Standby  AND
714    ...  Initialize OpenBMC
715
716    ${content_dict}=  Add Content To Files  ${Partition_file_list}  ${1}
717    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPDATED_MESSAGE}
718    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
719    Verify Redfish Partition File Content  ${Partition_file_list}  ${content_dict}  ${HTTP_OK}
720
721    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
722    Delete Local Partition File  ${Partition_file_list}
723
724
725Create File Names
726    [Documentation]  Create partition file names.
727    [Arguments]  ${range}
728
729    # Description of argument(s):
730    # range    Range in numbers.
731
732    @{file_name_list}=  Create List
733    Set Test Variable  ${file_name}  rangefile
734    FOR  ${count}  IN RANGE  ${range}
735      Append To List  ${file_name_list}  1KB-file${count}
736    END
737    [Return]  ${file_name_list}
738
739
740Redfish Upload Partition File With Range
741    [Documentation]  Upload the partition file with the range of files.
742    [Arguments]  ${range}
743
744    # Description of argument(s):
745    # range    Range in numbers.
746
747    ${Partition_file_list}=  Create File Names  ${range}
748    Delete Local Partition File  ${Partition_file_list}
749    Create Partition File  ${Partition_file_list}
750    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_OK}  ${FILE_UPLOAD_MESSAGE}
751    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
752    Delete All BMC Partition File  ${HTTP_OK}
753    Delete Local Partition File  ${Partition_file_list}
754
755
756Redfish Delete Non Existence Partition File
757    [Documentation]  Delete the partition file if do not exists.
758    [Arguments]  ${file_name}
759
760    # Description of argument(s):
761    # file_name    Partition file name.
762
763    @{Partition_file_list} =  Split String  ${file_name}  ,
764    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_NOT_FOUND}  ${RESOURCE_NOT_FOUND_MESSAGE}
765
766
767Non Admin User To Upload Partition File
768    [Documentation]  Non admin user to upload the partition file.
769    [Arguments]  ${file_name}  ${username}  ${password}  ${role}  ${enabled}=${True}
770
771    # Description of argument(s):
772    # file_name    Partition file name.
773    # username     Username.
774    # password     Password.
775    # role         Role of user.
776    # enabled      Value can be True or False.
777
778    Redfish Create User  ${username}  ${password}  ${role}  ${enabled}
779    Delete All Sessions
780    Initialize OpenBMC  rest_username=${username}  rest_password=${password}
781    @{Partition_file_list} =  Split String  ${file_name}  ,
782    Create Partition File  ${Partition_file_list}
783    Upload Partition File To BMC  ${Partition_file_list}  ${HTTP_FORBIDDEN}  ${FORBIDDEN_MESSAGE}  ${False}
784    Delete Local Partition File  ${Partition_file_list}
785    Redfish.Delete  /redfish/v1/AccountService/Accounts/${username}
786
787
788Non Admin Delete Non Existence Partition File
789    [Documentation]  Non admin user to upload the partition file.
790    [Arguments]  ${file_name}  ${username}  ${password}  ${role}  ${enabled}=${True}
791
792    # Description of argument(s):
793    # file_name    Partition file name.
794    # username     Username.
795    # password     Password.
796    # role         Role of user.
797    # enabled      Value can be True or False.
798
799    Redfish Create User  ${username}  ${password}  ${role}  ${enabled}
800    Delete All Sessions
801    Initialize OpenBMC  rest_username=${username}  rest_password=${password}
802    @{Partition_file_list} =  Split String  ${file_name}  ,
803    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_FORBIDDEN}  ${FORBIDDEN_MESSAGE}
804
805
806Verify Update Wrong Partition File To BMC
807    [Documentation]  Upload the wrong partition file to BMC.
808    [Arguments]  ${file_name}
809
810    # Description of argument(s):
811    # file_name    Partition file name.
812
813    Redfish.Login
814    ${resp}=  Run Keyword And Return Status
815    ...  Redfish.Put  /ibm/v1/Host/ConfigFiles/../../../../../etc/resolv.conf  body={"data": "test string"}
816    Should Be Equal As Strings  ${resp}  False
817
818
819Check Redfish Upload Partition File Name With Character Limit To BMC
820    [Documentation]  Upload the partition file to BMC with file name character limit.
821    [Arguments]  ${file_name}  ${status_code}  ${message}
822
823    # Description of argument(s):
824    # file_name       Partition file name.
825    # status_code     HTTPS status code.
826    # message         Expected message of from upload partition file URI.
827
828    @{Partition_file_list} =  Split String  ${file_name}  ,
829    ${num_records}=  Get Length  ${Partition_file_list}
830    Create Partition File  ${Partition_file_list}
831
832    ${file_name_length}=  Get Length  ${Partition_file_list}[0]
833
834    Run Keyword If  ${file_name_length} == 20
835    ...  Run Keywords
836    ...    Upload Partition File To BMC  ${Partition_file_list}  ${status_code}  ${message}  AND
837    ...    Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1  AND
838    ...    Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
839    ...  ELSE
840    ...    Upload Partition File To BMC  ${Partition_file_list}  ${status_code}  ${message}
841
842    Delete Local Partition File  ${Partition_file_list}
843
844
845Check Redfish Fail To Upload Partition File Name With Special Character To BMC
846    [Documentation]  Upload the partition file to BMC with special character file name.
847    [Arguments]  ${file_name}  ${status_code}  ${message}
848
849    # Description of argument(s):
850    # file_name       Partition file name.
851    # status_code     HTTPS status code.
852    # message         Expected message from upload partition file URI.
853
854    @{Partition_file_list} =  Split String  ${file_name}  ,
855    ${num_records}=  Get Length  ${Partition_file_list}
856
857    Create Partition File  ${Partition_file_list}
858
859    Upload Partition File To BMC  ${Partition_file_list}  ${status_code}  ${message}
860
861    ${status}=  Run Keyword And Return Status
862    ...  Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
863    Should Be Equal As Strings  ${status}  False
864
865    Delete Local Partition File  ${Partition_file_list}
866
867
868Redfish Upload Partition File From Path
869    [Documentation]  Upload the partition file to BMC from file path.
870    [Arguments]  ${PARTITION_FILE_PATH}
871
872    # Description of argument(s):
873    # PARTITION_FILE_PATH    Partition file path.
874
875    ${file_list} =  OperatingSystem.List Files In Directory  ${PARTITION_FILE_PATH}
876
877    ${num_records}=  Get Length  ${file_list}
878    Should Not Be Equal As Integers  ${num_records}  0
879
880    FOR  ${file_name}  IN  @{file_list}
881      @{Partition_file_list} =  Split String  ${file_name}  ,
882      ${num_records}=  Get Length  ${Partition_file_list}
883      Upload Partition File To BMC  file_name=${Partition_file_list}  status_code=${HTTP_OK}  expected_message=${FILE_UPLOAD_MESSAGE}  path=${PARTITION_FILE_PATH}
884      Verify Partition File On BMC  ${Partition_file_list}  Partition_status=1
885      Delete BMC Partition File  ${Partition_file_list}  ${HTTP_OK}  ${FILE_DELETED_MESSAGE}
886    END
887
888