Added setup to remove old PNOR images before code update.
Change-Id: I668d44cecf2dd9cc72b0d3d1e938154d27c78781
Signed-off-by: Charles Paul Hofer <Charles.Hofer@ibm.com>
diff --git a/extended/code_update/code_update.py b/extended/code_update/code_update.py
index d4f838a..1569107 100644
--- a/extended/code_update/code_update.py
+++ b/extended/code_update/code_update.py
@@ -25,6 +25,28 @@
###############################################################################
+def delete_all_pnor_images():
+
+ r"""
+ Delete all PNOR images from the BMC.
+ """
+
+ status, images = keyword.run_key("Read Properties "
+ + var.SOFTWARE_VERSION_URI + "enumerate")
+ for image_name in images:
+ image_id = image_name.split('/')[-1]
+ image_purpose = images[image_name]["Purpose"]
+ if var.VERSION_PURPOSE_HOST == image_purpose:
+ # Delete twice, in case the image is in the /tmp/images directory
+ keyword.run_key("Call Method " + var.SOFTWARE_VERSION_URI
+ + image_id + " delete data={\"data\":[]}")
+ keyword.run_key("Call Method " + var.SOFTWARE_VERSION_URI
+ + image_id + " delete data={\"data\":[]}")
+
+###############################################################################
+
+
+###############################################################################
def wait_for_activation_state_change(version_id, initial_state):
r"""
diff --git a/extended/code_update/code_update.robot b/extended/code_update/code_update.robot
index 741c16b..27a274b 100644
--- a/extended/code_update/code_update.robot
+++ b/extended/code_update/code_update.robot
@@ -2,6 +2,7 @@
Documentation Code update to a target BMC.
... Execution Method:
... python -m robot -v OPENBMC_HOST:<hostname>
+... -v DELETE_OLD_PNOR_IMAGES:<"true" or "false">
... -v IMAGE_FILE_PATH:<path/*.tar> code_update.robot
...
... Code update method BMC
@@ -34,12 +35,14 @@
${activation_state} ${EMPTY}
${requested_state} ${EMPTY}
${IMAGE_FILE_PATH} ${EMPTY}
+${DELETE_OLD_PNOR_IMAGES} false
*** Test Cases ***
REST PNOR Code Update
[Documentation] Do a PNOR code update by uploading image on BMC via REST.
[Tags] REST_PNOR_Code_Update
+ [Setup] Code Update Setup
OperatingSystem.File Should Exist ${IMAGE_FILE_PATH}
${IMAGE_VERSION}= Get Version Tar ${IMAGE_FILE_PATH}
@@ -68,6 +71,12 @@
*** Keywords ***
+Code Update Setup
+ [Documentation] Do code update test case setup.
+
+ Run Keyword If 'true' == '${DELETE_OLD_PNOR_IMAGES}'
+ ... Delete All PNOR Images
+
Code Update Teardown
[Documentation] Do code update test case teardown.
diff --git a/lib/resource.txt b/lib/resource.txt
index fa8f66e..74a5fcd 100755
--- a/lib/resource.txt
+++ b/lib/resource.txt
@@ -56,6 +56,10 @@
${BMC_IMAGE_FILE_PATH} ${EMPTY}
${BAD_IMAGES_DIR_PATH} ${EMPTY}
+# The caller must set this to the string "true" in order to delete images. The
+# code is picky.
+${DELETE_OLD_PNOR_IMAGES} false
+
# Caller can specify a value for LAST_KNOWN_GOOD_VERSION to indicate that if
# the machine already has that version on it, the update should be skipped.
${LAST_KNOWN_GOOD_VERSION} ${EMPTY}
diff --git a/tools/generate_argumentfile.sh b/tools/generate_argumentfile.sh
index 7d41fa2..4ca44f0 100755
--- a/tools/generate_argumentfile.sh
+++ b/tools/generate_argumentfile.sh
@@ -29,4 +29,5 @@
echo "--variable PNOR_IMAGE_FILE_PATH:$PNOR_IMAGE_FILE_PATH" >> $ARG_FILE
echo "--variable BMC_IMAGE_FILE_PATH:$BMC_IMAGE_FILE_PATH" >> $ARG_FILE
echo "--variable BAD_IMAGES_DIR_PATH:$BAD_IMAGES_DIR_PATH" >> $ARG_FILE
+echo "--variable DELETE_OLD_PNOR_IMAGES:$DELETE_OLD_PNOR_IMAGES" >> $ARG_FILE
echo "--variable LAST_KNOWN_GOOD_VERSION:$LAST_KNOWN_GOOD_VERSION" >> $ARG_FILE