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/utils.robot
9
10Suite Setup    Suite Setup Execution
11Test Teardown  Test Teardown Execution
12
13
14*** Variables ***
15
16${MAX_SIZE_UPLOAD_MSG}  File size exceeds 200KB. Maximum allowed size is 200KB
17${FILE_UPLOADED_MSG}    File Created
18
19
20*** Test Cases ***
21
22Verify Small Partition File Upload And Delete
23    [Documentation]  Verify small partition file upload and delete.
24    [Tags]  Verify_Small_Partition_File_Upload_And_Delete
25    [Template]  Upload File To Create Partition Then Delete Partition
26
27    # file_name  size_kb  partition_name  expect_resp_code     expected_msg             delete_partition
28    201KB_file   201      201KB           ${HTTP_BAD_REQUEST}  ${MAX_SIZE_UPLOAD_MSG}   ${True}
29    15KB_file    15       15KB            ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${True}
30    200KB_file   200      200KB           ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${True}
31
32
33Verify Multiple Files Upload
34    [Documentation]  Verify multiple files upload.
35    [Tags]  Verify_Multiple_Files_Upload
36    [Template]  Upload File To Create Partition Then Delete Partition
37
38    # file_name  size_kb  partition_name  expect_resp_code     expected_msg             delete_partition
39    0KB_file     0        0KB             ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${False}
40    10KB_file    10       10KB            ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${False}
41    50KB_file    50       50KB            ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${False}
42    250KB_file   250      250KB           ${HTTP_BAD_REQUEST}  ${MAX_SIZE_UPLOAD_MSG}   ${False}
43    15KB_file    15       15KB            ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${False}
44    199KB_file   199      199KB           ${HTTP_OK}           ${FILE_UPLOADED_MSG}     ${False}
45
46
47Verify Read Partition
48    [Documentation]  Verify read partition.
49    [Tags]  Verify_Read_Partition
50
51    Set Test Variable  ${file_name}  testfile
52    Set Test Variable  ${partition_name}  part_read
53    Set Test Variable  ${content}  Sample Content to test partition file upload
54
55    Run  echo "${content}" > ${file_name}
56    OperatingSystem.File Should Exist  ${file_name}
57
58    Upload File To Create Partition Then Delete Partition  ${file_name}  1  ${partition_name}
59    ...  delete_partition=${False}
60
61    Read Partition And Verify Content  ${partition_name}  ${content}
62
63
64*** Keywords ***
65
66Create Partition File
67    [Documentation]  Create partition file.
68    [Arguments]  ${file_name}=dummyfile  ${size_kb}=15
69
70    # Description of argument(s):
71    # file_name           Name of the test file to be created. Examples:  p1.log, part1.txt etc.
72    # size_kb             Size of the test file to be created in KB, default is 15KB.
73    #                     Example : 15, 200 etc.
74
75    ${file_exist}=  Run Keyword And Return Status  OperatingSystem.File Should Exist  ${file_name}
76    Return From Keyword If  ${file_exist}  ${True}
77
78    # Create a partition file if it does not exist locally.
79    Run  dd if=/dev/zero of=${file_name} bs=1 count=0 seek=${size_kb}KB
80    OperatingSystem.File Should Exist  ${file_name}
81
82
83Upload File To Create Partition Then Delete Partition
84    [Documentation]  Upload file to create partition the delete partition.
85    [Arguments]  ${file_name}=dummyfile  ${size_kb}=15  ${partition_name}=p1  ${expect_resp_code}=${HTTP_OK}
86    ...  ${expected_msg}=File Created  ${delete_partition}=${True}
87
88    # Description of argument(s):
89    # file_name           Name of the test file to be created.
90    # partition_name      Name of the partition on BMC.
91    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
92    # expected_msg        Expected message from file upload, default is 'File Created'.
93    # delete_partition    Partition will be deleted if this is True.
94
95    # Create a partition file.
96    Create Partition File  ${file_name}  ${size_kb}
97
98    # Get the content of the file and upload to BMC.
99    ${image_data}=  OperatingSystem.Get Binary File  ${file_name}
100    ${data}=  Create Dictionary  data  ${image_data}
101    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
102
103    Set To Dictionary  ${data}  headers  ${headers}
104    ${resp}=  Put Request  openbmc  /ibm/v1/Host/ConfigFiles/${partition_name}  &{data}
105    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
106
107    # Upload Success will have a response body as :
108    #           {
109    #             "Description": "File Created"
110    #           }
111    ${message}=  evaluate  json.loads('''${resp.text}''')  json
112    Should Be Equal As Strings  ${message["Description"]}  ${expected_msg}
113
114    # Cleanup local space after upload attempt.
115    Run Keyword And Ignore Error  Delete Local File Created To Upload  ${file_name}
116
117    ${upload_success}=  Set Variable If   ${expect_resp_code} != ${HTTP_OK}  ${False}  ${True}
118    Verify Partition Available On BMC  ${partition_name}  ${upload_success}
119
120    # Delete partition and verify on BMC.
121    Return From Keyword If  ${delete_partition} == ${False}
122    ${del_resp_code}=  Set Variable If  ${expect_resp_code} != ${HTTP_OK}  ${HTTP_NOT_FOUND}  ${HTTP_OK}
123    Delete Partition  ${partition_name}  ${del_resp_code}
124    Verify Partition Available On BMC  ${partition_name}  ${False}
125
126
127Get List Of Partitions
128    [Documentation]  Get list of partitions.
129    [Arguments]  ${expect_resp_code}=${HTTP_OK}
130
131    # Description of argument(s):
132    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
133
134    ${resp}=  Get Request  openbmc  /ibm/v1/Host/ConfigFiles
135    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
136    Return From Keyword If  ${expect_resp_code} != ${HTTP_OK}
137
138    ${resp_json}=  To JSON  ${resp.content}
139    ${partitions_cnt}=  Get Length  ${resp_json['Members']}
140
141    [Return]  ${resp_json['Members']}  ${partitions_cnt}
142
143
144Verify Partition Available On BMC
145    [Documentation]  Verify partition available on BMC.
146    [Arguments]  ${partition_name}=${EMPTY}  ${operation_status}=${True}
147
148    # Description of argument(s):
149    # partition_name    Name of the partition on BMC.
150    # operation_success   Status of the previous operation like upload/delete success or failure.
151    #                     True if operation was a success else False.
152
153
154    ${partitions}  ${partitions_cnt}=  Get List Of Partitions
155    ${rest_response}=  Run Keyword And Return Status  List Should Contain Value  ${partitions}
156    ...  /ibm/v1/Host/ConfigFiles/${partition_name}
157
158    ${status}  ${stderr}  ${rc}=  BMC Execute Command
159    ...  ls -l /var/lib/obmc/bmc-console-mgmt/save-area/${partition_name} | wc -l
160    ${bmc_response}=  Run Keyword And Return Status  Should Be True  ${status} == ${1}
161
162    Run Keyword If  '${partition_name}' == '${EMPTY}'  Run Keywords
163    ...  Should Be Equal  ${rest_response}  ${False}  AND  Should Be Equal  ${bmc_response}  ${False}
164
165    Run Keyword And Return If  '${partition_name}' != '${EMPTY}'  Run Keywords
166    ...  Should Be True  ${rest_response} == ${operation_status}  AND
167    ...  Should Be True  ${bmc_response} == ${operation_status}
168
169
170Delete Partition
171    [Documentation]  Delete partition.
172    [Arguments]  ${partition_name}='${EMPTY}'  ${expect_resp_code}=${HTTP_OK}
173
174    # Description of argument(s):
175    # partition_name      Name of the partition on BMC.
176    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
177
178    ${data}=  Create Dictionary
179    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
180    Set To Dictionary  ${data}  headers  ${headers}
181
182    ${resp}=  Delete Request  openbmc  /ibm/v1/Host/ConfigFiles/${partition_name}  &{data}
183    ${expect_resp_code}=  Set Variable If  '${partition_name}' == '${EMPTY}'
184    ...  ${HTTP_NOT_FOUND}  ${expect_resp_code}
185    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
186
187
188Delete And Verify All Partitions on BMC
189    [Documentation]  Delete and verify all partitions on BMC.
190    [Arguments]  ${expect_resp_code}=${HTTP_OK}
191
192    # Description of argument(s):
193    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
194
195    ${data}=  Create Dictionary
196    ${headers}=  Create Dictionary  X-Auth-Token=${XAUTH_TOKEN}
197    Set To Dictionary  ${data}  headers  ${headers}
198
199    ${resp}=  Post Request  openbmc  /ibm/v1/Host/ConfigFiles/Actions/FileCollection.DeleteAll  &{data}
200    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
201
202    Return From Keyword If  ${expect_resp_code} != ${HTTP_OK}
203    Verify Partition Available On BMC  operation_status=${False}
204
205
206Read Partition And Verify Content
207    [Documentation]  Read partition and verify content.
208    [Arguments]  ${partition_name}=p1  ${content}=${EMPTY}  ${expect_resp_code}=${HTTP_OK}
209
210    # Description of argument(s):
211    # partition_name      Name of the partition on BMC.
212    # content             Content of the partition file uploaded.
213    # expect_resp_code    Expected REST response code, default is ${HTTP_OK}.
214
215    ${resp}=  Get Request  openbmc  /ibm/v1/Host/ConfigFiles/${partition_name}
216    Should Be Equal As Strings  ${resp.status_code}  ${expect_resp_code}
217
218    ${partition_data}=  Remove String  ${resp.text}  \\n
219    ${partition_data}=  Evaluate  json.loads('''${partition_data}''')  json
220    Should Be Equal As Strings  ${partition_data["Data"]}  ${content}
221
222
223Delete Local File Created To Upload
224    [Documentation]  Delete local file created to upload.
225    [Arguments]  ${file_name}
226
227    # Description of argument(s):
228    # file_name       Name of the local file to be deleted.
229
230    Run Keyword And Ignore Error  Run  rm -f ${file_name}
231
232
233Suite Setup Execution
234    [Documentation]  Suite setup execution.
235
236    # Get REST session to BMC.
237    Initialize OpenBMC
238
239
240Test Teardown Execution
241    [Documentation]  Test teardown execution.
242
243    Delete And Verify All Partitions on BMC
244    FFDC On Test Case Fail
245
246