Moved code update keywords to lib
Change-Id: Ia9875b0b9545cd940a81e1a511ae7456cf6ac681
Signed-off-by: Charles Paul Hofer <Charles.Hofer@ibm.com>
diff --git a/extended/code_update/code_update.robot b/extended/code_update/code_update.robot
index 76eb061..6b6f058 100644
--- a/extended/code_update/code_update.robot
+++ b/extended/code_update/code_update.robot
@@ -15,10 +15,7 @@
... - Verify the new version
Library ../../lib/code_update_utils.py
-Library OperatingSystem
-Library String
Variables ../../data/variables.py
-Resource ../lib/rest_client.robot
Resource ../lib/openbmc_ffdc.robot
Resource ../../lib/code_update_utils.robot
Resource ../../lib/boot_utils.robot
@@ -26,17 +23,12 @@
Resource code_update_utils.robot
Resource ../../lib/state_manager.robot
-Test Teardown Code Update Teardown
+Test Teardown FFDC On Test Case Fail
*** Variables ***
${QUIET} ${1}
-${version_id} ${EMPTY}
${upload_dir_path} /tmp/images/
-${image_version} ${EMPTY}
-${image_purpose} ${EMPTY}
-${activation_state} ${EMPTY}
-${requested_state} ${EMPTY}
${IMAGE_FILE_PATH} ${EMPTY}
${DELETE_OLD_PNOR_IMAGES} false
@@ -47,30 +39,7 @@
[Tags] REST_Host_Code_Update
[Setup] Code Update Setup
- OperatingSystem.File Should Exist ${image_file_path}
- ${image_version}= Get Version Tar ${image_file_path}
-
- ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
- Upload Image To BMC /upload/image data=${image_data}
- ${ret}= Verify Image Upload
- Should Be True ${ret}
-
- # Verify the image is 'READY' to be activated.
- ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
- Should Be Equal As Strings &{software_state}[Activation] ${READY}
-
- # Request the image to be activated.
- ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
- Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
- ... RequestedActivation data=${args}
- ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
- Should Be Equal As Strings &{software_state}[RequestedActivation]
- ... ${REQUESTED_ACTIVE}
-
- # Verify code update was successful and Activation state is Active.
- Wait For Activation State Change ${version_id} ${ACTIVATING}
- ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
- Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
+ Upload And Activate Image ${IMAGE_FILE_PATH}
OBMC Reboot (off)
@@ -182,12 +151,6 @@
... Delete All PNOR Images
-Code Update Teardown
- [Documentation] Do code update test case teardown.
-
- FFDC On Test Case Fail
-
-
Get PNOR Extended Version
[Documentation] Return the PNOR extended version.
[Arguments] ${path}
@@ -199,46 +162,3 @@
${version}= Execute Command On BMC
... "grep \"extended_version=\" " + ${path}
[return] ${version.split(",")}
-
-
-Delete Image And Verify
- [Documentation] Delete an image from the BMC and verify that it was
- ... removed from software and the /tmp/images directory.
- [Arguments] ${software_object} ${version_type}
-
- # Description of argument(s):
- # software_object The URI of the software object to delete.
- # version_type The type of the software object, e.g.
- # xyz.openbmc_project.Software.Version.VersionPurpose.Host
- # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
-
- # Delete the image.
- Delete Software Object ${software_object}
- # TODO: If/when we don't have to delete twice anymore, take this out
- Run Keyword And Ignore Error Delete Software Object ${software_object}
-
- # Verify that it's gone from software.
- ${software_objects}= Get Software Objects version_type=${version_type}
- Should Not Contain ${software_objects} ${software_object}
-
- # Check that there is no file in the /tmp/images directory.
- ${image_id}= Fetch From Right ${software_object} /
- BMC Execute Command
- ... [ ! -d "/tmp/images/${image_id}" ]
-
-
-Set Property To Invalid Value And Verify No Change
- [Documentation] Attempt to set a property and check that the value didn't
- ... change.
- [Arguments] ${property}
-
- # Description of argument(s):
- # property The property to attempt to set.
-
- ${sw_objs}= Get Software Objects
- ${prev_props}= Get Host Software Property @{sw_objs}[0]
- Run Keyword And Expect Error 500 != 200
- ... Set Host Software Property @{sw_objs}[0] ${property} foo
- ${cur_props}= Get Host Software Property @{sw_objs}[0]
- Should Be Equal As Strings &{prev_props}[${property}]
- ... &{cur_props}[${property}]
diff --git a/extended/test_uploadimage.robot b/extended/test_uploadimage.robot
index 8aa0595..ade0b0b 100644
--- a/extended/test_uploadimage.robot
+++ b/extended/test_uploadimage.robot
@@ -29,7 +29,6 @@
${timeout} 10
${upload_dir_path} /tmp/images/
${QUIET} ${1}
-${image_version} ${EMPTY}
*** Test Cases ***
@@ -225,7 +224,7 @@
${image_version}= Get Version Tar ${image_file_path}
${image_data}= OperatingSystem.Get Binary File ${image_file_path}
Upload Image To BMC /upload/image data=${image_data}
- ${ret}= Verify Image Upload
+ ${ret} ${version_id}= Verify Image Upload ${image_version}
Should Be True ${ret}
Upload Image Via TFTP And Verify Success
@@ -246,7 +245,7 @@
Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
Sleep 1 minute
${image_version}= Get Image Version From TFTP Server ${image_file_name}
- ${ret}= Verify Image Upload
+ ${ret} ${version_id}= Verify Image Upload ${image_version}
Should Be True ${ret}
Upload Bad Image Via REST And Verify Failure
diff --git a/lib/code_update_utils.py b/lib/code_update_utils.py
index 44a3ea0..c33d360 100644
--- a/lib/code_update_utils.py
+++ b/lib/code_update_utils.py
@@ -213,7 +213,7 @@
###############################################################################
-def verify_image_upload(timeout=3):
+def verify_image_upload(image_version, timeout=3):
r"""
Verify the image was uploaded correctly and that it created
@@ -221,14 +221,13 @@
fails, try again until we reach the timeout.
Description of argument(s):
+ image_version The version from the image's manifest file.
timeout How long, in minutes, to keep trying to find the
image on the BMC. Default is 3 minutes.
"""
- image_version = BuiltIn().get_variable_value("${image_version}")
image_path = get_image_path(image_version)
image_version_id = image_path.split("/")[-2]
- BuiltIn().set_global_variable("${version_id}", image_version_id)
keyword.run_key_u("Open Connection And Log In")
image_purpose = get_image_purpose(image_path + "MANIFEST")
@@ -242,16 +241,16 @@
if ((ret_values == var.READY) or (ret_values == var.INVALID)
or (ret_values == var.ACTIVE)):
- return True
+ return True, image_version_id
else:
time.sleep(30)
# If we exit the for loop, the timeout has been reached
gp.print_var(ret_values)
- return False
+ return False, None
else:
gp.print_var(image_purpose)
- return False
+ return False, None
###############################################################################
diff --git a/lib/code_update_utils.robot b/lib/code_update_utils.robot
index ce1eb85..d336888 100644
--- a/lib/code_update_utils.robot
+++ b/lib/code_update_utils.robot
@@ -1,7 +1,11 @@
*** Settings ***
Documentation BMC and PNOR update utilities keywords.
-Resource ../lib/rest_client.robot
+Library code_update_utils.py
+Library OperatingSystem
+Library String
+Variables ../data/variables.py
+Resource rest_client.robot
*** Keywords ***
@@ -58,6 +62,57 @@
${args}= Create Dictionary data=${data}
Write Attribute ${host_object} ${sw_attribute} data=${args}
+
+Set Property To Invalid Value And Verify No Change
+ [Documentation] Attempt to set a property and check that the value didn't
+ ... change.
+ [Arguments] ${property}
+
+ # Description of argument(s):
+ # property The property to attempt to set.
+
+ ${sw_objs}= Get Software Objects
+ ${prev_props}= Get Host Software Property @{sw_objs}[0]
+ Run Keyword And Expect Error 500 != 200
+ ... Set Host Software Property @{sw_objs}[0] ${property} foo
+ ${cur_props}= Get Host Software Property @{sw_objs}[0]
+ Should Be Equal As Strings &{prev_props}[${property}]
+ ... &{cur_props}[${property}]
+
+
+Upload And Activate Image
+ [Documentation] Uploads an image to the BMC and activates it with REST.
+ [Arguments] ${image_file_path}
+
+ # Description of argument(s):
+ # image_file_path The path to the image tarball to upload and activate.
+
+ OperatingSystem.File Should Exist ${image_file_path}
+ ${image_version}= Get Version Tar ${image_file_path}
+
+ ${image_data}= OperatingSystem.Get Binary File ${image_file_path}
+ Upload Image To BMC /upload/image data=${image_data}
+ ${ret} ${version_id}= Verify Image Upload ${image_version}
+ Should Be True ${ret}
+
+ # Verify the image is 'READY' to be activated.
+ ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
+ Should Be Equal As Strings &{software_state}[Activation] ${READY}
+
+ # Request the image to be activated.
+ ${args}= Create Dictionary data=${REQUESTED_ACTIVE}
+ Write Attribute ${SOFTWARE_VERSION_URI}${version_id}
+ ... RequestedActivation data=${args}
+ ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
+ Should Be Equal As Strings &{software_state}[RequestedActivation]
+ ... ${REQUESTED_ACTIVE}
+
+ # Verify code update was successful and Activation state is Active.
+ Wait For Activation State Change ${version_id} ${ACTIVATING}
+ ${software_state}= Read Properties ${SOFTWARE_VERSION_URI}${version_id}
+ Should Be Equal As Strings &{software_state}[Activation] ${ACTIVE}
+
+
Delete Software Object
[Documentation] Deletes an image from the BMC.
[Arguments] ${software_object}
@@ -70,3 +125,29 @@
${resp}= OpenBMC Post Request ${software_object}/action/delete
... data=${args}
Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
+
+
+Delete Image And Verify
+ [Documentation] Delete an image from the BMC and verify that it was
+ ... removed from software and the /tmp/images directory.
+ [Arguments] ${software_object} ${version_type}
+
+ # Description of argument(s):
+ # software_object The URI of the software object to delete.
+ # version_type The type of the software object, e.g.
+ # xyz.openbmc_project.Software.Version.VersionPurpose.Host
+ # or xyz.openbmc_project.Software.Version.VersionPurpose.BMC.
+
+ # Delete the image.
+ Delete Software Object ${software_object}
+ # TODO: If/when we don't have to delete twice anymore, take this out
+ Run Keyword And Ignore Error Delete Software Object ${software_object}
+
+ # Verify that it's gone from software.
+ ${software_objects}= Get Software Objects version_type=${version_type}
+ Should Not Contain ${software_objects} ${software_object}
+
+ # Check that there is no file in the /tmp/images directory.
+ ${image_id}= Fetch From Right ${software_object} /
+ BMC Execute Command
+ ... [ ! -d "/tmp/images/${image_id}" ]