BMC driver version check

Checks the user specified BMC version string and if found installed
on the BMC, skip the update process.

Resolves  openbmc/openbmc-test-automation#780

Change-Id: Ia48c90a0db74b02d82cad5f7ac1c2a4586214c99
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/extended/code_update/code_update_utils.robot b/extended/code_update/code_update_utils.robot
index 5ec74c8..8be8876 100755
--- a/extended/code_update/code_update_utils.robot
+++ b/extended/code_update/code_update_utils.robot
@@ -114,19 +114,16 @@
 
 
 Validate BMC Version
-    [Arguments]   ${args}=post
-    # Check BMC installed version
+    [Documentation]  Get BMC version from /etc/os-release and compare.
+    [Arguments]  ${version}
+
+    # Description of argument(s):
+    # version  Software version (e.g. "v1.99.8-41-g86a4abc").
+
     Open Connection And Log In
-    ${version}   ${stderr}=    Execute Command   cat /etc/version
-    ...    return_stderr=True
-    Should Be Empty     ${stderr}
-    # The File name contains the version installed
-    Run Keyword If   '${args}' == 'before'
-    ...    Should not Contain  ${FILE_PATH}   ${version}
-    ...    msg=Same version already installed
-    ...    ELSE
-    ...    Should Contain      ${FILE_PATH}   ${version}
-    ...    msg=Code update Failed
+    ${cmd}=  Set Variable  grep ^VERSION_ID= /etc/os-release | cut -f 2 -d '='
+    ${output}=  Execute Command On BMC  ${cmd}
+    Should Be Equal As Strings  ${version}  ${output[1:-1]}
 
 
 Trigger Warm Reset via Reboot
diff --git a/extended/code_update/update_bmc.robot b/extended/code_update/update_bmc.robot
index 8771e86..b82ae13 100644
--- a/extended/code_update/update_bmc.robot
+++ b/extended/code_update/update_bmc.robot
@@ -79,12 +79,12 @@
     [Documentation]  Initiate a code update on the BMC.
     [Tags]  Initiate_Code_Update_BMC
 
-    # TODO: Disabling version check until new logic are in place.
-    # ${status}=   Run Keyword and Return Status
-    # ...   Validate BMC Version   before
+    ${status}=  Run Keyword If  '${LAST_KNOWN_GOOD_VERSION}' != '${EMPTY}'
+    ...  Run Keyword And Return Status
+    ...  Validate BMC Version  ${LAST_KNOWN_GOOD_VERSION}
 
-    # Run Keyword if  '${status}' == '${False}'
-    # ...     Pass Execution   Same Driver version installed
+    Run Keyword if  '${status}' == '${True}'
+    ...  Pass Execution  The BMC already has the requested build loaded so no further action will be taken.
 
     # Enable user to bypass prerequisite operations.
     # Use cases for if BMC is not in working state.
diff --git a/lib/resource.txt b/lib/resource.txt
index d457ad6..3aef429 100755
--- a/lib/resource.txt
+++ b/lib/resource.txt
@@ -53,6 +53,10 @@
 ${IMAGE_FILE_PATH}   ${EMPTY}
 ${BAD_IMAGES_DIR_PATH}    ${EMPTY}
 
+# 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}
+
 *** Keywords ***
 Get Inventory Schema
     [Arguments]    ${machine}
diff --git a/tools/generate_argumentfile.sh b/tools/generate_argumentfile.sh
index a19aca1..f571971 100755
--- a/tools/generate_argumentfile.sh
+++ b/tools/generate_argumentfile.sh
@@ -26,3 +26,4 @@
 echo "--variable TFTP_FILE_NAME:$TFTP_FILE_NAME" >> $ARG_FILE
 echo "--variable IMAGE_FILE_PATH:$IMAGE_FILE_PATH" >> $ARG_FILE
 echo "--variable BAD_IMAGES_DIR_PATH:$BAD_IMAGES_DIR_PATH" >> $ARG_FILE
+echo "--variable LAST_KNOWN_GOOD_VERSION:$LAST_KNOWN_GOOD_VERSION" >> $ARG_FILE