inform_shopfloor: Set timeout when sending request to shopfloor

Set timeout period when informing shopfloor

BUG=chromium:544021
TEST=Run in-place wipe on Paine

Change-Id: I8101914a27cc19103ed1ac0893d438b50bbd841d
Reviewed-on: https://chromium-review.googlesource.com/311935
Commit-Ready: Shun-Hsing Ou <shunhsingou@chromium.org>
Tested-by: Shun-Hsing Ou <shunhsingou@chromium.org>
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
diff --git a/battery_cutoff/inform_shopfloor.sh b/battery_cutoff/inform_shopfloor.sh
index bec5490..4bf03d8 100755
--- a/battery_cutoff/inform_shopfloor.sh
+++ b/battery_cutoff/inform_shopfloor.sh
@@ -28,7 +28,7 @@
   # In factory install shim, we need to reset tty1 to show message in currect
   # way.
   stty -F "${TTY}" sane
-  echo "$1" > "${TTY}"
+  echo "$@" > "${TTY}"
   exit 1
 }
 
@@ -39,15 +39,13 @@
 post_to_shopfloor() {
   local shopfloor_url="$1"
   local post_file="$2"
-  local response="" wget_rc=""
+  local response=""
 
-  response=$(wget -q --header='Content-Type: text/xml' \
-    --post-file="${post_file}" -O - "${shopfloor_url}")
-  wget_rc=$?
+  until response=$(wget -T 30 --tries 1 -q --header='Content-Type: text/xml' \
+      --post-file="${post_file}" -O - "${shopfloor_url}"); do
+    echo "Cannot connect to server ${shopfloor_url}, retry again." >"${TTY}"
+  done
 
-  if [ "${wget_rc}" != "0" ]; then
-    die_with_error_message "Can't connect to server ${shopfloor_url}"
-  fi
   if echo "${response}" | grep -q "fault"; then
     die_with_error_message "Shopfloor call failed with response ${response}"
   fi
@@ -55,8 +53,8 @@
 
 wait_for_ethernet() {
   # Make sure we already connect to ethernet.
-  until ifconfig eth0 | grep -q 'inet' ; do
-    sleep 0.5;
+  until ifconfig eth0 | grep -q 'inet'; do
+    sleep 0.5
   done
 }
 
@@ -74,7 +72,9 @@
     factory_reset|factory_wipe )
       wait_for_ethernet
       if ! "${GENERATE_FINALIZE_REQUEST}" "$2" >"${POST_FILE}"; then
-        die_with_error_message "Failed to generate request."
+        local err=""
+        err="$(cat ${POST_FILE})"
+        die_with_error_message "Failed to generate request: ${err}"
       fi
       post_to_shopfloor "${shopfloor_url}" "${POST_FILE}"
       ;;