[autotest] Aggressively commit HostInfo back to AFE.

This CL is a much-too-aggressive commit of the HostInfo back to its
store. We found one place where the info udpates were stepping over its
own feet. Rather than audit right now if another such instance exists
within |machine_install| assume the worst.

BUG=chromium:730272
TEST=TBD.

Change-Id: Ia7d80fc3ea3a175f387f1d268cfd9e9f9b002a22
Reviewed-on: https://chromium-review.googlesource.com/527276
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/server/afe_utils.py b/server/afe_utils.py
index d8d81f1..7c62151 100644
--- a/server/afe_utils.py
+++ b/server/afe_utils.py
@@ -155,19 +155,18 @@
         return local_value
 
 
-def _clear_host_attributes_before_provision(host):
+def _clear_host_attributes_before_provision(host, info):
     """Clear host attributes before provision, e.g., job_repo_url.
 
     @param host: A Host object to clear attributes before provision.
+    @param info: A HostInfo to update the attributes in.
     """
     attributes = host.get_attributes_to_clear_before_provision()
     if not attributes:
         return
 
-    info = host.host_info_store.get()
     for key in attributes:
         info.attributes.pop(key, None)
-    host.host_info_store.commit(info)
 
 
 def update_host_attribute(host, attribute, value):
@@ -199,9 +198,9 @@
     @param **dargs: dargs dict to pass to machine_install.
     """
     info = host.host_info_store.get()
-
     info.clear_version_labels()
-    _clear_host_attributes_before_provision(host)
+    _clear_host_attributes_before_provision(host, info)
+    host.host_info_store.commit(info)
     # If ENABLE_DEVSERVER_TRIGGER_AUTO_UPDATE is enabled and the host is a
     # CrosHost, devserver will be used to trigger auto-update.
     if host.support_devserver_provision:
@@ -209,7 +208,10 @@
             *args, **dargs)
     else:
         image_name, host_attributes = host.machine_install(*args, **dargs)
+        info = host.host_info_store.get()
         info.attributes.update(host_attributes)
-    info.set_version_label(host.VERSION_PREFIX, image_name)
+        host.host_info_store.commit(info)
 
+    info = host.host_info_store.get()
+    info.set_version_label(host.VERSION_PREFIX, image_name)
     host.host_info_store.commit(info)