blob: 72e211a897acc599723293535a201707cce3bb50 [file] [log] [blame]
J. Richard Barnette556038b2014-07-08 14:33:00 -07001#!/bin/bash
2
3# Usage:
4# servo-stat DUT ...
5#
6# Reports the status of the servo (if any) attached to the DUT.
7# The DUT name is the host name without the .cros, or -servo.
8# For each named DUT, reports a line something like this:
9# DUT ...ABCDEFG is up BOARD=swanky CHROMEOS_RELEASE_VERSION=5995.0.0
10#
11# The letters are just arbitrary tags printed before any
12# long-running operation that might time out. It allows you to see
13# progress, and if things get hung up, you can see where.
14
15
J. Richard Barnette655318d2014-07-24 15:24:24 -070016# readlink -f $0, in case $0 is a symlink from somewhere else
17REPO=$(dirname $(readlink -f $0))/../../../../..
18REPO=$(readlink -f $REPO)
J. Richard Barnette556038b2014-07-08 14:33:00 -070019HDCTOOLS=$(readlink -f $REPO/chroot/usr/lib/python2.7/site-packages/servo)
J. Richard Barnette655318d2014-07-24 15:24:24 -070020KEYFILE=$REPO
21KEYFILE=$KEYFILE/src/third_party/chromiumos-overlay
J. Richard Barnette086ca9d2014-10-10 12:33:47 -070022KEYFILE=$KEYFILE/chromeos-base/chromeos-ssh-testkeys/files/testing_rsa
J. Richard Barnette655318d2014-07-24 15:24:24 -070023
24# Need some temporary files to keep ssh happy:
25# + Just setting StrictHostKeyChecking=no won't silence all
26# possible errors about host keys, so we need a temporary file
27# where host keys can be cached.
28# + We don't want to require the user to edit or provide the
29# standard test keys, so we use the keys from the repo. But...
30# The file must be user-readable only, so we need a copy with
31# the correct modes (mktemp is 600 by default).
32
33TMPKEYS=$(mktemp)
34TMPHOSTS=$(mktemp)
35trap 'rm $TMPKEYS $TMPHOSTS' EXIT
36cp $KEYFILE $TMPKEYS
J. Richard Barnette556038b2014-07-08 14:33:00 -070037
38dut_control() {
39 timeout 90 python $HDCTOOLS/dut_control.py "$@"
40}
41
42remote() {
J. Richard Barnette655318d2014-07-24 15:24:24 -070043 local ssh_opts=( -n -o BatchMode=yes -o StrictHostKeyChecking=no
44 -o UserKnownHostsFile=$TMPHOSTS -i $TMPKEYS )
J. Richard Barnette556038b2014-07-08 14:33:00 -070045 local servo=$1
46 shift
J. Richard Barnette0c8dc5c2014-09-11 10:12:07 -070047 timeout 45 ssh "${ssh_opts[@]}" root@$servo "$@"
J. Richard Barnette556038b2014-07-08 14:33:00 -070048}
49
50CONFIG=/var/lib/servod/config
51
52for H in "$@"
53do
54 SERVO=$H-servo.cros
55 echo -n "$H ..."
56 STATUS=()
57
58 HAVE_SERVOD=1
59 BOARD=
60 VERSION=
61
62 echo -n "A"
63 if ping -c1 -w2 $SERVO >/dev/null 2>&1
64 then
65 echo -n "B"
66 if BUTTON=$(dut_control -s $SERVO pwr_button 2>&1)
67 then
68 if [ "$BUTTON" != "pwr_button:release" ]
69 then
70 STATUS=("${STATUS[@]}" "pwr_button is '$BUTTON'")
71 else
72 echo -n "C"
73 LID=$(dut_control -s $SERVO lid_open 2>&1)
J. Richard Barnette36f77432014-10-01 14:36:06 -070074 if [ "$LID" != "lid_open:yes" -a "$LID" != "lid_open:not_applicable" ]
J. Richard Barnette556038b2014-07-08 14:33:00 -070075 then
76 STATUS=("${STATUS[@]}" "lid_open is '$LID'")
77 fi
78 fi
79 else
80 STATUS=("${STATUS[@]}" "not running servod")
81 HAVE_SERVOD=0
82 fi
83
84 echo -n "D"
85 if ! remote $SERVO true >/dev/null 2>&1
86 then
87 STATUS=("${STATUS[@]}" "ssh is down")
88 else
89 echo -n "E"
90 VERSION=$(
91 remote $SERVO grep CHROMEOS_RELEASE_VERSION /etc/lsb-release 2>&1)
92 if [ -z "$VERSION" ]
93 then
94 STATUS=("${STATUS[@]}" "not running brillo")
95 fi
96 fi
97
98 if [ -n "$VERSION" ]
99 then
100 echo -n "F"
101 if remote $SERVO test -f $CONFIG
102 then
103 echo -n "G"
104 BOARD=$(remote $SERVO grep BOARD= $CONFIG)
105 fi
106 if [ $HAVE_SERVOD -eq 0 ]
107 then
108 if [ -z "$BOARD" ]
109 then
110 STATUS=("servod not configured")
111 else
112 echo -n "H"
113 JOB=$(remote $SERVO status servod | sed 's/,.*//')
114 if [ "$JOB" = "servod start/running" ]
115 then
116 STATUS=("servod failed")
117 fi
118 fi
119 fi
120 fi
121 else
122 STATUS=("${STATUS[@]}" "is down")
123 fi
124
125 if [ "${#STATUS}" -eq 0 ]
126 then
127 STATUS=("is up")
128 fi
129
130 if [ -n "$VERSION" ]
131 then
132 STATUS=("${STATUS[@]}" $BOARD $VERSION)
133 fi
134 echo " ${STATUS[@]}"
135done