Increase logging of check_ethernet.hook.

Prior to this change, the only message check_ethernet.hook wrote
to /var/log/messages was to report reboot.  Other interesting events
(such as attempting to restart the network) went unreported.  This
adds logging messages to check_ethernet.hook to report the first
time ping fails to reach the gateway, and again before attempting to
restart ethernet interfaces.

The motivation for this change is to increase visibility during
unexplained network outages on the DUT.

BUG=chromium:354944
TEST=run check_ethernet.hook on a DUT with and without a network

Change-Id: I77dfbfe51aee118c7802726379216948be45620f
Reviewed-on: https://chromium-review.googlesource.com/197529
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Prashanth B <beeps@chromium.org>
diff --git a/recover_duts/hooks/check_ethernet.hook b/recover_duts/hooks/check_ethernet.hook
index 94b4146..117bd9e 100755
--- a/recover_duts/hooks/check_ethernet.hook
+++ b/recover_duts/hooks/check_ethernet.hook
@@ -20,7 +20,7 @@
 # TODO(tbroch) Relocate this to common hook library if/when there's more than
 # one hook.
 critical_msg() {
-  logger -t "recover_duts:$(basename $0)" -- "$@"
+  logger -t "$(basename $0)" -- "$@"
 }
 
 # Returns the default gateway.
@@ -72,7 +72,9 @@
 # Restart all our ethernet devices and restart shill.
 recover_ethernet_devices() {
   local eth
+  critical_msg "Gateway still unreachable; restarting ethernet interfaces"
   for eth in $(find_ethernet_interfaces); do
+    echo "Bounce interface ${eth}"
     ifconfig ${eth} down
     ifconfig ${eth} up
   done
@@ -89,15 +91,14 @@
 
 # Try to find a connected SSH client (our autotest server) and ping it
 ping_controlling_server() {
-  local ssh_client default_gateway
-  ssh_client="$(find_ssh_client)" || ssh_client=
+  local default_gateway="$(get_default_gateway)" || default_gateway=
+  if [ -n "${default_gateway}" ]; then
+    do_ping ${default_gateway} && return 0
+  fi
+
+  local ssh_client="$(find_ssh_client)" || ssh_client=
   if [ -n "${ssh_client}" ]; then
     do_ping ${ssh_client} && return 0
-  else
-    default_gateway="$(get_default_gateway)" || default_gateway=
-    if [ -n "${default_gateway}" ]; then
-      do_ping ${default_gateway} && return 0
-    fi
   fi
   return 1
 }
@@ -107,11 +108,16 @@
   # a minimum of 12 minutes network timeout tolerance for tests that disrupt
   # connectivity with the SSH connection from the autotest server. This timeout
   # is 15 minutes to make sure it can never fail before that SSH session does.
-  for i in {0..29}; do
+  if ping_controlling_server; then
+    return 0
+  fi
+  critical_msg "Gateway unreachable; will retry for 15 minutes"
+  for i in {1..30}; do
+    sleep 30
     if ping_controlling_server; then
+      critical_msg "Gateway now answering; returning success"
       return 0
     fi
-    sleep 30
   done
 
   # We can't reach our controlling server through any ethernet devices.