Added test case for setting PNOR images to the same priority

Resolves openbmc/openbmc-test-automation#913

Change-Id: Id8f83f10a73f0639d843d369d100dcf0abb393b2
Signed-off-by: Charles Paul Hofer <Charles.Hofer@ibm.com>
diff --git a/extended/code_update/host_code_update.robot b/extended/code_update/host_code_update.robot
index 799e38f..0fd9e5b 100644
--- a/extended/code_update/host_code_update.robot
+++ b/extended/code_update/host_code_update.robot
@@ -3,7 +3,9 @@
 ...               Execution Method:
 ...               python -m robot -v OPENBMC_HOST:<hostname>
 ...               -v DELETE_OLD_PNOR_IMAGES:<"true" or "false">
-...               -v IMAGE_FILE_PATH:<path/*.tar>  host_code_update.robot
+...               -v IMAGE_FILE_PATH:<path/*.tar>
+...               -v ALTERNATE_IMAGE_FILE_PATH:<path/*.tar>
+...               host_code_update.robot
 ...
 ...               Code update method BMC
 ...               Update work flow sequence:
@@ -108,6 +110,16 @@
     ${ALTERNATE_IMAGE_FILE_PATH}   ${VERSION_PURPOSE_HOST}
 
 
+Set Same Priority For Multiple Host Images
+    [Documentation]  Attempt to set the priority to be the same for two PNOR
+    ...              images and verify that the priorities are not the same.
+    [Tags]  Set_Same_Priority_For_Multiple_Host_Images
+
+    Run Keyword If  '${PREV_TEST_STATUS}' == 'FAIL'
+    ...  Fail  Activation of alternate image failed. Cannot set priority.
+    Set Same Priority For Multiple Images  ${VERSION_PURPOSE_HOST}
+
+
 Delete Host Image
     [Documentation]  Delete a PNOR image from the BMC and PNOR flash chip.
     [Tags]  Delete_Host_Image
diff --git a/lib/code_update_utils.py b/lib/code_update_utils.py
index 88836d6..dd1cdc3 100644
--- a/lib/code_update_utils.py
+++ b/lib/code_update_utils.py
@@ -42,7 +42,7 @@
         if image_priority in taken_priorities:
             BuiltIn().fail("Found active images with the same priority.\n"
                     + gp.sprint_vars(image, taken_priorities[image_priority]))
-            taken_priorities[image_priority] = image
+        taken_priorities[image_priority] = image
 
 ###############################################################################
 
diff --git a/lib/code_update_utils.robot b/lib/code_update_utils.robot
index 03c6d3f..77b0892 100644
--- a/lib/code_update_utils.robot
+++ b/lib/code_update_utils.robot
@@ -144,6 +144,33 @@
     Verify No Duplicate Image Priorities  ${image_purpose}
 
 
+Set Same Priority For Multiple Images
+    [Documentation]  Find two images, set the priorities to be the same, and
+    ...              verify that the priorities are not the same.
+    [Arguments]  ${version_purpose}
+
+    # Description of argument(s):
+    # version_purpose  Either BMC or host version purpose.
+    #                  (e.g. "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
+    #                        "xyz.openbmc_project.Software.Version.VersionPurpose.Host").
+
+    # Make sure we have more than two images.
+    ${software_objects}=  Get Software Objects  version_type=${version_purpose}
+    ${num_images}=  Get Length  ${software_objects}
+    Should Be True  1 < ${num_images}
+    ...  msg=Only found one image on the BMC with purpose ${version_purpose}.
+
+    # Set the priority of the second image to the priority of the first.
+    ${properties}=  Get Host Software Property  @{software_objects}[0]
+    Set Host Software Property  @{software_objects}[1]  Priority
+    ...  &{properties}[Priority]
+    Verify No Duplicate Image Priorities  ${version_purpose}
+
+    # Set the priority of the first image back to what it was before
+    Set Host Software Property  @{software_objects}[0]  Priority
+    ...  &{properties}[Priority]
+
+
 Delete Software Object
     [Documentation]  Deletes an image from the BMC.
     [Arguments]  ${software_object}