Add verification for BMC and PNOR image version

Resolves openbmc/openbmc-test-automation#1003

Change-Id: Id455ad78d24401b20f16a41c5ee26b61aeb2677c
Signed-off-by: Charles Paul Hofer <Charles.Hofer@ibm.com>
diff --git a/extended/code_update/bmc_code_update.robot b/extended/code_update/bmc_code_update.robot
index a11e385..f04d567 100644
--- a/extended/code_update/bmc_code_update.robot
+++ b/extended/code_update/bmc_code_update.robot
@@ -31,6 +31,7 @@
     Upload And Activate Image  ${IMAGE_FILE_PATH}
     ...  skip_if_active=${SKIP_UPDATE_IF_ACTIVE}
     OBMC Reboot (off)
+    Verify Running BMC Image  ${IMAGE_FILE_PATH}
 
 
 Upload And Activate Multiple BMC Images
diff --git a/extended/code_update/host_code_update.robot b/extended/code_update/host_code_update.robot
index df728b5..6feafe2 100644
--- a/extended/code_update/host_code_update.robot
+++ b/extended/code_update/host_code_update.robot
@@ -62,6 +62,7 @@
     Start SOL Console Logging
     Delete Error Logs
     REST Power On
+    Verify Running Host Image  ${IMAGE_FILE_PATH}
 
 
 Host Image Priority Attribute Test
diff --git a/lib/code_update_utils.robot b/lib/code_update_utils.robot
index 352af81..d7cc3c8 100644
--- a/lib/code_update_utils.robot
+++ b/lib/code_update_utils.robot
@@ -300,3 +300,30 @@
     ${status}=  Run Keyword And Return Status  Error Logs Should Not Exist
     Run Keyword If  '${status}' == 'False'  FFDC
     Delete Error Logs
+
+
+Verify Running BMC Image
+    [Documentation]  Verify that the version on the BMC is the same as the
+    ...              version in the given image.
+    [Arguments]  ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the BMC image tarball.
+
+    ${tar_version}=  Get Version Tar  ${image_file_path}
+    ${bmc_version}=  Get BMC Version
+    ${bmc_version}=  Remove String  ${bmc_version}  "
+    Should Be Equal  ${tar_version}  ${bmc_version}
+
+
+Verify Running Host Image
+    [Documentation]  Verify that the version of the PNOR image that is on the
+    ...              BMC is the same as the one in the given image.
+    [Arguments]  ${image_file_path}
+
+    # Description of argument(s):
+    # image_file_path   Path to the PNOR image tarball.
+
+    ${tar_version}=  Get Version Tar  ${image_file_path}
+    ${pnor_version}=  Get PNOR Version
+    Should Be Equal  ${tar_version}  ${pnor_version}
diff --git a/lib/utils.robot b/lib/utils.robot
index cf5ee7b..5d67982 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -1120,6 +1120,25 @@
     [Return]  ${output}
 
 
+Get PNOR Version
+    [Documentation]  Get the PNOR version from the BMC.
+
+    ${pnor_attrs}=  Get PNOR Attributes
+    [Return]  ${pnor_attrs['version']}
+
+
+Get PNOR Attributes
+    [Documentation]  Return PNOR software attributes as a dictionary.
+
+    # This keyword parses /var/lib/phosphor-software-manager/pnor/ro/pnor.toc into key/value pairs.
+
+    ${outbuf}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  cat /var/lib/phosphor-software-manager/pnor/ro/pnor.toc
+    ${pnor_attrs}=  Key Value Outbuf To Dict  ${outbuf}  delim==
+
+    [Return]  ${pnor_attrs}
+
+
 Get Elog URL List
     [Documentation]  Return error log entry list of URLs.