2 echo "----------> Copy ssh public keys to csit lab"
4 # shellcheck disable=SC1090
5 source "$WORKSPACE/.venv-openstack/bin/activate"
6 PYTHON="$WORKSPACE/.venv-openstack/bin/python"
7 OPENSTACK="$WORKSPACE/.venv-openstack/bin/openstack"
9 function copy-ssh-keys-to-slave() {
11 for j in $(seq 1 $RETRIES); do
12 # shellcheck disable=SC2092
13 if `ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${i}" > /dev/null 2>&1`; then
14 ssh "jenkins@${i}" 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts'
15 echo "Successfully copied public keys to slave ${i}"
17 elif [ "$j" -eq $RETRIES ]; then
18 echo "SSH not responding on ${i} after $RETIRES tries. Giving up."
21 echo "SSH not responding on ${i}. Retrying in 10 seconds..."
25 # ping test to see if connectivity is available
26 if ping -c1 "${i}" &> /dev/null; then
27 echo "Ping to ${i} successful."
29 echo "Ping to ${i} failed."
34 # Print the Stack outputs parameters so that we can identify which IPs belong
36 $PYTHON $OPENSTACK stack show -c outputs "$STACK_NAME"
38 # shellcheck disable=SC2006
39 ADDR=(`$PYTHON $OPENSTACK stack show -f json -c outputs "$STACK_NAME" | \
41 select(.output_key | match("^vm_[0-9]+_ips\$")) | \
42 .output_value | .[]'`)
44 for i in "${ADDR[@]}"; do
45 ( copy-ssh-keys-to-slave ) &
46 # Store PID of process
50 # Detect when a process failed to copy ssh keys and fail build
53 echo "Process $p successfully copied ssh keys."
55 echo "Process $p failed to copy ssh keys."
59 echo "Copying ssh keys complete."