J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 1 | #!/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 Barnette | 655318d | 2014-07-24 15:24:24 -0700 | [diff] [blame] | 16 | # readlink -f $0, in case $0 is a symlink from somewhere else |
| 17 | REPO=$(dirname $(readlink -f $0))/../../../../.. |
| 18 | REPO=$(readlink -f $REPO) |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 19 | HDCTOOLS=$(readlink -f $REPO/chroot/usr/lib/python2.7/site-packages/servo) |
J. Richard Barnette | 655318d | 2014-07-24 15:24:24 -0700 | [diff] [blame] | 20 | KEYFILE=$REPO |
| 21 | KEYFILE=$KEYFILE/src/third_party/chromiumos-overlay |
J. Richard Barnette | 086ca9d | 2014-10-10 12:33:47 -0700 | [diff] [blame] | 22 | KEYFILE=$KEYFILE/chromeos-base/chromeos-ssh-testkeys/files/testing_rsa |
J. Richard Barnette | 655318d | 2014-07-24 15:24:24 -0700 | [diff] [blame] | 23 | |
| 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 | |
| 33 | TMPKEYS=$(mktemp) |
| 34 | TMPHOSTS=$(mktemp) |
| 35 | trap 'rm $TMPKEYS $TMPHOSTS' EXIT |
| 36 | cp $KEYFILE $TMPKEYS |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 37 | |
| 38 | dut_control() { |
| 39 | timeout 90 python $HDCTOOLS/dut_control.py "$@" |
| 40 | } |
| 41 | |
| 42 | remote() { |
J. Richard Barnette | 655318d | 2014-07-24 15:24:24 -0700 | [diff] [blame] | 43 | local ssh_opts=( -n -o BatchMode=yes -o StrictHostKeyChecking=no |
| 44 | -o UserKnownHostsFile=$TMPHOSTS -i $TMPKEYS ) |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 45 | local servo=$1 |
| 46 | shift |
J. Richard Barnette | 0c8dc5c | 2014-09-11 10:12:07 -0700 | [diff] [blame] | 47 | timeout 45 ssh "${ssh_opts[@]}" root@$servo "$@" |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | CONFIG=/var/lib/servod/config |
| 51 | |
| 52 | for H in "$@" |
| 53 | do |
| 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 Barnette | 36f7743 | 2014-10-01 14:36:06 -0700 | [diff] [blame] | 74 | if [ "$LID" != "lid_open:yes" -a "$LID" != "lid_open:not_applicable" ] |
J. Richard Barnette | 556038b | 2014-07-08 14:33:00 -0700 | [diff] [blame] | 75 | 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[@]}" |
| 135 | done |