redfish code update keyword

Resolves  openbmc/openbmc-test-automation#1612

Change-Id: I9b6cea5e0b6b2424ed347ea0e6e44275baeac7c0
Signed-off-by: Sushil Singh <susilsi7@in.ibm.com>
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/code_update_utils.robot b/lib/code_update_utils.robot
index d6c0be6..1207618 100644
--- a/lib/code_update_utils.robot
+++ b/lib/code_update_utils.robot
@@ -5,6 +5,7 @@
 Library     OperatingSystem
 Library     String
 Library     utilities.py
+Library     gen_robot_valid.py
 Variables   ../data/variables.py
 Resource    boot_utils.robot
 Resource    rest_client.robot
@@ -158,6 +159,50 @@
     ...  Set Host Software Property  @{images}[0]  Priority  ${priority}
 
 
+Redfish Upload Image
+    [Documentation]  Upload an image to the BMC via redfish.
+    [Arguments]  ${uri}  ${image_file_path}
+
+    # Description of argument(s):
+    # uri                 URI for uploading image via redfish.
+    # image_file_path     The path to the image tarball.
+
+    ${image_data}=  OperatingSystem.Get Binary File  ${image_file_path}
+
+    Wait Until Keyword Succeeds  3 times  60 sec
+    ...  Upload Image To BMC  ${uri}  data=${image_data}
+
+
+Redfish Verify BMC Version
+    [Documentation]  Verify that the version on the BMC is the same as the
+    ...              version in the given image via Redfish.
+    [Arguments]      ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the image tarball.
+
+    # Extract the version from the image tarball on our local system.
+    ${tar_version}=  Get Version Tar  ${image_file_path}
+    ${bmc_version}=  Redfish Get BMC Version
+
+    Rvalid Value  bmc_version  valid_values=['${tar_version}']
+
+
+Redfish Verify Host Version
+    [Documentation]  Verify that the version of the PNOR image that is on the
+    ...              BMC is the same as the one in the given image via Redfish.
+    [Arguments]      ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the image tarball.
+
+    # Extract the version from the image tarball on our local system.
+    ${tar_version}=  Get Version Tar  ${image_file_path}
+    ${host_version}=  Redfish Get Host Version
+
+    Rvalid Value  host_version  valid_values=['${tar_version}']
+
+
 Upload And Activate Image
     [Documentation]  Upload an image to the BMC and activate it with REST.
     [Arguments]  ${image_file_path}  ${wait}=${1}  ${skip_if_active}=false
diff --git a/lib/common_utils.robot b/lib/common_utils.robot
index bbac89f..e3eae8a 100755
--- a/lib/common_utils.robot
+++ b/lib/common_utils.robot
@@ -851,6 +851,19 @@
     [Return]  ${bmc_version}  ${pnor_version}
 
 
+Redfish Get BMC Version
+    [Documentation]  Get BMC version via Redfish.
+
+    ${output}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}Managers/bmc  FirmwareVersion
+    [Return]  ${output}
+
+Redfish Get Host Version
+    [Documentation]  Get host version via Redfish.
+
+    ${output}=  Redfish.Get Attribute  ${REDFISH_BASE_URI}Systems/system  BiosVersion
+    [Return]  ${output}
+
+
 Copy Address Translation Utils To HOST OS
     [Documentation]  Copy address translation utils to host OS.