Merge "move ending regex out of csit list indent"
[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         if ping -c1 ${i} &> /dev/null; then
23             echo "Ping to ${i} successful."
24         else
25             echo "Ping to ${i} failed."
26         fi
27     done
28 }
29
30 # Print the Stack outputs parameters so that we can identify which IPs belong
31 # to which VM types.
32 openstack --os-cloud rackspace stack show -c outputs $STACK_NAME
33
34 ADDR=(`openstack --os-cloud rackspace stack show -f json -c outputs $STACK_NAME | \
35        jq -r '.outputs[] | \
36               select(.output_key | match("^vm_[0-9]+_ips\$")) | \
37               .output_value | .[]'`)
38 pids=""
39 for i in "${ADDR[@]}"; do
40     ( copy-ssh-keys-to-slave ) &
41     # Store PID of process
42     pids+=" $!"
43 done
44
45 # Detect when a process failed to copy ssh keys and fail build
46 for p in $pids; do
47     if wait $p; then
48         echo "Process $p successfully copied ssh keys."
49     else
50         echo "Process $p failed to copy ssh keys."
51         exit 1
52     fi
53 done
54 echo "Copying ssh keys complete."