[autotest] Consistent lock_time for a host
In the old code, 'lock_time' field for a host is recorded
when django saves the modified host record. It can sometimes
generate a slight lag (a couple seconds) for lock_time
between the master and a shard DB. This CL makes it always
consistent.
BUG=chromium:535651
TEST=Puppylab. Try locking a sharded host with a test code that
delays the message (modify_host_local) forwarding to a shard.
Change-Id: I33885f659c7511ae136493228380b459dae001d5
Reviewed-on: https://chromium-review.googlesource.com/318387
Commit-Ready: Mungyung Ryu <mkryu@google.com>
Tested-by: Mungyung Ryu <mkryu@google.com>
Reviewed-by: Mungyung Ryu <mkryu@google.com>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 7ff36ee..50623db 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -287,6 +287,11 @@
host = models.Host.smart_get(id)
rpc_utils.check_modify_host_locking(host, kwargs)
+ # This is required to make `lock_time` for a host be exactly same
+ # between the master and a shard.
+ if kwargs.get('locked', None) and 'lock_time' not in kwargs:
+ kwargs['lock_time'] = datetime.datetime.now()
+
rpc_utils.fanout_rpc([host], 'modify_host_local',
include_hostnames=False, id=id, **kwargs)
host.update_object(kwargs)
@@ -338,6 +343,11 @@
affected_shard_hostnames.add(host.shard.rpc_hostname())
affected_host_ids.append(host.id)
+ # This is required to make `lock_time` for a host be exactly same
+ # between the master and a shard.
+ if update_data.get('locked', None) and 'lock_time' not in update_data:
+ update_data['lock_time'] = datetime.datetime.now()
+
# Caution: Changing the filter from the original here. See docstring.
rpc_utils.run_rpc_on_multiple_hostnames(
'modify_hosts_local', affected_shard_hostnames,