X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=jjb%2Fopendaylight-infra-copy-ssh-keys.sh;h=cce9296371d1d054be7425e656f7d0a872b3902a;hb=fee730e378c29833969b49e210a26ed5414279eb;hp=0fad4bf1c1b16ead99e20714f58c6687afa307e4;hpb=8f6fca564dc9f568f9e553b993b8dfb61d2f9653;p=releng%2Fbuilder.git diff --git a/jjb/opendaylight-infra-copy-ssh-keys.sh b/jjb/opendaylight-infra-copy-ssh-keys.sh index 0fad4bf1c..cce929637 100644 --- a/jjb/opendaylight-infra-copy-ssh-keys.sh +++ b/jjb/opendaylight-infra-copy-ssh-keys.sh @@ -1,34 +1,53 @@ #!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2017 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## + +echo "----------> Copy ssh public keys to csit lab" + +# shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091 +source "/tmp/v/openstack/bin/activate" + function copy-ssh-keys-to-slave() { RETRIES=60 for j in $(seq 1 $RETRIES); do + # shellcheck disable=SC2006,SC2092 if `ssh-copy-id -i /home/jenkins/.ssh/id_rsa.pub "jenkins@${i}" > /dev/null 2>&1`; then - ssh jenkins@${i} 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts' + ssh "jenkins@${i}" 'echo "$(facter ipaddress_eth0) $(/bin/hostname)" | sudo tee -a /etc/hosts' echo "Successfully copied public keys to slave ${i}" break - elif [ $j -eq $RETRIES ]; then + elif [ "$j" -eq $RETRIES ]; then echo "SSH not responding on ${i} after $RETIRES tries. Giving up." exit 1 else echo "SSH not responding on ${i}. Retrying in 10 seconds..." sleep 10 fi + + # ping test to see if connectivity is available + if ping -c1 "${i}" &> /dev/null; then + echo "Ping to ${i} successful." + else + echo "Ping to ${i} failed." + fi done } -# TODO: Remove condition when we no longer use JClouds plugin -if [ -z "$JCLOUDS_IPS" ]; then - # If JCLOUDS_IPS is not set then we will spawn instances with - # OpenStack Heat. - source $WORKSPACE/.venv-openstack/bin/activate - 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[]'` - 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[]'` - ADDR=($CONTROLLER_IPS $MININET_IPS) -else - echo "OpenStack IPS are ${JCLOUDS_IPS}" - IFS=',' read -ra ADDR <<< "${JCLOUDS_IPS}" -fi +# Print the Stack outputs parameters so that we can identify which IPs belong +# to which VM types. +openstack stack show -c outputs "$STACK_NAME" +# shellcheck disable=SC2006,SC2207 +ADDR=(`openstack stack show -f json -c outputs "$STACK_NAME" | \ + jq -r '.outputs[] | \ + select(.output_key | match("^vm_[0-9]+_ips\$")) | \ + .output_value | .[]'`) pids="" for i in "${ADDR[@]}"; do ( copy-ssh-keys-to-slave ) & @@ -38,7 +57,7 @@ done # Detect when a process failed to copy ssh keys and fail build for p in $pids; do - if wait $p; then + if wait "$p"; then echo "Process $p successfully copied ssh keys." else echo "Process $p failed to copy ssh keys."