[autotest] Update labels on host._afe_host when clearing/adding them.

BUG=chromium:632503
TEST=Locally on moblab ran brillo gtests and saw that the updated
packages were downloaded.

Change-Id: I48c60569614f627af007bf1c92745e86402f0b42
Reviewed-on: https://chromium-review.googlesource.com/364384
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Kevin Cheng <kevcheng@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/afe_utils.py b/server/afe_utils.py
index 4073026..f6997bd 100644
--- a/server/afe_utils.py
+++ b/server/afe_utils.py
@@ -108,6 +108,8 @@
 
     @param host: Host whose version labels to clear.
     """
+    host._afe_host.labels = [label for label in host._afe_host.labels
+                             if not label.startswith(host.VERSION_PREFIX)]
     if not host_in_lab(host):
         return
 
@@ -126,9 +128,10 @@
     @param host: Host to add the version label for.
     @param image_name: Name of the build version to add to the host.
     """
+    label = '%s:%s' % (host.VERSION_PREFIX, image_name)
+    host._afe_host.labels.append(label)
     if not host_in_lab(host):
         return
-    label = '%s:%s' % (host.VERSION_PREFIX, image_name)
     AFE.run('label_add_hosts', id=label, hosts=[host.hostname])