Redfish code update lab/ci usecases
Change-Id: I4b45ed9270776ba782b4d970cb8fb9df33bc8635
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 ad091f8..ff0580f 100644
--- a/lib/redfish_code_update_utils.robot
+++ b/lib/redfish_code_update_utils.robot
@@ -3,6 +3,7 @@
Library code_update_utils.py
Library gen_robot_valid.py
+Library tftp_update_utils.py
Resource bmc_redfish_utils.robot
*** Keywords ***
@@ -99,3 +100,50 @@
# Return the first list entry.
[Return] ${software_inventory}[0]
+
+
+Redfish Upload Image And Check Progress State
+ [Documentation] Code update with ApplyTime.
+ [Arguments] ${apply_time}
+
+ # Description of argument(s):
+ # policy ApplyTime allowed values (e.g. "OnReset", "Immediate").
+
+ Set ApplyTime policy=${apply_Time}
+ Redfish Upload Image ${REDFISH_BASE_URI}UpdateService ${IMAGE_FILE_PATH}
+
+ ${image_id}= Get Latest Image ID
+ Rprint Vars image_id
+
+ Check Image Update Progress State
+ ... match_state='Disabled', 'Updating' image_id=${image_id}
+
+ # Wait a few seconds to check if the update progress started.
+ Sleep 5s
+ Check Image Update Progress State
+ ... match_state='Updating' image_id=${image_id}
+
+ Wait Until Keyword Succeeds 8 min 20 sec
+ ... Check Image Update Progress State
+ ... match_state='Enabled' image_id=${image_id}
+
+
+Reboot BMC And Verify BMC Image
+ [Documentation] Reboot or wait for BMC standby post reboot and
+ ... verify installed image is functional.
+ [Arguments] ${apply_time} ${start_boot_seconds}
+
+ # Description of argument(s):
+ # policy ApplyTime allowed values
+ # (e.g. "OnReset", "Immediate").
+ # start_boot_seconds See 'Wait For Reboot' for details.
+
+ Run Keyword if 'OnReset' == '${apply_time}'
+ ... Run Keyword
+ ... Redfish OBMC Reboot (off)
+ ... ELSE
+ ... Run Keyword
+ ... Wait For Reboot start_boot_seconds=${start_boot_seconds}
+ Redfish.Login
+ Redfish Verify BMC Version ${IMAGE_FILE_PATH}
+
diff --git a/redfish/extended/redfish_bmc_code_update.robot b/redfish/extended/redfish_bmc_code_update.robot
new file mode 100644
index 0000000..da8caf1
--- /dev/null
+++ b/redfish/extended/redfish_bmc_code_update.robot
@@ -0,0 +1,135 @@
+*** Settings ***
+Documentation Update the BMC code on a target BMC via Redifsh.
+
+# Test Parameters:
+# IMAGE_FILE_PATH The path to the BMC 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/openbmc_ffdc.robot
+Resource ../../lib/common_utils.robot
+Resource ../../lib/code_update_utils.robot
+Resource ../../lib/redfish_code_update_utils.robot
+Resource ../../extended/code_update/update_bmc.robot
+Library ../../lib/gen_robot_valid.py
+Library ../../lib/var_funcs.py
+
+Suite Setup Suite Setup Execution
+Suite Teardown Redfish.Logout
+Test Setup Printn
+Test Teardown FFDC On Test Case Fail
+
+Force Tags BMC_Code_Update
+
+*** Test Cases ***
+
+Redfish BMC Code Update
+ [Documentation] Update the firmware image.
+ [Tags] Redfish_BMC_Code_Update
+
+ ${image_version}= Get Version Tar ${IMAGE_FILE_PATH}
+ Rprint Vars image_version
+
+ Run Keyword If not ${FORCE_UPDATE}
+ ... Activate Existing Firmware ${image_version}
+ Redfish Update Firmware
+
+*** Keywords ***
+
+Suite Setup Execution
+ [Documentation] Do the suite setup.
+
+ Redfish.Login
+
+ # Delete BMC dump and Error logs.
+ Delete All BMC Dump
+ Redfish Purge Event Log
+
+ # Checking for file existence.
+ Valid File Path IMAGE_FILE_PATH
+
+
+Activate Existing Firmware
+ [Documentation] Set fimware image to lower priority.
+ [Arguments] ${image_version}
+
+ # Description of argument(s):
+ # image_version Version of image.
+
+ ${software_inventory_record}= Get Software Inventory State By Version
+ ... ${image_version}
+ ${num_keys}= Get Length ${software_inventory_record}
+
+ Rprint Vars software_inventory_record
+
+ # If no software inventory record was found, there is no existing
+ # firmware for the given version and therefore no action to be taken.
+ Return From Keyword If not ${num_keys}
+
+ # Check if the existing firmware is functional.
+ Pass Execution If ${software_inventory_record['functional']}
+ ... The existing ${image_version} firmware is already functional.
+
+ # If existing firmware is not functional, then set the priority to least.
+ Print Timen The existing ${image_version} firmware is not yet functional.
+ Set BMC Image Priority To Least ${image_version} ${software_inventory_record}
+
+ Pass Execution The existing ${image_version} firmware is now functional.
+
+
+Get Image Priority
+ [Documentation] Get Current Image Priority.
+ [Arguments] ${image_version}
+
+ # Description of argument(s):
+ # image_version The Fimware image version (e.g. ibm-v.x-xx).
+
+ ${software_info}= Read Properties
+ ... ${SOFTWARE_VERSION_URI}/enumerate quiet=1
+ # Get only the record associated with our image_version.
+
+ ${software_info}= Filter Struct
+ ... ${software_info} [('Version', '${image_version}')]
+ # Convert from dict to list.
+ ${software_info}= Get Dictionary Values ${software_info}
+
+ [Return] ${software_info[0]['Priority']}
+
+
+Set BMC Image Priority To Least
+ [Documentation] Set BMC image priority to least value.
+ [Arguments] ${image_version} ${software_inventory}
+
+ # Description of argument(s):
+ # image_version The Fimware image version (e.g. ibm-v.x-xx).
+ # software_inventory Software inventory details.
+
+ ${least_priority}= Get Least Value Priority Image ${VERSION_PURPOSE_BMC}
+ ${cur_priority}= Get Image Priority ${image_version}
+ Rprint Vars least_priority cur_priority
+
+ Return From Keyword If '${least_priority}' == ${cur_priority}
+ Set Host Software Property
+ ... ${SOFTWARE_VERSION_URI}${software_inventory['image_id']}
+ ... Priority ${least_priority}
+
+ # Reboot BMC And Login
+ Redfish OBMC Reboot (off)
+ Redfish.Login
+
+
+Redfish Update Firmware
+ [Documentation] Update the BMC firmware via redfish interface.
+
+ ${state}= Get Pre Reboot State
+ Rprint Vars state
+
+ Redfish Upload Image And Check Progress State Immediate
+ Reboot BMC And Verify BMC Image
+ ... Immediate start_boot_seconds=${state['epoch_seconds']}
+
diff --git a/redfish/update_service/redfish_bmc_code_update.robot b/redfish/update_service/redfish_bmc_code_update.robot
deleted file mode 100644
index d87ba60..0000000
--- a/redfish/update_service/redfish_bmc_code_update.robot
+++ /dev/null
@@ -1,121 +0,0 @@
-*** Settings ***
-Documentation Update firmware on a target BMC via Redifsh.
-
-# Test Parameters:
-# IMAGE_FILE_PATH The path to the BMC 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/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 BMC_Code_Update
-
-*** Variables ***
-${immediate} Immediate
-${onreset} OnReset
-
-*** 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.
-
- Redfish.Login
-
- # Delete BMC dump and Error logs
- Delete All BMC Dump
- Redfish Purge Event Log
-
- # Checking for file existence.
- OperatingSystem.File Should Exist ${IMAGE_FILE_PATH}
-
-
-Redfish Update Firmware
- [Documentation] Code update with ApplyTime and verify installation.
- [Arguments] ${apply_time}
-
- # Description of argument(s):
- # policy ApplyTime allowed values (e.g. "OnReset", "Immediate").
-
- ${state}= Get Pre Reboot State
- Rprint Vars state
-
- Set ApplyTime policy=${apply_time}
-
- Redfish Upload Image ${REDFISH_BASE_URI}UpdateService ${IMAGE_FILE_PATH}
-
- ${image_id}= Get Latest Image ID
- Rprint Vars image_id
-
- Check Image Update Progress State
- ... match_state='Disabled', 'Updating' image_id=${image_id}
-
- # Wait a few seconds to check if the update progress started.
- Sleep 5s
- Check Image Update Progress State
- ... match_state='Updating' image_id=${image_id}
-
- Wait Until Keyword Succeeds 8 min 20 sec
- ... Check Image Update Progress State
- ... match_state='Enabled' image_id=${image_id}
-
- Reboot BMC And Verify BMC Image
- ... ${apply_time} start_boot_seconds=${state['epoch_seconds']}
-
-
-Reboot BMC And Verify BMC Image
- [Documentation] Reboot or wait for BMC standby post reboot and
- ... verify installed image is functional.
- [Arguments] ${apply_time} ${start_boot_seconds}
-
- # Description of argument(s):
- # policy ApplyTime allowed values (e.g. "OnReset", "Immediate").
- # start_boot_seconds See 'Wait For Reboot' for details.
-
- Run Keyword if 'OnReset' == '${apply_time}'
- ... Run Keywords
- ... Redfish OBMC Reboot (off) AND
- ... Redfish.Login AND
- ... Redfish Verify BMC Version ${IMAGE_FILE_PATH}
- ... ELSE
- ... Run Keywords
- ... Wait For Reboot start_boot_seconds=${start_boot_seconds} AND
- ... Redfish.Login AND
- ... Redfish Verify BMC Version ${IMAGE_FILE_PATH}
-