[autotest] Fix a bug in host label metadata collection

Add retries in metadata bulk uploading.
Abort label collection if bulk upload failed.

If an entry of time_index posted to metadb without actual host labels uploaded,
host history lookup will fail as there is no board information found for the
latest time_index.

BUG=None
TEST=local run

Change-Id: Ic234cf8e97f4b80498c51189a06647b1ea8685cb
Reviewed-on: https://chromium-review.googlesource.com/301117
Commit-Ready: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Mungyung Ryu <mkryu@google.com>
diff --git a/site_utils/host_label_utils.py b/site_utils/host_label_utils.py
index 3a6f21b..461c962 100755
--- a/site_utils/host_label_utils.py
+++ b/site_utils/host_label_utils.py
@@ -30,7 +30,6 @@
 _HOST_LABEL_TYPE = 'host_labels'
 _HOST_LABEL_TIME_INDEX_TYPE = 'host_labels_time_index'
 
-
 def get_all_boards(labels=None):
     """Get a list of boards from host labels.
 
@@ -111,7 +110,8 @@
                 'labels': [label.name for label in host.labels.all()],
                 'time_index': time_index}
         data_list.append(info)
-    autotest_es.bulk_post(data_list, log_time_recorded=False)
+    if not autotest_es.bulk_post(data_list, log_time_recorded=False):
+        raise Exception('Failed to upload host label info.')
 
     # After all host label information is logged, save the time stamp.
     autotest_es.post(use_http=True, type_str=_HOST_LABEL_TIME_INDEX_TYPE,