1*** Settings *** 2 3Documentation Test task service and tasks URI functionality of OpenBMC. 4 5Library OperatingSystem 6 7Resource ../../lib/resource.robot 8Resource ../../lib/bmc_redfish_resource.robot 9Resource ../../lib/dump_utils.robot 10Resource ../../lib/openbmc_ffdc.robot 11 12Suite Setup Suite Setup Execution 13Suite Teardown Suite Teardown Execution 14Test Teardown FFDC On Test Case Fail 15 16Force Tags Tasks_Service 17 18*** Variables *** 19${TIME_REGEXP_PATTERN} (.+)[\\-|\\+]\\d\\d\\:\\d\\d 20 21*** Test Cases *** 22 23Verify Task Service Attributes 24 [Documentation] Validate attributes and default values in task service URI. 25 [Tags] Verify_Task_Service_Attributes 26 27 # { 28 # "@odata.id": "/redfish/v1/TaskService", 29 # "@odata.type": "#TaskService.v1_1_4.TaskService", 30 # "CompletedTaskOverWritePolicy": "Oldest", 31 # "DateTime": "2022-08-08T06:04:11+00:00", 32 # "Id": "TaskService", 33 # "LifeCycleEventOnTaskStateChange": true, 34 # "Name": "Task Service", 35 # "ServiceEnabled": true, 36 # "Status": { 37 # "Health": "OK", 38 # "HealthRollup": "OK", 39 # "State": "Enabled" 40 # }, 41 # "Tasks": { 42 # "@odata.id": "/redfish/v1/TaskService/Tasks" 43 # } 44 # } 45 46 ${resp}= Redfish.Get Properties /redfish/v1/TaskService 47 48 # Verify CompletedTaskOverWritePolicy is a valid value. 49 Should Be True 50 ... '${resp["CompletedTaskOverWritePolicy"]}' in ${allowed_completed_task_overwrite_policy} 51 52 # Verify service enabled property. 53 Should Be Equal ${resp["ServiceEnabled"]} ${TRUE} 54 55 # Verify status. 56 Dictionaries Should Be Equal ${resp["Status"]} ${valid_status} 57 58 # Get current time from BMC console. 59 ${cur_time}= Get Current Date from BMC 60 61 # Remove offset from task service time. 62 ${bmc_time}= Get Regexp Matches ${resp["DateTime"]} 63 ... ${TIME_REGEXP_PATTERN} 1 64 65 ${time_diff}= Subtract Date From Date ${cur_time} ${bmc_time[0]} 66 ... date1_format=%m/%d/%Y %H:%M:%S date2_format=%Y-%m-%dT%H:%M:%S 67 68 # Compare system time and time displayed in task service URI. 69 ${time_diff}= Evaluate ${time_diff} < 5 70 71 Should Be Equal ${time_diff} ${TRUE} 72 ... Time Difference between BMC time and time displayed in task URI is higher. 73 74 75Test Generated Task Instance Validity And Task State 76 [Documentation] Trigger a Redfish event that generates task instance and 77 ... verify the values of generated task instance. 78 [Tags] Test_Generated_Task_Instance_Validity_And_Task_State 79 80 # { 81 # "@odata.id": "/redfish/v1/TaskService/Tasks/3", 82 # "@odata.type": "#Task.v1_4_3.Task", 83 # "Id": "3", 84 # "Messages": [ 85 # { 86 # "@odata.type": "#Message.v1_0_0.Message", 87 # "Message": "The task with id 3 has started.", 88 # "MessageArgs": [ 89 # "3" 90 # ], 91 # "MessageId": "TaskEvent.1.0.1.TaskStarted", 92 # "Resolution": "None.", 93 # "Severity": "OK" 94 # } 95 # ], 96 # "Name": "Task 3", 97 # "Payload": { 98 # "HttpHeaders": [ 99 # "User-Agent: PostmanRuntime/7.26.8", 100 # "Accept: */*", 101 # "Host: 10.0.123.113", 102 # "Accept-Encoding: gzip, deflate, br", 103 # "Connection: keep-alive", 104 # "Content-Length: 41" 105 # ], 106 # "HttpOperation": "POST", 107 # "JsonBody": "{\n \"DiagnosticDataType\": \"Manager\"\n}", 108 # "TargetUri": "/redfish/v1/Managers/${MANAGER_ID}/LogServices/Dump/Actions 109 # /LogService.CollectDiagnosticData" 110 # }, 111 # "PercentComplete": 0, 112 # "StartTime": "2022-08-09T12:57:06+00:00", 113 # "TaskMonitor": "/redfish/v1/TaskService/Tasks/3/Monitor", 114 # "TaskState": "Running", 115 # "TaskStatus": "OK" 116 # } 117 118 # Trigger a Redfish event that generates task instance. 119 ${task_id} ${resp_obj}= Generate Task Instance 120 121 # Verify task monitor before task completion. 122 ${resp}= Redfish.Get /redfish/v1/TaskService/Tasks/${task_id}/Monitor 123 ... valid_status_codes=[${HTTP_ACCEPTED}] 124 125 # Get current time from BMC console before generating task. 126 ${cur_time}= Get Current Date from BMC 127 128 # Verify task start time is within 10s of current time. 129 ${resp}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id} 130 131 ${start_time}= Get Regexp Matches ${resp["StartTime"]} 132 ... ${TIME_REGEXP_PATTERN} 1 133 134 # Compare system time and time displayed in task service URI. 135 ${time_diff}= Subtract Date From Date ${cur_time} ${start_time[0]} 136 ... date1_format=%m/%d/%Y %H:%M:%S date2_format=%Y-%m-%dT%H:%M:%S 137 138 139 ${time_diff}= Evaluate ${time_diff} < 10 140 Should Be Equal ${time_diff} ${TRUE} Time difference greater than 10 seconds. 141 142 # Verify HttpOperation in task payload. 143 Should Be Equal ${resp["Payload"]["HttpOperation"]} POST 144 145 # Verify TargetUri. 146 Should Be Equal ${resp["Payload"]["TargetUri"]} 147 ... ${resp_obj.request.path} 148 149 Wait For Task Completion ${task_id} ${allowed_task_completion_state} 150 ... check_state=${TRUE} 151 152 # Verify task monitor URI after task completion. 153 ${resp}= Redfish.Get /redfish/v1/TaskService/Tasks/${task_id}/Monitor 154 ... valid_status_codes=[${HTTP_NOT_FOUND}] 155 156 # Verify end time is greater than start time post task completion. 157 ${resp}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id} 158 159 ${end_time}= Get Regexp Matches ${resp["EndTime"]} 160 ... ${TIME_REGEXP_PATTERN} 1 161 162 # Compare start time and end time displayed in task service URI. 163 ${time_diff}= Subtract Date From Date ${end_time[0]} ${start_time[0]} 164 165 ${time_diff}= Evaluate ${time_diff} >= 0 166 167 Should Be Equal ${time_diff} ${TRUE} 168 ... End time not greater than start time. 169 170 171Verify Task Persistency Post BMC Reboot 172 [Documentation] Verify task collection persistency post BMC reboot. 173 [Tags] Verify_Task_Persistency_Post_BMC_Reboot 174 175 Verify Generate Task Instance Completion 176 177 ${initial_task_count}= Redfish.Get Attribute /redfish/v1/TaskService/Tasks 178 ... Members@odata.count 179 180 Redfish BMC Reset Operation reset_type=ForceRestart 181 182 ${current_task_count}= Redfish.Get Attribute /redfish/v1/TaskService/Tasks 183 ... Members@odata.count 184 185 Should Be Equal As Integers ${initial_task_count} ${current_task_count} 186 187 188*** Keywords *** 189 190Suite Setup Execution 191 [Documentation] Do suite setup operation. 192 193 Redfish.login 194 Load Task Service Properties Data 195 196 197Suite Teardown Execution 198 [Documentation] Do suite teardown operation. 199 200 Run Keyword And Ignore Error Redfish.Logout 201 Close All Connections 202 203 204Generate Task Instance 205 [Documentation] Trigger Redfish event to generate task instance 206 ... and return the task id. 207 [Arguments] ${task_type}=bmc_dump 208 209 # Description of argument(s): 210 # task_type Default value for task_type is bmc_dump. When 'task_type' 211 # is 'bmc_dump', then keyword will initiate bmc user dump 212 # creation and will return the task id and response object. 213 214 IF '${task_type}' == 'bmc_dump' 215 ${task_id} ${resp}= Create BMC User Dump 216 ELSE 217 Fail Task type "${task_type}" is unknown. 218 END 219 220 Return From Keyword ${task_id} ${resp} 221 222 223Verify Generate Task Instance Completion 224 [Documentation] Trigger Redfish event to generate task and wait until 225 ... task gets completed. 226 [Arguments] ${task_type}=bmc_dump 227 228 # Description of argument(s): 229 # task_type If 'task_type' set as 'bmc_dump', the keyword will 230 # initiate bmc user dump creation and wait until 231 # task is completed. Default value of task_type 232 # is bmc_dump. 233 234 ${task_id} ${resp}= Generate Task Instance ${task_type} 235 Wait For Task Completion ${task_id} ${allowed_task_completion_state} 236 237 238Load Task Service Properties Data 239 [Documentation] Load the task service related properties from json file. 240 241 # User input -v TASK_JSON_FILE_PATH:<path> else default path. 242 # ${task_json_file}= Get Variable Value ${TASK_JSON_FILE_PATH} data/task_state.json 243 244 ${json}= OperatingSystem.Get File ${TASK_JSON_FILE_PATH} 245 ${properties}= Evaluate json.loads('''${json}''') json 246 247 Set Suite Variable ${allowed_completed_task_overwrite_policy} 248 ... ${properties["TaskService"]["CompletedTaskOverWritePolicy"]["AllowedValues"]} 249 250 Set Suite Variable ${allowed_task_state} 251 ... ${properties["Task"]["TaskState"]["AllowedValues"]} 252 253 Set Suite Variable ${allowed_task_completion_state} 254 ... ${properties["Task"]["TaskState"]["AllowedCompletionTaskState"]} 255 256 Set Suite Variable ${valid_status} 257 ... ${properties["TaskService"]["Status"]} 258 259 260Get Current Date from BMC 261 [Documentation] Runs the date command from BMC and returns current date and time. 262 263 # Get Current Date from BMC 264 ${date} ${stderr} ${rc}= BMC Execute Command date 265 266 # Split the string and remove first and 2nd last value from 267 # the list and join to form %d %b %H:%M:%S %Y date format. 268 269 ${date}= Split String ${date} 270 271 Remove From List ${date} 0 272 Remove From List ${date} -2 273 ${date}= Evaluate " ".join(${date}) 274 275 # Convert the date format to %m/%d/%Y %H:%M:%S 276 ${date}= Convert Date ${date} date_format=%b %d %H:%M:%S %Y result_format=%m/%d/%Y %H:%M:%S exclude_millis=True 277 278 [Return] ${date} 279