Inventory ignore list should be a parameter to htx_hardbootme.

-Add INV_IGNORE_LIST as a parameter.
-Make the list a string instead of a dictionary.
-Allow for zero-length or null INV_IGNORE_LIST.
-Check that PREV_INV_FILE_PATH exists if it is specified.
-Display the inventory input parameters in the log.
-Print the INV_IGNORE_LIST in the difference file.

Resolves  openbmc/openbmc-test-automation#840
Resolves  openbmc/openbmc-test-automation#862
Change-Id: I8662c1aba172eb5f23cb86517ad24107a3f19b50
Signed-off-by: Steven Sombar <ssombar@us.ibm.com>
diff --git a/syslib/utils_keywords.py b/syslib/utils_keywords.py
index 4e8b419..c802065 100644
--- a/syslib/utils_keywords.py
+++ b/syslib/utils_keywords.py
@@ -19,38 +19,35 @@
 def json_inv_file_diff_check(file1_path,
                              file2_path,
                              diff_file_path,
-                             skip_dictionary):
+                             skip_string):
     r"""
     Compare the contents of two files which contain inventory data in
     JSON format.  The comparison is similar to the unix 'diff' command but
     the output lists the hardware subsystem (category) where differences
     are found, and some differences are selectively ignored.  The items
-    ignored are defined in the skip_dictionary dictionary.
+    ignored are defined by the skip_string.
 
     Description of arguments:
     file1_path       File containing JSON formatted data.
     file2_path       File to compare to file1 to.
     diff_file_path   File which will contain the resulting difference report.
-    skip_dictionary  Dictionary which defines what inventory items
+    skip_string      String which defines what inventory items
                      to ignore if there are differences in inventory
                      files -- some differences are expected or
-                     immaterial.  Specify items in this dictionary
-                     if there are inventory items that should be
-                     ignored whenever a comparison between inventory
-                     files is done.  For example, assigned processor
+                     immaterial.  For example, assigned processor
                      speed routinely varies depending upon the
                      needs of OCC/tmgt/ondemand governor.
                      Back-to-back inventory runs may show
                      processor speed differences even if nothing
                      else was run between them.
-                     Each dictionary entry is of the form
+                     Each item in this string is of the form
                      category:leafname where category is a JSON
                      hardware category such as "processor", "memory",
                      "disk", "display", "network", etc.,
                      and leafname is a leaf node (atribute name)
                      within that category.
-                     For example: {'processor':'size'}, or
-                     {'processor':'size','memory':'claimed','display':'id'}.
+                     For example: "processor:size", or
+                     "processor:size,network:speed,display:id".
 
     Sample difference report:
     Difference at line 102  (in section "memory":)
@@ -112,6 +109,9 @@
             file = open(diff_file_path, 'w')
         except IOError:
             file.close()
+        line_to_print = "Specified skip (ignore) string = " + \
+            skip_string + "\n\n"
+        file.write(line_to_print)
         line_to_print = now + " found no difference between file " + \
             file1_path + " and " + \
             file2_path + "\n"
@@ -126,6 +126,8 @@
         file.close()
         return IO_EXCEPTION_WRITING_FILE
 
+    line_to_print = "Specified skip (ignore) string = " + skip_string + "\n\n"
+    file.write(line_to_print)
     line_to_print = now + " compared files " + \
         file1_path + " and " + \
         file2_path + "\n"
@@ -179,20 +181,27 @@
                  str(row_num) + "  (in section " + \
                  category + ")\n"
                 file.write(line_to_print)
-            # If this is in the ignore dictionary, we'll print
+            # If this is in the ignore string, we'll print
             # it but also add text that it is an ignore item.
             skipitem = False
-            for key, value in skip_dictionary.iteritems():
-                if ((key in category.lower().strip()) and
-                   (value in diff_item.lower().strip())):
-                    line_to_print = "  " + \
-                        str(row_num) + " " + diff_item + \
-                        "    +++ NOTE! This line matches" + \
-                        " the inventory ignore list and" + \
-                        " can be ignored. +++\n"
-                    # set flag indicating this item is a skip item
-                    skipitem = True
-                    break
+            # If a skip_string is specified, check if category and item are
+            # in the skip_string.
+            if skip_string:
+                skip_list = skip_string.split(",")
+                for item in skip_list:
+                    cat_and_value = item.split(":")
+                    ignore_category = cat_and_value[0].lower().strip()
+                    ignore_value = cat_and_value[1].lower().strip()
+                    if ((ignore_category in category.lower().strip()) and
+                       (ignore_value in diff_item.lower().strip())):
+                        line_to_print = "  " + \
+                            str(row_num) + " " + diff_item + \
+                            "    +++ NOTE! This line matches" + \
+                            " the inventory ignore list and" + \
+                            " can be ignored. +++\n"
+                        # Set flag indicating this item is a skip item.
+                        skipitem = True
+                        break
             if skipitem is False:
                 # Its not a skip item, that is,
                 # this is not on the ignore list.
diff --git a/systest/htx_hardbootme_test.robot b/systest/htx_hardbootme_test.robot
index 2021885..d1a1796 100755
--- a/systest/htx_hardbootme_test.robot
+++ b/systest/htx_hardbootme_test.robot
@@ -26,6 +26,14 @@
 #                     This parameter is optional.  If not specified, an
 #                     initial inventory snapshot will be taken before
 #                     HTX startup.
+# INV_IGNORE_LIST     A comma-delimited list of colon-delimited pairs that
+#                     indicate what to ignore if there are inventory
+#                     differences.  For example, "processor:size,network:speed"
+#                     If differences are found during inventory checking
+#                     and those items are in this string, the
+#                     differences will be ignored.  This parameter is
+#                     optional.  If not specified the default value is
+#                     "processor:size".
 
 Resource        ../syslib/utils_os.robot
 Library         ../syslib/utils_keywords.py
@@ -43,7 +51,8 @@
 ${json_diff_file_path}       ${EXECDIR}/os_inventory_diff.json
 ${last_inventory_file_path}  ${EMPTY}
 ${CHECK_INVENTORY}           True
-&{ignore_dict}               processor=size
+${INV_IGNORE_LIST}           processor:size
+${PREV_INV_FILE_PATH}        ${EMPTY}
 
 
 *** Test Cases ***
@@ -52,16 +61,20 @@
     [Documentation]  Stress the system using HTX exerciser.
     [Tags]  Hard_Bootme_Test
 
-    Rprintn
-    Rpvars  HTX_DURATION  HTX_INTERVAL
-
     # Set last inventory file to PREV_INV_FILE_PATH otherwise set it
     # to ${EMPTY}.
     ${last_inventory_file_path}=  Get Variable Value  ${PREV_INV_FILE_PATH}
     ...  ${EMPTY}
 
+    Rprintn
+    Rpvars  HTX_DURATION  HTX_INTERVAL  CHECK_INVENTORY  INV_IGNORE_LIST
+    ...  PREV_INV_FILE_PATH
+
+    Run Keyword If  '${last_inventory_file_path}' != '${EMPTY}'
+    ...  OperatingSystem.File Should Exist  ${last_inventory_file_path}
+
     Set Suite Variable  ${last_inventory_file_path}  children=true
-    Set Suite Variable  &{ignore_dict}  children=true
+    Set Suite Variable  ${INV_IGNORE_LIST}  children=true
 
     Repeat Keyword  ${HTX_LOOP} times  Run HTX Exerciser
 
@@ -136,7 +149,7 @@
     # file2   A file that has an inventory snapshot, to compare with file1.
 
     ${diff_rc}=  JSON_Inv_File_Diff_Check  ${file1}
-     ...  ${file2}  ${json_diff_file_path}  ${ignore_dict}
+     ...  ${file2}  ${json_diff_file_path}  ${INV_IGNORE_LIST}
     Run Keyword If  '${diff_rc}' != '${0}'
     ...  Report Inventory Mismatch  ${diff_rc}  ${json_diff_file_path}