Merge "Add VLAN private network support to devstack"
[releng/builder.git] / jjb / opendaylight-infra-copy-ssh-keys.sh
1 #!/bin/bash
2 function copy-ssh-keys-to-slave() {
3     RETRIES=60
4     for j in $(seq 1 $RETRIES); do
5         if `ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${i}" > /dev/null 2>&1`; then
6             ssh jenkins@${i} 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts'
7             echo "Successfully copied public keys to slave ${i}"
8             break
9         elif [ $j -eq $RETRIES ]; then
10             echo "SSH not responding on ${i} after $RETIRES tries. Giving up."
11             exit 1
12         else
13             echo "SSH not responding on ${i}. Retrying in 10 seconds..."
14             sleep 10
15         fi
16     done
17 }
18
19 # TODO: Remove condition when we no longer use JClouds plugin
20 if [ -z "$JCLOUDS_IPS" ]; then
21     # If JCLOUDS_IPS is not set then we will spawn instances with
22     # OpenStack Heat.
23     source $WORKSPACE/.venv-openstack/bin/activate
24     CONTROLLER_IPS=`openstack --os-cloud rackspace stack show -f json -c outputs $STACK_NAME | jq -r '.outputs[] | select(.output_key=="vm_0_ips") | .output_value[]'`
25     MININET_IPS=`openstack --os-cloud rackspace stack show -f json -c outputs $STACK_NAME | jq -r '.outputs[] | select(.output_key=="vm_1_ips") | .output_value[]'`
26     ADDR=($CONTROLLER_IPS $MININET_IPS)
27 else
28     echo "OpenStack IPS are ${JCLOUDS_IPS}"
29     IFS=',' read -ra ADDR <<< "${JCLOUDS_IPS}"
30 fi
31
32 pids=""
33 for i in "${ADDR[@]}"; do
34     ( copy-ssh-keys-to-slave ) &
35     # Store PID of process
36     pids+=" $!"
37 done
38
39 # Detect when a process failed to copy ssh keys and fail build
40 for p in $pids; do
41     if wait $p; then
42         echo "Process $p successfully copied ssh keys."
43     else
44         echo "Process $p failed to copy ssh keys."
45         exit 1
46     fi
47 done
48 echo "Copying ssh keys complete."