lock_machine: shout when our `swarming` command dies
When I tried to run crosperf without proper `swarming.py`
authentication, crosperf said the machine I wanted to use wasn't
available in skylab. It'd be better if we reported that we couldn't tell
if the machine was/wasn't in skylab due to the tool we're using failing.
Looks like this script can fail for a number of other reasons, too, so
throwing our hands up is likely going to often be our best bet.
BUG=None
TEST=ran without auth; exception was thrown. ran with; things worked.
Change-Id: I4d0e4ec70eddb3a7836686eef819e6175a730756
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2177063
Reviewed-by: Bob Haarman <inglorion@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
diff --git a/lock_machine.py b/lock_machine.py
index 8588ebf..dc49414 100755
--- a/lock_machine.py
+++ b/lock_machine.py
@@ -386,7 +386,11 @@
(swarming,
credential,
machine.rstrip('.cros')))
- ret_tup = self.ce.RunCommandWOutput(cmd)
+ exit_code, stdout, stderr = self.ce.RunCommandWOutput(cmd)
+ if exit_code:
+ raise ValueError(
+ 'Querying bots failed (2); stdout: %r; stderr: %r' % (stdout, stderr))
+
# The command will return a json output as stdout. If machine not in skylab
# stdout will look like this:
# {
@@ -395,10 +399,7 @@
# }
# Otherwise there will be a tuple starting with 'items', we simply detect
# this keyword for result.
- if 'items' not in ret_tup[1]:
- return False
- else:
- return True
+ return 'items' in stdout
def LeaseSkylabMachine(self, machine):
"""Run command to lease dut from skylab.