[moblab] Remove orphaned attributes

Remove attributes associated with a DUT when it is deleted.
Also check for and remove attributes on a new DUT, so that
new DUTs aren't picking up orphaned attributes from previously
deleted DUTs.

BUG=chromium:783994
TEST=local moblab device

Change-Id: If244470c64226bb8c60a1edaf0da092f40261906
Reviewed-on: https://chromium-review.googlesource.com/896581
Commit-Ready: Keith Haddow <haddowk@chromium.org>
Tested-by: Matt Mallett <mattmallett@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Keith Haddow <haddowk@chromium.org>
diff --git a/frontend/afe/models.py b/frontend/afe/models.py
index 2353d81..26ab2b5 100644
--- a/frontend/afe/models.py
+++ b/frontend/afe/models.py
@@ -738,6 +738,10 @@
         if first_time:
             everyone = AclGroup.objects.get(name='Everyone')
             everyone.hosts.add(self)
+            # remove attributes that may have lingered from an old host and
+            # should not be associated with a new host
+            for host_attribute in self.hostattribute_set.all():
+                self.delete_attribute(host_attribute.attribute)
         self._check_for_updated_attributes()
 
 
@@ -746,6 +750,8 @@
         for queue_entry in self.hostqueueentry_set.all():
             queue_entry.deleted = True
             queue_entry.abort()
+        for host_attribute in self.hostattribute_set.all():
+            self.delete_attribute(host_attribute.attribute)
         super(Host, self).delete()