[autotest] Require lock reason to lock device
When locking a device, a locking reason now must be provided.
This applies to both adding a new device, and modifying an
existing device from both the web frontend and the atest
command-line tool.
BUG=chromium:336805
DEPLOY=migrate
TEST=Tested adding locked/unlocked devices and locking/unlocking devices
from both the web frontend and using the 'atest host ...' command-line tools.
Change-Id: I3a8cd8891a2999f026dd709ae8a79e2b8cbc251a
Reviewed-on: https://chromium-review.googlesource.com/267595
Tested-by: Matthew Sartori <msartori@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Matthew Sartori <msartori@chromium.org>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 352e77f..80cc67e 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -239,9 +239,14 @@
# hosts
-def add_host(hostname, status=None, locked=None, protection=None):
+def add_host(hostname, status=None, locked=None, lock_reason='', protection=None):
+ if locked and not lock_reason:
+ raise model_logic.ValidationError(
+ {'locked': 'Please provide a reason for locking when adding host.'})
+
return models.Host.add_object(hostname=hostname, status=status,
- locked=locked, protection=protection).id
+ locked=locked, lock_reason=lock_reason,
+ protection=protection).id
@rpc_utils.forward_single_host_rpc_to_shard