Moved code update keywords to lib
Change-Id: Ia9875b0b9545cd940a81e1a511ae7456cf6ac681
Signed-off-by: Charles Paul Hofer <Charles.Hofer@ibm.com>
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}" ]