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