Redfish host code update with apply time

Resolves openbmc/openbmc-test-automation#1922

Change-Id: I13d4b92356d9e1163e899a4cc4ff821c65517708
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
diff --git a/lib/redfish_code_update_utils.robot b/lib/redfish_code_update_utils.robot
index ff0580f..cf0ae51 100644
--- a/lib/redfish_code_update_utils.robot
+++ b/lib/redfish_code_update_utils.robot
@@ -5,6 +5,7 @@
 Library         gen_robot_valid.py
 Library         tftp_update_utils.py
 Resource        bmc_redfish_utils.robot
+Resource        boot_utils.robot
 
 *** Keywords ***
 
@@ -147,3 +148,41 @@
     Redfish.Login
     Redfish Verify BMC Version  ${IMAGE_FILE_PATH}
 
+
+Poweron Host And Verify Host Image
+    [Documentation]  Power on Host and verify installed image is functional.
+
+    Redfish Power On
+    Redfish.Login
+    Redfish Verify Host Version  ${IMAGE_FILE_PATH}
+
+
+Get Host Power State
+    [Documentation]  Get host power state.
+    [Arguments]  ${quiet}=0
+
+    # Description of arguments:
+    # quiet    Indicates whether results should be printed.
+
+    ${state}=  Redfish.Get Attribute
+    ...  ${REDFISH_BASE_URI}Systems/system  PowerState
+    Rqprint Vars  state
+
+    [Return]  ${state}
+
+
+Check Host Power State
+    [Documentation]  Check that the machine's host state matches
+    ...  the caller's required host state.
+    [Arguments]  ${match_state}
+
+    # Description of argument(s):
+    # match_state    The expected state. This may be one or more
+    #                comma-separated values (e.g. "On", "Off").
+    #                If the actual state matches any of the
+    #                states named in this argument,
+    #                this keyword passes.
+
+    ${state}=  Get Host Power State
+    Rvalid Value  state  valid_values=[${match_state}]
+
diff --git a/redfish/update_service/test_redfish_host_code_update.robot b/redfish/update_service/test_redfish_host_code_update.robot
new file mode 100644
index 0000000..d90e2a2
--- /dev/null
+++ b/redfish/update_service/test_redfish_host_code_update.robot
@@ -0,0 +1,72 @@
+*** Settings ***
+Documentation            Update firmware on a target Host via Redifsh.
+
+# Test Parameters:
+# IMAGE_FILE_PATH        The path to the Host image file.
+#
+# Firmware update states:
+#     Enabled            Image is installed and either functional or active.
+#     Disabled           Image installation failed or ready for activation.
+#     Updating           Image installation currently in progress.
+
+Resource                 ../../lib/resource.robot
+Resource                 ../../lib/bmc_redfish_resource.robot
+Resource                 ../../lib/boot_utils.robot
+Resource                 ../../lib/openbmc_ffdc.robot
+Resource                 ../../lib/common_utils.robot
+Resource                 ../../lib/code_update_utils.robot
+Resource                 ../../lib/dump_utils.robot
+Resource                 ../../lib/logging_utils.robot
+Resource                 ../../lib/redfish_code_update_utils.robot
+Library                  ../../lib/gen_robot_valid.py
+Library                  ../../lib/tftp_update_utils.py
+
+Suite Setup              Suite Setup Execution
+Suite Teardown           Redfish.Logout
+Test Setup               Printn
+Test Teardown            FFDC On Test Case Fail
+
+Force Tags               Host_Code_Update
+
+*** Test Cases ***
+
+Redfish Code Update With ApplyTime OnReset
+    [Documentation]  Update the firmaware image with ApplyTime of OnReset.
+    [Tags]  Redfish_Code_Update_With_ApplyTime_OnReset
+    [Template]  Redfish Update Firmware
+
+    # policy
+    OnReset
+
+
+Redfish Code Update With ApplyTime Immediate
+    [Documentation]  Update the firmaware image with ApplyTime of Immediate.
+    [Tags]  Redfish_Code_Update_With_ApplyTime_Immediate
+    [Template]  Redfish Update Firmware
+
+    # policy
+    Immediate
+
+*** Keywords ***
+
+Suite Setup Execution
+    [Documentation]  Do the suite setup.
+
+    Valid File Path  IMAGE_FILE_PATH
+    Redfish.Login
+    Delete All BMC Dump
+    Redfish Purge Event Log
+    Redfish Power Off  stack_mode=skip
+
+
+Redfish Update Firmware
+    [Documentation]  Update the BMC firmware via redfish interface.
+    [Arguments]  ${apply_time}
+
+    # Description of argument(s):
+    # policy     ApplyTime allowed values (e.g. "OnReset", "Immediate").
+
+    Redfish.Login
+    Redfish Upload Image And Check Progress State  ${apply_time}
+    Poweron Host And Verify Host Image
+