X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=bootstrap.sh;h=2d26bccfad59ca4625b9b9512bb2d10b09ce9dde;hp=56cfbe2e157aba79a5856c20caee344194820d7f;hb=7a68b45126c805dc0e12dac41b810495a97bf88f;hpb=61b9af12c182d40cbeede66c2c9ec52c616fab03 diff --git a/bootstrap.sh b/bootstrap.sh index 56cfbe2e15..2d26bccfad 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2018 Cisco and/or its affiliates. # 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: @@ -17,26 +17,93 @@ set -x cat /etc/hostname cat /etc/hosts -export DEBIAN_FRONTEND=noninteractive -sudo apt-get -y update -sudo apt-get -y install libpython2.7-dev python-virtualenv +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export PYTHONPATH=${SCRIPT_DIR} + +OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') +OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') + +if [ "$OS_ID" == "centos" ]; then + DISTRO="CENTOS" + PACKAGE="rpm" + sudo yum install -y python-devel python-virtualenv +elif [ "$OS_ID" == "ubuntu" ]; then + DISTRO="UBUNTU" + PACKAGE="deb" + export DEBIAN_FRONTEND=noninteractive + sudo apt-get -y update + sudo apt-get -y install libpython2.7-dev python-virtualenv +else + echo "$OS_ID is not yet supported." + exit 1 +fi +# Temporarily download VPP and DPDK packages from nexus.fd.io +if [ "${#}" -ne "0" ]; then + arr=(${@}) + echo ${arr[0]} + SKIP_PATCH="skip_patchORskip_vpp_patch" +else + VPP_VERSION=$(< ${SCRIPT_DIR}/VPP_STABLE_VER_${DISTRO}) + CSIT_DIR=${SCRIPT_DIR} + source "${SCRIPT_DIR}/resources/libraries/bash/function/artifacts.sh" + download_artifacts + # Need to revert -euo as the rest of script is not optimized for this. + set +euo pipefail +fi + +VIRL_DIR_LOC="/tmp/" +VPP_PKGS=(vpp*.$PACKAGE) +VPP_PKGS_FULL=("${VPP_PKGS[@]/#/${VIRL_DIR_LOC}}") +echo ${VPP_PKGS[@]} + +VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_${DISTRO}) +VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_${DISTRO}) 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" -VIRL_TOPOLOGY=double-ring-nested.xenial -VIRL_RELEASE=csit-ubuntu-16.04.1_2016-10-10_1.4 - SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error" -TEST_GROUPS=("bridge_domain,dhcp,gre,honeycomb,l2_xconnect,lisp,softwire" "cop,telemetry,ipsec,ipv6,rpf,tap,vrf" "fds,iacl,ipv4,policer,vlan,vxlan") -SUITE_PATH="tests.func" - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +TEST_GROUPS=("crypto,ip4_tunnels.softwire,ip4_tunnels.vxlan" "ip4,ip4_tunnels.gre,ip4_tunnels.lisp,ip6_tunnels.vxlan,ip6_tunnels.lisp,vm_vhost.ip4,vm_vhost.ip6" "interfaces,ip6,l2bd,l2xc,vm_vhost.l2bd,vm_vhost.l2xc,telemetry") +SUITE_PATH="tests.vpp.func" +SKIP_PATCH="SKIP_PATCH" # Create tmp dir mkdir ${SCRIPT_DIR}/tmp @@ -47,8 +114,6 @@ LOG_PATH="${SCRIPT_DIR}/tmp" # Use tmp dir for tarballs export TMPDIR="${SCRIPT_DIR}/tmp" -SHARED_MEMORY_PATH="/run/shm" - function ssh_do() { echo echo "### " ssh $@ @@ -87,9 +152,6 @@ maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E= EOF chmod 600 ${VIRL_PKEY} -# -# Pick a random host from the array of VIRL servers for every test set run -# and attempt to reach it and verify it's status. # # The server must be reachable and have a "status" file with # the content "PRODUCTION" to be selected. @@ -99,61 +161,43 @@ chmod 600 ${VIRL_PKEY} # # Abort if there are no more servers left in the array. # -for index in "${!TEST_GROUPS[@]}"; do - VIRL_SERVER[${index}]="" - while [[ ! "${VIRL_SERVER[${index}]}" ]]; do - num_hosts=${#VIRL_SERVERS[@]} - if [ $num_hosts == 0 ] - then - echo "No more VIRL candidate hosts available, failing." - exit 127 - fi - element=$[ $RANDOM % $num_hosts ] - virl_server_candidate=${VIRL_SERVERS[$element]} - virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${virl_server_candidate} cat $VIRL_SERVER_STATUS_FILE 2>&1) - echo VIRL HOST $virl_server_candidate status is \"$virl_server_status\" - if [ "$virl_server_status" == "$VIRL_SERVER_EXPECTED_STATUS" ] - then - # Candidate is in good status. Select this server. - VIRL_SERVER[${index}]="$virl_server_candidate" - else - # Candidate is in bad status. Remove from array. - VIRL_SERVERS=("${VIRL_SERVERS[@]:0:$element}" "${VIRL_SERVERS[@]:$[$element+1]}") - fi - done +VIRL_PROD_SERVERS=() +for index in "${!VIRL_SERVERS[@]}"; do + virl_server_status=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVERS[$index]} cat $VIRL_SERVER_STATUS_FILE 2>&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 -echo "Selected VIRL servers: ${VIRL_SERVER[@]}" - -# Temporarily download VPP packages from nexus.fd.io -if [ "${#}" -ne "0" ]; then - arr=(${@}) - echo ${arr[0]} -else - rm -f *.deb - VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER) - VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL) - VPP_CLASSIFIER="-deb" - wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit - wget -q "${VPP_REPO_URL}/vpp-dbg/${VPP_STABLE_VER}/vpp-dbg-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit - wget -q "${VPP_REPO_URL}/vpp-dev/${VPP_STABLE_VER}/vpp-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit - wget -q "${VPP_REPO_URL}/vpp-dpdk-dev/${VPP_STABLE_VER}/vpp-dpdk-dev-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit - wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${VPP_STABLE_VER}/vpp-dpdk-dkms-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit - wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit - wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit +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 -VPP_DEBS=(*.deb) -echo ${VPP_DEBS[@]} -VIRL_DIR_LOC="/tmp" -VPP_DEBS_FULL=(${VPP_DEBS[@]}) +# 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 -# Prepend directory location at remote host to deb file list -for index in "${!VPP_DEBS_FULL[@]}"; do - VPP_DEBS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_DEBS_FULL[${index}]} +# 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 "Updated file names: " ${VPP_DEBS_FULL[@]} +echo "Selected VIRL servers: ${VIRL_SERVER[@]}" cat ${VIRL_PKEY} @@ -164,18 +208,18 @@ for index in "${!VIRL_SERVER[@]}"; do [[ "${DONE[@]}" =~ "${VIRL_SERVER[${index}]}" ]] && copy=0 || copy=1 if [ "${copy}" -eq "0" ]; then - echo "VPP deb files have already been copied to the VIRL host ${VIRL_SERVER[${index}]}" + echo "VPP packages have already been copied to the VIRL host ${VIRL_SERVER[${index}]}" else - scp ${SSH_OPTIONS} *.deb \ - ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/ + scp ${SSH_OPTIONS} ${VPP_PKGS[@]} \ + ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC} - result=$? + result=$? if [ "${result}" -ne "0" ]; then - echo "Failed to copy VPP deb files to VIRL host ${VIRL_SERVER[${index}]}" + echo "Failed to copy VPP packages to VIRL host ${VIRL_SERVER[${index}]}" echo ${result} exit ${result} else - echo "VPP deb files successfully copied to the VIRL host ${VIRL_SERVER[${index}]}" + echo "VPP packages successfully copied to the VIRL host ${VIRL_SERVER[${index}]}" fi DONE+=(${VIRL_SERVER[${index}]}) fi @@ -195,11 +239,22 @@ trap stop_virl_simulation EXIT for index in "${!VIRL_SERVER[@]}"; do echo "Starting simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}" - VIRL_SID[${index}]=$(ssh ${SSH_OPTIONS} \ - ${VIRL_USERNAME}@${VIRL_SERVER[${index}]} \ - "start-testcase -c ${VIRL_TOPOLOGY} -r ${VIRL_RELEASE} ${VPP_DEBS_FULL[@]}") + # Get given VIRL server limits for max. number of VMs and IPs + max_ips=$(get_max_ip_nr ${VIRL_SERVER[${index}]}) + max_ips_from_sims=$(($(get_max_sim_nr ${VIRL_SERVER[${index}]})*IPS_PER_SIMULATION)) + # Set quota to lower value + IP_QUOTA=$([ $max_ips -le $max_ips_from_sims ] && echo "$max_ips" || echo "$max_ips_from_sims") + # Start the simulation + VIRL_SID[${index}]=$(ssh ${SSH_OPTIONS} ${VIRL_USERNAME}@${VIRL_SERVER[${index}]} \ + "start-testcase -vv \ + --quota ${IP_QUOTA} \ + --copy ${VIRL_TOPOLOGY} \ + --release ${VIRL_RELEASE} \ + ${VPP_PKGS_FULL[@]}") + # TODO: remove param ${VPP_PKGS_FULL[@]} when start-testcase script is + # updated on all virl servers retval=$? - if [ "$?" -ne "0" ]; then + if [ ${retval} -ne "0" ]; then echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}" exit ${retval} fi @@ -207,7 +262,7 @@ for index in "${!VIRL_SERVER[@]}"; do echo "No VIRL session ID reported." exit 127 fi - echo "VIRL simulation started on ${VIRL_SERVER[${index}]}" + echo "VIRL simulation nr. ${index} started on ${VIRL_SERVER[${index}]}" ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\ cat /scratch/${VIRL_SID[${index}]}/topology.yaml @@ -218,7 +273,7 @@ for index in "${!VIRL_SERVER[@]}"; do topologies/enabled/topology${index}.yaml retval=$? - if [ "$?" -ne "0" ]; then + if [ ${retval} -ne "0" ]; then echo "Failed to copy topology file from VIRL simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}" exit ${retval} fi @@ -263,7 +318,8 @@ function run_test_set() { --include vm_envAND3_node_single_link_topo \ --include vm_envAND3_node_double_link_topo \ --exclude PERFTEST \ - --exclude SKIP_PATCH \ + --exclude SOFTWIRE \ + --exclude ${SKIP_PATCH} \ --noncritical EXPECTED_FAILING \ --output ${LOG_PATH}/log_test_set_run${nr} \ tests/" @@ -274,14 +330,15 @@ function run_test_set() { --include vm_envAND3_node_single_link_topo \ --include vm_envAND3_node_double_link_topo \ --exclude PERFTEST \ - --exclude SKIP_PATCH \ + --exclude SOFTWIRE \ + --exclude ${SKIP_PATCH} \ --noncritical EXPECTED_FAILING \ --output ${LOG_PATH}/log_test_set_run${nr} \ tests/ - local_run_rc=$? - echo ${local_run_rc} > ${SHARED_MEMORY_PATH}/rc_test_run${nr} + local local_run_rc=$? set -x + echo ${local_run_rc} > ${LOG_PATH}/rc_test_run${nr} } set +x @@ -327,9 +384,13 @@ RC=0 for index in "${!VIRL_SERVER[@]}"; do echo "Test_set${index} log:" cat ${LOG_PATH}/test_run${index}.log - RC_PARTIAL_RUN=$(cat ${SHARED_MEMORY_PATH}/rc_test_run${index}) + RC_PARTIAL_RUN=$(cat ${LOG_PATH}/rc_test_run${index}) + if [ -z "$RC_PARTIAL_RUN" ]; then + echo "Failed to retrieve return code from test run ${index}" + exit 1 + fi RC=$((RC+RC_PARTIAL_RUN)) - rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index} + rm -f ${LOG_PATH}/rc_test_run${index} rm -f ${LOG_PATH}/test_run${index}.log echo done