Usability improvements to servo-stat.

This tweaks the ssh options not to depend quite so heavily on the
user's .ssh/config settings.

Additionally, this makes a small change so that if servo-stat or
servo-inventory is executed via a symlink that points into a
repository, we can still get the right answer

BUG=chromium:397273
TEST=run the commands

Change-Id: I877573122938b51b3e75969eb88bca866b1adb47
Reviewed-on: https://chromium-review.googlesource.com/209830
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Yusuf Mohsinally <mohsinally@chromium.org>
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
diff --git a/contrib/servo-inventory b/contrib/servo-inventory
index fbced9b..70a6a37 100755
--- a/contrib/servo-inventory
+++ b/contrib/servo-inventory
@@ -7,7 +7,8 @@
 # Output from servo-stat goes to stdout.  Starting and ending
 # timestamps are recorded on stderr.
 
-cd $(dirname $0)
+# readlink -f $0, in case $0 is a symlink from somewhere else
+cd $(dirname $(readlink -f $0))
 
 date >&2
 for MASTER in cautotest cautotest-cq
diff --git a/contrib/servo-stat b/contrib/servo-stat
index 5801870..38d95ae 100755
--- a/contrib/servo-stat
+++ b/contrib/servo-stat
@@ -13,15 +13,35 @@
 # progress, and if things get hung up, you can see where.
 
 
-REPO=$(dirname $0)/../../../../..
+# readlink -f $0, in case $0 is a symlink from somewhere else
+REPO=$(dirname $(readlink -f $0))/../../../../..
+REPO=$(readlink -f $REPO)
 HDCTOOLS=$(readlink -f $REPO/chroot/usr/lib/python2.7/site-packages/servo)
+KEYFILE=$REPO
+KEYFILE=$KEYFILE/src/third_party/chromiumos-overlay
+KEYFILE=$KEYFILE/chromeos-base/chromeos-test-testauthkeys/files/testing_rsa
+
+# Need some temporary files to keep ssh happy:
+#  + Just setting StrictHostKeyChecking=no won't silence all
+#    possible errors about host keys, so we need a temporary file
+#    where host keys can be cached.
+#  + We don't want to require the user to edit or provide the
+#    standard test keys, so we use the keys from the repo.  But...
+#    The file must be user-readable only, so we need a copy with
+#    the correct modes (mktemp is 600 by default).
+
+TMPKEYS=$(mktemp)
+TMPHOSTS=$(mktemp)
+trap 'rm $TMPKEYS $TMPHOSTS' EXIT
+cp $KEYFILE $TMPKEYS
 
 dut_control() {
   timeout 90 python $HDCTOOLS/dut_control.py "$@"
 }
 
 remote() {
-    local ssh_opts=( -n -o BatchMode=yes -o StrictHostKeyChecking=no )
+    local ssh_opts=( -n -o BatchMode=yes -o StrictHostKeyChecking=no
+                     -o UserKnownHostsFile=$TMPHOSTS -i $TMPKEYS )
     local servo=$1
     shift
     ssh "${ssh_opts[@]}" root@$servo "$@"