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 | |
| 16 | REPO=$(dirname $0)/../../../../.. |
| 17 | HDCTOOLS=$(readlink -f $REPO/chroot/usr/lib/python2.7/site-packages/servo) |
| 18 | |
| 19 | dut_control() { |
| 20 | timeout 90 python $HDCTOOLS/dut_control.py "$@" |
| 21 | } |
| 22 | |
| 23 | remote() { |
| 24 | local ssh_opts=( -n -o BatchMode=yes -o StrictHostKeyChecking=no ) |
| 25 | local servo=$1 |
| 26 | shift |
| 27 | ssh "${ssh_opts[@]}" root@$servo "$@" |
| 28 | } |
| 29 | |
| 30 | CONFIG=/var/lib/servod/config |
| 31 | |
| 32 | for H in "$@" |
| 33 | do |
| 34 | SERVO=$H-servo.cros |
| 35 | echo -n "$H ..." |
| 36 | STATUS=() |
| 37 | |
| 38 | HAVE_SERVOD=1 |
| 39 | BOARD= |
| 40 | VERSION= |
| 41 | |
| 42 | echo -n "A" |
| 43 | if ping -c1 -w2 $SERVO >/dev/null 2>&1 |
| 44 | then |
| 45 | echo -n "B" |
| 46 | if BUTTON=$(dut_control -s $SERVO pwr_button 2>&1) |
| 47 | then |
| 48 | if [ "$BUTTON" != "pwr_button:release" ] |
| 49 | then |
| 50 | STATUS=("${STATUS[@]}" "pwr_button is '$BUTTON'") |
| 51 | else |
| 52 | echo -n "C" |
| 53 | LID=$(dut_control -s $SERVO lid_open 2>&1) |
| 54 | if [ "$LID" != "lid_open:yes" ] |
| 55 | then |
| 56 | STATUS=("${STATUS[@]}" "lid_open is '$LID'") |
| 57 | fi |
| 58 | fi |
| 59 | else |
| 60 | STATUS=("${STATUS[@]}" "not running servod") |
| 61 | HAVE_SERVOD=0 |
| 62 | fi |
| 63 | |
| 64 | echo -n "D" |
| 65 | if ! remote $SERVO true >/dev/null 2>&1 |
| 66 | then |
| 67 | STATUS=("${STATUS[@]}" "ssh is down") |
| 68 | else |
| 69 | echo -n "E" |
| 70 | VERSION=$( |
| 71 | remote $SERVO grep CHROMEOS_RELEASE_VERSION /etc/lsb-release 2>&1) |
| 72 | if [ -z "$VERSION" ] |
| 73 | then |
| 74 | STATUS=("${STATUS[@]}" "not running brillo") |
| 75 | fi |
| 76 | fi |
| 77 | |
| 78 | if [ -n "$VERSION" ] |
| 79 | then |
| 80 | echo -n "F" |
| 81 | if remote $SERVO test -f $CONFIG |
| 82 | then |
| 83 | echo -n "G" |
| 84 | BOARD=$(remote $SERVO grep BOARD= $CONFIG) |
| 85 | fi |
| 86 | if [ $HAVE_SERVOD -eq 0 ] |
| 87 | then |
| 88 | if [ -z "$BOARD" ] |
| 89 | then |
| 90 | STATUS=("servod not configured") |
| 91 | else |
| 92 | echo -n "H" |
| 93 | JOB=$(remote $SERVO status servod | sed 's/,.*//') |
| 94 | if [ "$JOB" = "servod start/running" ] |
| 95 | then |
| 96 | STATUS=("servod failed") |
| 97 | fi |
| 98 | fi |
| 99 | fi |
| 100 | fi |
| 101 | else |
| 102 | STATUS=("${STATUS[@]}" "is down") |
| 103 | fi |
| 104 | |
| 105 | if [ "${#STATUS}" -eq 0 ] |
| 106 | then |
| 107 | STATUS=("is up") |
| 108 | fi |
| 109 | |
| 110 | if [ -n "$VERSION" ] |
| 111 | then |
| 112 | STATUS=("${STATUS[@]}" $BOARD $VERSION) |
| 113 | fi |
| 114 | echo " ${STATUS[@]}" |
| 115 | done |