Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Library for setting up remote access and running remote commands. | 5 # Library for setting up remote access and running remote commands. |
| 6 | 6 |
| 7 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\ | 7 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\ |
| 8 ssh_keys/testing_rsa" | 8 ssh_keys/testing_rsa" |
| 9 | 9 |
| 10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" | 10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 UserKnownHostsFile=$TMP_KNOWN_HOSTS" --no-R \ | 27 UserKnownHostsFile=$TMP_KNOWN_HOSTS" --no-R \ |
| 28 --files-from=$1 root@${FLAGS_remote}:/ $2 | 28 --files-from=$1 root@${FLAGS_remote}:/ $2 |
| 29 } | 29 } |
| 30 | 30 |
| 31 function remote_sh() { | 31 function remote_sh() { |
| 32 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ | 32 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ |
| 33 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") | 33 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") |
| 34 return ${PIPESTATUS[0]} | 34 return ${PIPESTATUS[0]} |
| 35 } | 35 } |
| 36 | 36 |
| 37 # Checks to see if pid $1 is running. | |
| 38 function is_pid_running() { | |
| 39 ps -p ${1} 2>&1 > /dev/null | |
| 40 } | |
| 41 | |
| 42 # Wait function given an additional timeout argument. | |
| 43 # $1 - pid to wait on. | |
| 44 # $2 - timeout to wait for. | |
| 45 function wait_with_timeout() { | |
| 46 local pid=$1 | |
| 47 local timeout=$2 | |
| 48 local timeout_inc=1 | |
|
petkov
2011/01/12 22:40:31
maybe
readonly TIMEOUT_INC=1
| |
| 49 local current_timeout=0 | |
| 50 while is_pid_running ${pid} && [ ${current_timeout} -lt ${timeout} ]; do | |
| 51 sleep ${timeout_inc} | |
| 52 current_timeout=$((current_timeout + timeout_inc)) | |
| 53 done | |
| 54 is_pid_running ${pid} | |
| 55 } | |
| 56 | |
| 57 # Robust ping that will monitor ssh and not hang even if ssh hangs. | |
| 58 function ping_ssh() { | |
| 59 remote_sh "true" & | |
| 60 local pid=$! | |
| 61 wait_with_timeout ${pid} 5 | |
| 62 ! kill -9 ${pid} | |
| 63 } | |
| 64 | |
| 37 function remote_sh_allow_changed_host_key() { | 65 function remote_sh_allow_changed_host_key() { |
| 38 rm -f $TMP_KNOWN_HOSTS | 66 rm -f $TMP_KNOWN_HOSTS |
| 67 ping_ssh | |
| 39 remote_sh "$@" | 68 remote_sh "$@" |
| 40 } | 69 } |
| 41 | 70 |
| 42 function set_up_remote_access() { | 71 function set_up_remote_access() { |
| 43 if [ -z "$SSH_AGENT_PID" ]; then | 72 if [ -z "$SSH_AGENT_PID" ]; then |
| 44 eval $(ssh-agent) | 73 eval $(ssh-agent) |
| 45 OWN_SSH_AGENT=1 | 74 OWN_SSH_AGENT=1 |
| 46 else | 75 else |
| 47 OWN_SSH_AGENT=0 | 76 OWN_SSH_AGENT=0 |
| 48 fi | 77 fi |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 135 |
| 107 function remote_access_init() { | 136 function remote_access_init() { |
| 108 TMP_PRIVATE_KEY=$TMP/private_key | 137 TMP_PRIVATE_KEY=$TMP/private_key |
| 109 TMP_KNOWN_HOSTS=$TMP/known_hosts | 138 TMP_KNOWN_HOSTS=$TMP/known_hosts |
| 110 if [ -z "$FLAGS_remote" ]; then | 139 if [ -z "$FLAGS_remote" ]; then |
| 111 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" | 140 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" |
| 112 exit 1 | 141 exit 1 |
| 113 fi | 142 fi |
| 114 set_up_remote_access | 143 set_up_remote_access |
| 115 } | 144 } |
| OLD | NEW |