[autotest] Simplify logic on check_for_duplicate_hosts()

Of note, Django object compare and equal if they have the same
id (they represent the same database tuple).

BUG=None
TEST=None

Change-Id: Iaad49743253323dfcd7244f7ae62b9be46bf28a0
Reviewed-on: https://chromium-review.googlesource.com/420507
Commit-Ready: Allen Li <ayatane@chromium.org>
Tested-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index 4468449..0ea1418 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -578,13 +578,10 @@
 
 
 def check_for_duplicate_hosts(host_objects):
-    host_ids = set()
-    duplicate_hostnames = set()
-    for host in host_objects:
-        if host.id in host_ids:
-            duplicate_hostnames.add(host.hostname)
-        host_ids.add(host.id)
-
+    host_counts = collections.Counter(host_objects)
+    duplicate_hostnames = {host.hostname
+                           for host, count in host_counts.iteritems()
+                           if count > 1}
     if duplicate_hostnames:
         raise model_logic.ValidationError(
                 {'hosts' : 'Duplicate hosts: %s'