#!/bin/bash # Copyright (c) 2018 Huawei Technologies Co.,Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -x cat /etc/hostname cat /etc/hosts SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export PYTHONPATH=${SCRIPT_DIR} if [ -f "/etc/redhat-release" ]; then DISTRO="CENTOS" sudo yum install -y python-devel python-virtualenv DPDK_ARTIFACTS="" VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS) VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS) else DISTRO="UBUNTU" export DEBIAN_FRONTEND=noninteractive sudo apt-get -y update sudo apt-get -y install libpython2.7-dev python-virtualenv DPDK_ARTIFACTS="" VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU) VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU) fi VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30") IPS_PER_VIRL=( "10.30.51.28:252" "10.30.51.29:252" "10.30.51.30:252" ) SIMS_PER_VIRL=( "10.30.51.28:13" "10.30.51.29:13" "10.30.51.30:13" ) IPS_PER_SIMULATION=5 function get_max_ip_nr() { virl_server=$1 IP_VALUE="0" for item in "${IPS_PER_VIRL[@]}" ; do if [ "${item%%:*}" == "${virl_server}" ] then IP_VALUE=${item#*:} break fi done echo "$IP_VALUE" } function get_max_sim_nr() { virl_server=$1 SIM_VALUE="0" for item in "${SIMS_PER_VIRL[@]}" ; do if [ "${item%%:*}" == "${virl_server}" ] then SIM_VALUE=${item#*:} break fi done echo "$SIM_VALUE" } VIRL_USERNAME=jenkins-in VIRL_PKEY=priv_key VIRL_SERVER_STATUS_FILE="status" VIRL_SERVER_EXPECTED_STATUS="PRODUCTION" SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error" TEST_GROUPS=("func") SUITE_PATH="tests.dmm" SKIP_PATCH="SKIP_PATCH" # Create tmp dir mkdir ${SCRIPT_DIR}/tmp # Use tmp dir to store log files LOG_PATH="${SCRIPT_DIR}/tmp" # Use tmp dir for tarballs export TMPDIR="${SCRIPT_DIR}/tmp" function ssh_do() { echo echo "### " ssh $@ ssh ${SSH_OPTIONS} $@ } rm -f ${VIRL_PKEY} cat > ${VIRL_PKEY} <&1) echo VIRL HOST ${VIRL_SERVERS[$index]} status is \"$virl_server_status\" if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ] then # Candidate is in good status. Add to array. VIRL_PROD_SERVERS+=(${VIRL_SERVERS[$index]}) fi done VIRL_SERVERS=("${VIRL_PROD_SERVERS[@]}") echo "VIRL servers in production: ${VIRL_SERVERS[@]}" num_hosts=${#VIRL_SERVERS[@]} if [ $num_hosts == 0 ] then echo "No more VIRL candidate hosts available, failing." exit 127 fi # Get the LOAD of each server based on number of active simulations (testcases) VIRL_SERVER_LOAD=() for index in "${!VIRL_SERVERS[@]}"; do VIRL_SERVER_LOAD[${index}]=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVERS[$index]} "list-testcases | grep session | wc -l") done # Pick for each TEST_GROUP least loaded server VIRL_SERVER=() for index in "${!TEST_GROUPS[@]}"; do least_load_server_idx=$(echo "${VIRL_SERVER_LOAD[*]}" | tr -s ' ' '\n' | awk '{print($0" "NR)}' | sort -g -k1,1 | head -1 | cut -f2 -d' ') least_load_server=${VIRL_SERVERS[$least_load_server_idx-1]} VIRL_SERVER+=($least_load_server) # Adjusting load as we are not going run simulation immediately VIRL_SERVER_LOAD[$least_load_server_idx-1]=$((VIRL_SERVER_LOAD[$least_load_server_idx-1]+1)) done echo "Selected VIRL servers: ${VIRL_SERVER[@]}" # Temporarily download DPDK packages DMM_TAR_FILE="dmm_depends.tar.gz" cd dmm/scripts/ ./build.sh cd - mv /tmp/dpdk/dpdk-18.02.tar.xz . wget http://security.ubuntu.com/ubuntu/pool/main/n/numactl/libnuma1_2.0.11-1ubuntu1.1_amd64.deb wget http://security.ubuntu.com/ubuntu/pool/main/n/numactl/libnuma-dev_2.0.11-1ubuntu1.1_amd64.deb tar zcf ${DMM_TAR_FILE} dpdk-18.02.tar.xz ./dmm/ libnuma*.deb VIRL_DIR_LOC="/tmp" cat ${VIRL_PKEY} # Copy the files to VIRL hosts DONE="" for index in "${!VIRL_SERVER[@]}"; do # Do not copy files in case they have already been copied to the VIRL host [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1 if [ "${copy}" -eq "0" ]; then echo "DMM_TAR_FILE has already been copied to the VIRL host ${VIRL_SERVER[${index}]}" else scp ${SSH_OPTIONS} ${DMM_TAR_FILE} \ ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/ result=$? if [ "${result}" -ne "0" ]; then echo "Failed to copy DMM_TAR_FILE to VIRL host ${VIRL_SERVER[${index}]}" echo ${result} exit ${result} else echo "DMM_TAR_FILE successfully copied to the VIRL host ${VIRL_SERVER[${index}]}" fi DONE+=(${VIRL_SERVER[${index}]}) fi done # Start a simulation on VIRL server function stop_virl_simulation { for index in "${!VIRL_SERVER[@]}"; do ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\ "stop-testcase ${VIRL_SID[${index}]}" done } # Upon script exit, cle