Added new test script for validating task service and tasks instance
Added validation for the following cases
- Validate attributes and default values in task service URI
- Trigger a redfish event that generates task instance and
-- Verify task state is valid throughout task lifecycle
-- Verify whether the start & end time for task is valid
-- Verify the task monitor functionality in tasks instance
-- Verify the payload properties in task instance
- Verify task collection persistency after BMC reboot
Tested: Run robot redfish/task_service/test_tasks.robot
Signed-off-by: Aravinth R <aravinthr@ami.com>
Change-Id: If9206e5eb9f624e7642d617664ef7af79bafc603
diff --git a/data/task_state.json b/data/task_state.json
index dd4c60f..14accd3 100644
--- a/data/task_state.json
+++ b/data/task_state.json
@@ -1,15 +1,52 @@
{
- "comment": "This is a generic possible redfish standard task states.",
- "TaskRunning": {
- "TaskState": "Running",
- "TaskStatus": "OK"
+ "comment": "This is a generic possible redfish standard task states.",
+ "TaskRunning": {
+ "TaskState": "Running",
+ "TaskStatus": "OK"
+ },
+ "TaskCompleted": {
+ "TaskState": "Completed",
+ "TaskStatus": "OK"
+ },
+ "TaskException": {
+ "TaskState": "Exception",
+ "TaskStatus": "Warning"
+ },
+ "TaskService": {
+ "CompletedTaskOverWritePolicy": {
+ "AllowedValues": [
+ "Manual",
+ "Oldest"
+ ]
},
- "TaskCompleted": {
- "TaskState": "Completed",
- "TaskStatus": "OK"
- },
- "TaskException": {
- "TaskState": "Exception",
- "TaskStatus": "Warning"
+ "Status": {
+ "Health": "OK",
+ "HealthRollup": "OK",
+ "State": "Enabled"
}
-}
+ },
+ "Task": {
+ "TaskState": {
+ "AllowedValues": [
+ "New",
+ "Starting",
+ "Running",
+ "Suspended",
+ "Interrupted",
+ "Pending",
+ "Stopping",
+ "Completed",
+ "Killed",
+ "Exception",
+ "Service",
+ "Cancelling",
+ "Cancelled"
+ ],
+ "AllowedCompletionTaskState": [
+ "Cancelled",
+ "Completed",
+ "Exception"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/dump_utils.robot b/lib/dump_utils.robot
index 85a88cf..b920efe 100644
--- a/lib/dump_utils.robot
+++ b/lib/dump_utils.robot
@@ -386,3 +386,53 @@
Wait Until Keyword Succeeds 10 min 15 sec Check Task Completion ${task_id}
${dump_id}= Get Dump ID ${task_id}
[Return] ${dump_id} Completed
+
+
+Create BMC User Dump
+ [Documentation] Generate user initiated BMC dump via Redfish and return
+ ... the task instance Id and response object (e.g., "5").
+
+ ${payload}= Create Dictionary DiagnosticDataType=Manager
+ ${resp}= Redfish.Post /redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData
+ ... body=${payload} valid_status_codes=[${HTTP_ACCEPTED}]
+
+ ${ip_resp}= Evaluate json.loads(r'''${resp.text}''') json
+
+ Return From Keyword ${ip_resp["Id"]} ${resp}
+
+
+Wait For Task Completion
+ [Documentation] Check whether the state of task instance matches any of the
+ ... expected completion states before maximum number of retries exceeds and
+ ... exit loop in case completion state is met.
+ [Arguments] ${task_id} ${expected_status} ${retry_max_count}=300
+ ... ${check_state}=${FALSE}
+
+ # Description of argument(s):
+ # task_id the task id for which completion is
+ # to be monitored.
+ # expected_status the task state which is to be considered as the
+ # end of task life cycle.
+ # retry_max_count the maximum number of retry count to wait for
+ # task to reach its completion state. Default
+ # value of retry_max_count is 300.
+ # check_state if set as TRUE, the task state will be
+ # monitored whether the task state value is
+ # valid throughout task life cycle until
+ # expected completion state is reached.
+ # Default value of check_state is FALSE.
+
+ FOR ${retry} IN RANGE ${retry_max_count}
+ ${resp}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id}
+ ${current_task_state}= Set Variable ${resp["TaskState"]}
+ Rprint Vars current_task_state
+
+ Run Keyword If ${check_state} == ${TRUE} Should Be True
+ ... '${resp["TaskState"]}' in ${allowed_task_state}
+ ... msg=Verify task state is valid
+
+ Exit For Loop If
+ ... '${resp["TaskState"]}' in ${expected_status}
+
+ Sleep 5s
+ END
\ No newline at end of file
diff --git a/redfish/task_service/test_tasks.robot b/redfish/task_service/test_tasks.robot
new file mode 100644
index 0000000..9182802
--- /dev/null
+++ b/redfish/task_service/test_tasks.robot
@@ -0,0 +1,253 @@
+*** Settings ***
+
+Documentation Test task service and tasks URI functionality of OpenBMC.
+
+Library OperatingSystem
+
+Resource ../../lib/resource.robot
+Resource ../../lib/bmc_redfish_resource.robot
+Resource ../../lib/dump_utils.robot
+Resource ../../lib/openbmc_ffdc.robot
+
+Suite Setup Suite Setup Execution
+Suite Teardown Suite Teardown Execution
+Test Teardown FFDC On Test Case Fail
+
+
+*** Variables ***
+${TIME_REGEXP_PATTERN} (.+)[\\-|\\+]\\d\\d\\:\\d\\d
+
+
+*** Test Cases ***
+
+Verify Task Service Attributes
+ [Documentation] Validate attributes and default values in task service URI.
+ [Tags] Verify_Task_Service_Attributes
+
+ # {
+ # "@odata.id": "/redfish/v1/TaskService",
+ # "@odata.type": "#TaskService.v1_1_4.TaskService",
+ # "CompletedTaskOverWritePolicy": "Oldest",
+ # "DateTime": "2022-08-08T06:04:11+00:00",
+ # "Id": "TaskService",
+ # "LifeCycleEventOnTaskStateChange": true,
+ # "Name": "Task Service",
+ # "ServiceEnabled": true,
+ # "Status": {
+ # "Health": "OK",
+ # "HealthRollup": "OK",
+ # "State": "Enabled"
+ # },
+ # "Tasks": {
+ # "@odata.id": "/redfish/v1/TaskService/Tasks"
+ # }
+ # }
+
+ ${resp}= Redfish.Get Properties /redfish/v1/TaskService
+
+ # Verify CompletedTaskOverWritePolicy is a valid value.
+ Should Be True
+ ... '${resp["CompletedTaskOverWritePolicy"]}' in ${allowed_completed_task_overwrite_policy}
+
+ # Verify service enabled property.
+ Should Be Equal ${resp["ServiceEnabled"]} ${TRUE}
+
+ # Verify status.
+ Dictionaries Should Be Equal ${resp["Status"]} ${valid_status}
+
+ # Get current time from BMC console.
+ ${cur_time}= Get Current Date from BMC
+
+ # Remove offset from task service time.
+ ${bmc_time}= Get Regexp Matches ${resp["DateTime"]}
+ ... ${TIME_REGEXP_PATTERN} 1
+
+ ${time_diff}= Subtract Date From Date ${cur_time} ${bmc_time[0]}
+ ... date1_format=%m/%d/%Y %H:%M:%S date2_format=%Y-%m-%dT%H:%M:%S
+
+ # Compare system time and time displayed in task service URI.
+ ${time_diff}= Evaluate ${time_diff} < 5
+
+ Should Be Equal ${time_diff} ${TRUE}
+ ... Time Difference between BMC time and time displayed in task URI is higher.
+
+
+Test Generated Task Instance Validity And Task State
+ [Documentation] Trigger a Redfish event that generates task instance and
+ ... verify the values of generated task instance.
+ [Tags] Test_Generated_Task_Instance_Validity_And_Task_State
+
+ # {
+ # "@odata.id": "/redfish/v1/TaskService/Tasks/3",
+ # "@odata.type": "#Task.v1_4_3.Task",
+ # "Id": "3",
+ # "Messages": [
+ # {
+ # "@odata.type": "#Message.v1_0_0.Message",
+ # "Message": "The task with id 3 has started.",
+ # "MessageArgs": [
+ # "3"
+ # ],
+ # "MessageId": "TaskEvent.1.0.1.TaskStarted",
+ # "Resolution": "None.",
+ # "Severity": "OK"
+ # }
+ # ],
+ # "Name": "Task 3",
+ # "Payload": {
+ # "HttpHeaders": [
+ # "User-Agent: PostmanRuntime/7.26.8",
+ # "Accept: */*",
+ # "Host: 10.0.123.113",
+ # "Accept-Encoding: gzip, deflate, br",
+ # "Connection: keep-alive",
+ # "Content-Length: 41"
+ # ],
+ # "HttpOperation": "POST",
+ # "JsonBody": "{\n \"DiagnosticDataType\": \"Manager\"\n}",
+ # "TargetUri": "/redfish/v1/Managers/bmc/LogServices/Dump/Actions
+ # /LogService.CollectDiagnosticData"
+ # },
+ # "PercentComplete": 0,
+ # "StartTime": "2022-08-09T12:57:06+00:00",
+ # "TaskMonitor": "/redfish/v1/TaskService/Tasks/3/Monitor",
+ # "TaskState": "Running",
+ # "TaskStatus": "OK"
+ # }
+
+ # Trigger a Redfish event that generates task instance.
+ ${task_id} ${resp_obj}= Generate Task Instance
+
+ # Verify task monitor before task completion.
+ ${resp}= Redfish.Get /redfish/v1/TaskService/Tasks/${task_id}/Monitor
+ ... valid_status_codes=[${HTTP_ACCEPTED}]
+
+ # Get current time from BMC console before generating task.
+ ${cur_time}= Get Current Date from BMC
+
+ # Verify task start time is within 10s of current time.
+ ${resp}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id}
+
+ ${start_time}= Get Regexp Matches ${resp["StartTime"]}
+ ... ${TIME_REGEXP_PATTERN} 1
+
+ # Compare system time and time displayed in task service URI.
+ ${time_diff}= Subtract Date From Date ${cur_time} ${start_time[0]}
+ ... date1_format=%m/%d/%Y %H:%M:%S date2_format=%Y-%m-%dT%H:%M:%S
+
+ ${time_diff}= Evaluate ${time_diff} < 10
+ Should Be Equal ${time_diff} ${TRUE} Time difference greater than 10 seconds.
+
+ # Verify HttpOperation in task payload.
+ Should Be Equal ${resp["Payload"]["HttpOperation"]} POST
+
+ # Verify TargetUri.
+ Should Be Equal ${resp["Payload"]["TargetUri"]}
+ ... ${resp_obj.request.path}
+
+ Wait For Task Completion ${task_id} ${allowed_task_completion_state}
+ ... check_state=${TRUE}
+
+ # Verify task monitor URI after task completion.
+ ${resp}= Redfish.Get /redfish/v1/TaskService/Tasks/${task_id}/Monitor
+ ... valid_status_codes=[${HTTP_NOT_FOUND}]
+
+ # Verify end time is greater than start time post task completion.
+ ${resp}= Redfish.Get Properties /redfish/v1/TaskService/Tasks/${task_id}
+
+ ${end_time}= Get Regexp Matches ${resp["EndTime"]}
+ ... ${TIME_REGEXP_PATTERN} 1
+
+ # Compare start time and end time displayed in task service URI.
+ ${time_diff}= Subtract Date From Date ${end_time[0]} ${start_time[0]}
+
+ ${time_diff}= Evaluate ${time_diff} >= 0
+
+ Should Be Equal ${time_diff} ${TRUE}
+ ... End time not greater than start time.
+
+
+Verify Task Persistency Post BMC Reboot
+ [Documentation] Verify task collection persistency post BMC reboot.
+ [Tags] Verify_Task_Persistency_Post_BMC_Reboot
+
+ Verify Generate Task Instance Completion
+
+ ${initial_task_count}= Redfish.Get Attribute /redfish/v1/TaskService/Tasks
+ ... Members@odata.count
+
+ Redfish BMC Reset Operation reset_type=ForceRestart
+
+ ${current_task_count}= Redfish.Get Attribute /redfish/v1/TaskService/Tasks
+ ... Members@odata.count
+
+ Should Be Equal As Integers ${initial_task_count} ${current_task_count}
+
+
+*** Keywords ***
+
+Suite Setup Execution
+ [Documentation] Do suite setup operation.
+
+ Redfish.login
+ Load Task Service Properties Data
+
+
+Suite Teardown Execution
+ [Documentation] Do suite teardown operation.
+
+ Run Keyword And Ignore Error Redfish.Logout
+ Close All Connections
+
+
+Generate Task Instance
+ [Documentation] Trigger Redfish event to generate task instance
+ ... and return the task id.
+ [Arguments] ${task_type}=bmc_dump
+
+ # Description of argument(s):
+ # task_type Default value for task_type is bmc_dump. When 'task_type'
+ # is 'bmc_dump', then keyword will initiate bmc user dump
+ # creation and will return the task id and response object.
+
+ IF '${task_type}' == 'bmc_dump'
+ ${task_id} ${resp}= Create BMC User Dump
+ ELSE
+ Fail Task type "${task_type}" is unknown.
+ END
+
+ Return From Keyword ${task_id} ${resp}
+
+
+Verify Generate Task Instance Completion
+ [Documentation] Trigger Redfish event to generate task and wait until
+ ... task gets completed.
+ [Arguments] ${task_type}=bmc_dump
+
+ # Description of argument(s):
+ # task_type If 'task_type' set as 'bmc_dump', the keyword will
+ # initiate bmc user dump creation and wait until
+ # task is completed. Default value of task_type
+ # is bmc_dump.
+
+ ${task_id} ${resp}= Generate Task Instance ${task_type}
+ Wait For Task Completion ${task_id} ${allowed_task_completion_state}
+
+
+Load Task Service Properties Data
+ [Documentation] Load the task service related properties from json file.
+
+ ${json}= OperatingSystem.Get File data/task_state.json
+ ${properties}= Evaluate json.loads('''${json}''') json
+
+ Set Suite Variable ${allowed_completed_task_overwrite_policy}
+ ... ${properties["TaskService"]["CompletedTaskOverWritePolicy"]["AllowedValues"]}
+
+ Set Suite Variable ${allowed_task_state}
+ ... ${properties["Task"]["TaskState"]["AllowedValues"]}
+
+ Set Suite Variable ${allowed_task_completion_state}
+ ... ${properties["Task"]["TaskState"]["AllowedCompletionTaskState"]}
+
+ Set Suite Variable ${valid_status}
+ ... ${properties["TaskService"]["Status"]}
\ No newline at end of file