Redfish code update changes
Changes:
- Added task state in json file
data/task_state.json
- Added Keyword Create List Of Task,
Create Initiated Task State Dict,
Match Target URI,
Check Task With Match TargetUri,
Verify Task Progress State
- Added Keyword Get Task State From File
Tested:
Ran succesfully redfish/
update_service/test_redfish_bmc_code_update.robot
Change-Id: Iba2131925cb60614f456cbf5ec91b1b02bddc06b
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/data/task_state.json b/data/task_state.json
new file mode 100644
index 0000000..dd4c60f
--- /dev/null
+++ b/data/task_state.json
@@ -0,0 +1,15 @@
+{
+ "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"
+ }
+}
diff --git a/lib/redfish_code_update_utils.robot b/lib/redfish_code_update_utils.robot
index 17ffbe0..5210c9b 100644
--- a/lib/redfish_code_update_utils.robot
+++ b/lib/redfish_code_update_utils.robot
@@ -284,3 +284,101 @@
Redfish.Patch /redfish/v1/Managers/bmc
... body={'Links': {'ActiveSoftwareImage': {'@odata.id': '${firmware_inv_path}'}}}
+
+Create List Of Task
+ [Documentation] Return list of task id(s) from provided list of dictionary.
+ [Arguments] ${task_dict_list}
+
+ # Description of argument(s):
+ # task_dict_list Task id dictionary list.
+
+ # '@odata.id': '/redfish/v1/TaskService/Tasks/0'
+
+ ${task_list}= Create List
+
+ FOR ${task_dict} IN @{task_dict_list}
+ Append To List ${task_list} ${task_dict['@odata.id']}
+ END
+
+ [Return] ${task_list}
+
+
+Create Initiated Task State Dict
+ [Documentation] Create active task inventory dictionary as certain URI create task
+ ... to serve the user request.
+ [Arguments] ${task_obj}
+
+ # Description of argument(s):
+ # task_obj Task dictionary.
+
+ # task_inv
+ # TargetUri /redfish/v1/UpdateService
+ # TaskIdURI /redfish/v1/TaskService/Tasks/0
+ # TaskState Starting
+ # TaskStatus OK
+
+ ${task_inv}= Create Dictionary
+ Set To Dictionary ${task_inv} TargetUri ${task_obj['Payload']['TargetUri']}
+ Set To Dictionary ${task_inv} TaskIdURI ${task_obj['@odata.id']}
+ Set To Dictionary ${task_inv} TaskState ${task_obj['TaskState']}
+ Set To Dictionary ${task_inv} TaskStatus ${task_obj['TaskStatus']}
+
+ [Return] ${task_inv}
+
+
+Match Target URI
+ [Documentation] Match target uri from task list.
+ [Arguments] ${task_list} ${target_uri}
+
+ # Description of argument(s):
+ # task_list Task id list.
+ # target_uri Task created for target URI.
+
+ # target_uri /redfish/v1/UpdateService
+
+ FOR ${task_id} IN @{task_list}
+ ${task_payload}= Redfish.Get Properties ${task_id}
+ Run Keyword And Return If '${task_payload['Payload']['TargetUri']}' == '${target_uri}' Create Initiated Task State Dict ${task_payload}
+ END
+
+
+Check Task With Match TargetUri
+ [Documentation] Create task state dictionary.
+ [Arguments] ${target_uri}=/redfish/v1/TaskService/Tasks
+
+ # Description of argument(s):
+ # target_uri Target URI for which task is initiated.
+
+ ${task_dict_list}= Redfish.Get Attribute /redfish/v1/TaskService/Tasks Members
+
+ ${task_list}= Create List Of Task ${task_dict_list}
+
+ ${task_inv}= Match Target URI ${task_list} ${target_uri}
+
+ [Return] ${task_inv}
+
+
+Verify Task Progress State
+ [Documentation] Verify task progress matches the user expected task state.
+ [Arguments] ${task_inv} ${task_state}
+
+ # Description of argument(s):
+ # task_inv Initiated task inventory dict information.
+ # task_state Expected task state, user reference from data/task_state.json.
+
+ # task_inv
+ # TaskIdURI /redfish/v1/TaskService/Tasks/0
+ # TaskState Starting
+ # TaskStatus OK
+
+ ${task_payload}= Redfish.Get Properties ${task_inv['TaskIdURI']}
+
+ ${temp_task_inv}= Create Dictionary
+ Set To Dictionary ${temp_task_inv} TaskState ${task_payload['TaskState']}
+ Set To Dictionary ${temp_task_inv} TaskStatus ${task_payload['TaskStatus']}
+
+ Rprint Vars temp_task_inv
+
+ Should Be Equal As Strings ${task_state['TaskState']} ${task_payload['TaskState']}
+ Should Be Equal As Strings ${task_state['TaskStatus']} ${task_payload['TaskStatus']}
+
diff --git a/lib/utils.robot b/lib/utils.robot
index 1032514..a306dc5 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -832,6 +832,35 @@
[Return] ${post_code_update_actions}
+Get Task State From File
+ [Documentation] Get task states from pre-define data/task_state.json file.
+
+ # Example: Task state JSON format.
+ #
+ # {
+ # "TaskRunning": {
+ # "TaskState": "Running",
+ # "TaskStatus": "OK"
+ # },
+ # "TaskCompleted": {
+ # "TaskState": "Completed",
+ # "TaskStatus": "OK"
+ # },
+ # "TaskException": {
+ # "TaskState": "Exception",
+ # "TaskStatus": "Warning"
+ # }
+ # }
+
+ # Python module: get_code_base_dir_path()
+ ${code_base_dir_path}= Get Code Base Dir Path
+ ${task_state}= Evaluate
+ ... json.load(open('${code_base_dir_path}data/task_state.json')) modules=json
+ Rprint Vars task_state
+
+ [Return] ${task_state}
+
+
Redfish Set Boot Default
[Documentation] Set and Verify Boot source override
[Arguments] ${override_enabled} ${override_target} ${override_mode}=UEFI
diff --git a/redfish/update_service/test_redfish_bmc_code_update.robot b/redfish/update_service/test_redfish_bmc_code_update.robot
index 34e39d7..ef3da4e 100644
--- a/redfish/update_service/test_redfish_bmc_code_update.robot
+++ b/redfish/update_service/test_redfish_bmc_code_update.robot
@@ -122,7 +122,22 @@
${state}= Get Pre Reboot State
Rprint Vars state
Set ApplyTime policy=${apply_Time}
- Redfish Upload Image And Check Progress State
+
+ ${task_inv_dict}= Get Task State from File
+
+ ${file_bin_data}= OperatingSystem.Get Binary File ${image_file_path}
+
+ Log To Console Start uploading image to BMC.
+ Upload Image To BMC ${REDFISH_BASE_URI}UpdateService timeout=${600} data=${file_bin_data}
+ Log To Console Completed image upload to BMC.
+
+ ${task_inv}= Check Task With Match TargetUri /redfish/v1/UpdateService
+
+ Rprint Vars task_inv
+
+ Wait Until Keyword Succeeds 5 min 10 sec
+ ... Verify Task Progress State ${task_inv} ${task_inv_dict['TaskCompleted']}
+
Run Key ${post_code_update_actions['BMC image']['${apply_time}']}
Redfish.Login
Redfish Verify BMC Version ${IMAGE_FILE_PATH}