[autotest] Retransmit hosts and jobs if heartbeat failed on client.

If the client fails while performing a heartbeat, the master will
have already set the shard_id and therefore won't ever send jobs or
hosts again.

This changes this behavior: The shard client sends ids of hosts and
incomplete jobs it already has in the heartbeat.
Objects with id's that weren't sent, will be returned by the
heartbeat regardless of already having a shard_id set.

BUG=None
DEPLOY=apache
TEST=Ran suites

Change-Id: I46bbb13a81886476ec48c6f879f123290769b659
Reviewed-on: https://chromium-review.googlesource.com/220692
Tested-by: Jakob Jülich <jakobjuelich@chromium.org>
Reviewed-by: Prashanth B <beeps@chromium.org>
Commit-Queue: Jakob Jülich <jakobjuelich@chromium.org>
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index 7e53c7c..5c0deb1 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -943,15 +943,17 @@
     return models.Shard.smart_get(shard_hostname)
 
 
-def find_records_for_shard(shard):
+def find_records_for_shard(shard, known_job_ids, known_host_ids):
     """Find records that should be sent to a shard.
 
     @param shard: Shard to find records for.
+    @param known_job_ids: List of ids of jobs the shard already has.
+    @param known_host_ids: List of ids of hosts the shard already has.
 
     @returns: Tuple of two lists for hosts and jobs: (hosts, jobs).
     """
-    hosts = models.Host.assign_to_shard(shard)
-    jobs = models.Job.assign_to_shard(shard)
+    hosts = models.Host.assign_to_shard(shard, known_host_ids)
+    jobs = models.Job.assign_to_shard(shard, known_job_ids)
 
     return hosts, jobs