Merge "move heat-stack delete to include shell script"
[releng/builder.git] / jjb / opendaylight-infra-copy-ssh-keys.sh
1 #!/bin/bash
2 echo "----------> Copy ssh public keys to csit lab"
3
4 source $WORKSPACE/.venv-openstack/bin/activate
5
6 function copy-ssh-keys-to-slave() {
7     RETRIES=60
8     for j in $(seq 1 $RETRIES); do
9         if `ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${i}" > /dev/null 2>&1`; then
10             ssh jenkins@${i} 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts'
11             echo "Successfully copied public keys to slave ${i}"
12             break
13         elif [ $j -eq $RETRIES ]; then
14             echo "SSH not responding on ${i} after $RETIRES tries. Giving up."
15             exit 1
16         else
17             echo "SSH not responding on ${i}. Retrying in 10 seconds..."
18             sleep 10
19         fi
20
21         # ping test to see if connectivity is available
22         ping -c1 ${i}
23     done
24 }
25
26 # Print the Stack outputs parameters so that we can identify which IPs belong
27 # to which VM types.
28 openstack --os-cloud rackspace stack show -c outputs $STACK_NAME
29
30 ADDR=(`openstack --os-cloud rackspace stack show -f json -c outputs $STACK_NAME | \
31        jq -r '.outputs[] | \
32               select(.output_key | match("^vm_[0-9]+_ips\$")) | \
33               .output_value | .[]'`)
34 pids=""
35 for i in "${ADDR[@]}"; do
36     ( copy-ssh-keys-to-slave ) &
37     # Store PID of process
38     pids+=" $!"
39 done
40
41 # Detect when a process failed to copy ssh keys and fail build
42 for p in $pids; do
43     if wait $p; then
44         echo "Process $p successfully copied ssh keys."
45     else
46         echo "Process $p failed to copy ssh keys."
47         exit 1
48     fi
49 done
50 echo "Copying ssh keys complete."