[autotest] For lab inventory, don't recommend non-inventory boards

The regular board inventory excludes boards that have no suites
pool, or that have only suites DUTs.  However, when we create a list
of DUTs for repair, we don't honor those exclusions.  The result is
that in some cases, we recommend DUTs for repair when the board
isn't listed in the inventory.

This change makes the repair recommendations be drawn only from
the boards that are part of the regular inventory.

BUG=None
TEST=unit tests, plus selected testing w/ --debug

Change-Id: I0dfbd060193afbd9dd08d646151e598a9b8c0d5f
Reviewed-on: https://chromium-review.googlesource.com/305398
Commit-Ready: Richard Barnette <jrbarnette@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Paul Hobbs <phobbs@google.com>
diff --git a/site_utils/lab_inventory.py b/site_utils/lab_inventory.py
index b46e022..19c0814 100755
--- a/site_utils/lab_inventory.py
+++ b/site_utils/lab_inventory.py
@@ -401,34 +401,37 @@
             self[h.host_board].record_host(h)
 
 
-    def get_working_list(self):
-        """Return a list of all working DUTs in the inventory.
+    def get_working_list(self, boards):
+        """Return a list of working DUTs for given boards.
 
-        Go through all HostJobHistory objects in the inventory,
-        selecting the ones where the last diagnosis is `WORKING`.
+        For every board in the list, select all HostJobHistory
+        objects where the last diagnosis is `WORKING`.
 
+        @param boards   The list of boards to be searched for working
+                        DUTs.
         @return A list of HostJobHistory objects.
 
         """
         l = []
-        for counts in self.values():
-            l.extend(counts.get_working_list())
+        for b in boards:
+            l.extend(self[b].get_working_list())
         return l
 
 
-    def get_broken_list(self):
-        """Return a list of all broken DUTs in the inventory.
+    def get_broken_list(self, boards):
+        """Return a list of broken DUTs for given boards.
 
-        Go through all HostJobHistory objects in the inventory,
-        selecting the ones where the last diagnosis is not
-        `WORKING`.
+        For every board in the list, select all HostJobHistory
+        objects where the last diagnosis is not `WORKING`.
 
+        @param boards   The list of boards to be searched for broken
+                        DUTs.
         @return A list of HostJobHistory objects.
 
         """
         l = []
-        for counts in self.values():
-            l.extend(counts.get_broken_list())
+        for b in boards:
+            l.extend(self[b].get_broken_list())
         return l
 
 
@@ -601,9 +604,9 @@
     # t[2] - number of broken devices
     board_buffer_counts = {t[0]: t[1] for t in board_counts
                                     if t[2] != 0}
-    recommendation = None
-    best_score = None
-    # N.B. The logic of this loop may seem complicated, but
+    search_boards = board_buffer_counts.keys()
+    broken_list = inventory.get_broken_list(search_boards)
+    # N.B. The logic inside this loop may seem complicated, but
     # simplification is hard:
     #   * Calculating an initial recommendation outside of
     #     the loop likely would make things more complicated,
@@ -611,7 +614,9 @@
     #   * It's necessary to calculate an initial lab slice once per
     #     lab _before_ the while loop, in case the number of broken
     #     DUTs in a lab is less than `num_recommend`.
-    for lab_duts in _sort_by_location(inventory.get_broken_list()):
+    recommendation = None
+    best_score = None
+    for lab_duts in _sort_by_location(broken_list):
         start = 0
         end = num_recommend
         lab_slice = lab_duts[start : end]