[autotest] Fix inventory handling when `last_diagnosis()` fails.

In the lab_inventory, when `_get_diagnosis()` encountered an exception
it would return `None`.  Unfortunately, callers expected a `_Diagnosis`
tuple in all cases.

This fixes the exception return case, and adds a unit test to prevent
a recurrence.

BUG=None
TEST=Run the unit tests

Change-Id: I782231e0516c87600cb74d922edf96dbda1bc83a
Reviewed-on: https://chromium-review.googlesource.com/1246467
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Richard Barnette <jrbarnette@google.com>
Reviewed-by: Matthew Leszczenski <stagenut@chromium.org>
Reviewed-by: Jacob Kopczynski <jkop@chromium.org>
diff --git a/site_utils/lab_inventory.py b/site_utils/lab_inventory.py
index 9148744..8b9b646 100755
--- a/site_utils/lab_inventory.py
+++ b/site_utils/lab_inventory.py
@@ -152,6 +152,8 @@
     finally:
         _MISSING_DUT_METRIC.increment(
             fields={'host': history.hostname, 'presence': dut_present})
+    return _Diagnosis(None, None)
+
 
 def _host_is_working(history):
     return _get_diagnosis(history).status == status_history.WORKING
diff --git a/site_utils/lab_inventory_unittest.py b/site_utils/lab_inventory_unittest.py
index bb1b19a..1d06aa5 100755
--- a/site_utils/lab_inventory_unittest.py
+++ b/site_utils/lab_inventory_unittest.py
@@ -10,6 +10,7 @@
 import unittest
 
 import common
+from autotest_lib.frontend.afe.json_rpc import proxy
 from autotest_lib.server.lib import status_history
 from autotest_lib.site_utils import lab_inventory
 
@@ -46,10 +47,14 @@
         self.start_time = _FAKE_TIME
         self.end_time = _FAKE_TIME + 20
         self.fake_task = _FakeHostEvent(_FAKE_TIME + 5)
+        self.exception = None
 
     def last_diagnosis(self):
         """Return the recorded diagnosis."""
-        return self.status, self.fake_task
+        if self.exception:
+            raise self.exception
+        else:
+            return self.status, self.fake_task
 
 
 class _FakeHostLocation(object):
@@ -107,6 +112,12 @@
         history.fake_task = _FakeHostEvent(history.start_time - 2)
         self.assertEqual(self._get_diagnosis_status(history), _UNUSED)
 
+    def test_exception(self):
+        """Test exceptions raised by `last_diagnosis()`."""
+        history = _FakeHostHistory('', '', _BROKEN)
+        history.exception = proxy.JSONRPCException('exception for testing')
+        self.assertIsNone(self._get_diagnosis_status(history))
+
 
 class HostSetInventoryTestCase(unittest.TestCase):
     """Unit tests for class `_HostSetInventory`.