2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017, 2018 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> Copy SSH public keys to CSIT lab"
13 os_cloud="${OS_CLOUD:-vex}"
14 stack_name="${OS_STACK_NAME}"
16 function copy_ssh_keys() {
18 >&2 echo "ERROR: Missing required arguments."
19 >&2 echo "Usage: copy_ssh_keys IP_ADDRESS"
26 for i in $(seq 1 $RETRIES); do
27 if ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${ip_address}" > /dev/null 2>&1; then
28 ssh "jenkins@${ip_address}" 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts'
29 echo "Successfully copied public keys to slave ${ip_address}"
31 elif [ "$i" -eq $RETRIES ]; then
32 echo "SSH not responding on ${ip_address} after $RETIRES tries. Giving up."
34 server=$(openstack port list -f value -c device_id --fixed-ip ip-address="${ip_address}")
35 echo "Dumping console logs for $server ${ip_address}"
36 openstack --os-cloud "$os_cloud" console log show "$server"
40 echo "SSH not responding on ${ip_address}. Retrying in 10 seconds..."
44 # ping test to see if connectivity is available
45 if ping -c1 "${ip_address}" &> /dev/null; then
46 echo "Ping to ${ip_address} successful."
48 echo "Ping to ${ip_address} failed."
53 # IP Addresses are returned as a space separated list so word splitting is ok
54 # shellcheck disable=SC2207
55 ip_addresses=($(openstack --os-cloud "$os_cloud" stack show -f json -c outputs "$stack_name" |
57 select(.output_key | match("^vm_[0-9]+_ips$")) |
58 .output_value | .[]'))
60 for ip in "${ip_addresses[@]}"; do
61 ( copy_ssh_keys "$ip" ) &
62 # Store PID of process
67 echo "Process $p ready."
69 echo "Process $p timed out waiting for SSH."
73 echo "SSH ready on all stack servers."