diff options
-rwxr-xr-x | bootstrap-centos.sh | 384 | ||||
-rwxr-xr-x | bootstrap-ubuntu.sh | 390 | ||||
-rwxr-xr-x | bootstrap.sh | 436 | ||||
-rwxr-xr-x | resources/tools/virl/bin/list-testcases | 19 | ||||
-rwxr-xr-x | resources/tools/virl/bin/start-testcase | 85 |
5 files changed, 529 insertions, 785 deletions
diff --git a/bootstrap-centos.sh b/bootstrap-centos.sh deleted file mode 100755 index b7c6891ef6..0000000000 --- a/bootstrap-centos.sh +++ /dev/null @@ -1,384 +0,0 @@ -#!/bin/bash -# Copyright (c) 2016 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: -# -# 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 - -sudo yum install -y python-devel python-virtualenv - -VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30") - -VIRL_USERNAME=jenkins-in -VIRL_PKEY=priv_key -VIRL_SERVER_STATUS_FILE="status" -VIRL_SERVER_EXPECTED_STATUS="PRODUCTION" - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS) -VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS) - -SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error" - -TEST_GROUPS=("gre,ipv6,lisp,policer,rpf,softwire" "dhcp,ipsec,l2bd,l2xc,telemetry,vrf,vxlan" "cop,fds,honeycomb,iacl,ipv4,tap,vhost,vlan") -SUITE_PATH="tests.func" -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" - -SHARED_MEMORY_PATH="/dev/shm" - -function ssh_do() { - echo - echo "### " ssh $@ - ssh ${SSH_OPTIONS} $@ -} - -rm -f ${VIRL_PKEY} -cat > ${VIRL_PKEY} <<EOF ------BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6 -GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX -VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9 -asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz -L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J -73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76 -gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb -4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN -e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV -SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J -kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI -ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa -MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY -RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa -YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0 -2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab -UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV -IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I -wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS -NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM -xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj -yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS -U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ -cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh -maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E= ------END RSA PRIVATE KEY----- -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. -# -# If the server is not reachable or does not have the correct -# status remove it from the array and start again. -# -# 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 -done - -echo "Selected VIRL servers: ${VIRL_SERVER[@]}" - -# Temporarily download VPP packages from nexus.fd.io -VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_CENTOS) -VPP_CLASSIFIER="" -if [ "${#}" -ne "0" ]; then - arr=(${@}) - echo ${arr[0]} - SKIP_PATCH="skip_patchORskip_vpp_patch" -else - rm -f *.rpm - VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_CENTOS) - wget -q "${VPP_REPO_URL}/vpp/${VPP_STABLE_VER}/vpp-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit - wget -q "${VPP_REPO_URL}/vpp-debuginfo/${VPP_STABLE_VER}/vpp-debuginfo-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit - wget -q "${VPP_REPO_URL}/vpp-devel/${VPP_STABLE_VER}/vpp-devel-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit - wget -q "${VPP_REPO_URL}/vpp-lib/${VPP_STABLE_VER}/vpp-lib-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit - wget -q "${VPP_REPO_URL}/vpp-plugins/${VPP_STABLE_VER}/vpp-plugins-${VPP_STABLE_VER}${VPP_CLASSIFIER}.rpm" || exit -fi - -VPP_RPMS=(*.rpm) -echo ${VPP_RPMS[@]} -VIRL_DIR_LOC="/tmp" -VPP_RPMS_FULL=(${VPP_RPMS[@]}) - -# Prepend directory location at remote host to rpm list -for index in "${!VPP_RPMS_FULL[@]}"; do - VPP_RPMS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_RPMS_FULL[${index}]} -done - -echo "Updated file names: " ${VPP_RPMS_FULL[@]} - -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 "VPP rpms have already been copied to the VIRL host ${VIRL_SERVER[${index}]}" - else - scp ${SSH_OPTIONS} *.rpm \ - ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/ - - result=$? - if [ "${result}" -ne "0" ]; then - echo "Failed to copy VPP rpms to VIRL host ${VIRL_SERVER[${index}]}" - echo ${result} - exit ${result} - else - echo "VPP rpms 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, cleanup the simulation execution -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 -vv --copy ${VIRL_TOPOLOGY} \ - --release ${VIRL_RELEASE} ${VPP_RPMS_FULL[@]}") - retval=$? - if [ ${retval} -ne "0" ]; then - echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}" - exit ${retval} - fi - if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then - echo "No VIRL session ID reported." - exit 127 - fi - echo "VIRL simulation started on ${VIRL_SERVER[${index}]}" - - ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\ - cat /scratch/${VIRL_SID[${index}]}/topology.yaml - - # Download the topology file from VIRL session and rename it - scp ${SSH_OPTIONS} \ - ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \ - topologies/enabled/topology${index}.yaml - - retval=$? - 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 -done - -echo ${VIRL_SID[@]} - -virtualenv --system-site-packages env -. env/bin/activate - -echo pip install -pip install -r ${SCRIPT_DIR}/requirements.txt - -for index in "${!VIRL_SERVER[@]}"; do - pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \ - -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \ - -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \ - -vvv - if [ "$?" -ne "0" ]; then - echo "Topology${index} schema validation failed." - echo "However, the tests will start." - fi -done - -function run_test_set() { - set +x - OLDIFS=$IFS - IFS="," - nr=$(echo $1) - rm -f ${LOG_PATH}/test_run${nr}.log - exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \ - >> ${LOG_PATH}/test_run${nr}.log; done;) - suite_str="" - for suite in ${TEST_GROUPS[${nr}]}; do - suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}" - done - IFS=$OLDIFS - - echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\ - -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \ - ${suite_str} \ - --include vm_envAND3_node_single_link_topo \ - --include vm_envAND3_node_double_link_topo \ - --exclude PERFTEST \ - --exclude ${SKIP_PATCH} \ - --noncritical EXPECTED_FAILING \ - --output ${LOG_PATH}/log_test_set_run${nr} \ - tests/" - - PYTHONPATH=`pwd` pybot -L TRACE -W 136\ - -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \ - ${suite_str} \ - --include vm_envAND3_node_single_link_topo \ - --include vm_envAND3_node_double_link_topo \ - --exclude PERFTEST \ - --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} - set -x -} - -set +x -# Send to background an instance of the run_test_set() function for each number, -# record the pid. -for index in "${!VIRL_SERVER[@]}"; do - run_test_set ${index} & - pid=$! - echo "Sent to background: Test_set${index} (pid=$pid)" - pids[$pid]=$index -done - -echo -echo -n "Waiting..." - -# Watch the stable of background processes. -# If a pid goes away, remove it from the array. -while [ -n "${pids[*]}" ]; do - for i in $(seq 0 9); do - sleep 1 - echo -n "." - done - for pid in "${!pids[@]}"; do - if ! ps "$pid" >/dev/null; then - echo -e "\n" - echo "Test_set${pids[$pid]} with PID $pid finished." - unset pids[$pid] - fi - done - if [ -z "${!pids[*]}" ]; then - break - fi - echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..." -done - -echo -echo "All test set runs finished." -echo - -set -x - -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=$((RC+RC_PARTIAL_RUN)) - rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index} - rm -f ${LOG_PATH}/test_run${index}.log - echo -done - -# Log the final result -if [ "${RC}" -eq "0" ]; then - set +x - echo - echo "========================================================================================================================================" - echo "Final result of all test loops: | PASS |" - echo "All critical tests have passed." - echo "========================================================================================================================================" - echo - set -x -else - if [ "${RC}" -eq "1" ]; then - HLP_STR="test has" - else - HLP_STR="tests have" - fi - set +x - echo - echo "========================================================================================================================================" - echo "Final result of all test loops: | FAIL |" - echo "${RC} critical ${HLP_STR} failed." - echo "========================================================================================================================================" - echo - set -x -fi - -echo Post-processing test data... - -partial_logs="" -for index in "${!VIRL_SERVER[@]}"; do - partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml" -done - -# Rebot output post-processing -rebot --noncritical EXPECTED_FAILING \ - --output output.xml ${partial_logs} - -# Remove unnecessary log files -rm -f ${partial_logs} - -echo Post-processing finished. - -if [ ${RC} -eq 0 ]; then - RETURN_STATUS=0 -else - RETURN_STATUS=1 -fi - -exit ${RETURN_STATUS} diff --git a/bootstrap-ubuntu.sh b/bootstrap-ubuntu.sh deleted file mode 100755 index e99a6088d4..0000000000 --- a/bootstrap-ubuntu.sh +++ /dev/null @@ -1,390 +0,0 @@ -#!/bin/bash -# Copyright (c) 2016 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: -# -# 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 - -export DEBIAN_FRONTEND=noninteractive -sudo apt-get -y update -sudo apt-get -y install libpython2.7-dev python-virtualenv - -VIRL_SERVERS=("10.30.51.28" "10.30.51.29" "10.30.51.30") - -VIRL_USERNAME=jenkins-in -VIRL_PKEY=priv_key -VIRL_SERVER_STATUS_FILE="status" -VIRL_SERVER_EXPECTED_STATUS="PRODUCTION" - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU) -VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU) - -SSH_OPTIONS="-i ${VIRL_PKEY} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=error" - -TEST_GROUPS=("gre,ipv6,lisp,policer,rpf,softwire" "dhcp,ipsec,l2bd,l2xc,telemetry,vrf,vxlan" "cop,fds,honeycomb,iacl,ipv4,tap,vhost,vlan") -SUITE_PATH="tests.func" -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" - -SHARED_MEMORY_PATH="/run/shm" - -function ssh_do() { - echo - echo "### " ssh $@ - ssh ${SSH_OPTIONS} $@ -} - -rm -f ${VIRL_PKEY} -cat > ${VIRL_PKEY} <<EOF ------BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6 -GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX -VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9 -asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz -L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J -73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76 -gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb -4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN -e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV -SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J -kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI -ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa -MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY -RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa -YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0 -2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab -UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV -IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I -wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS -NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM -xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj -yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS -U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ -cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh -maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E= ------END RSA PRIVATE KEY----- -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. -# -# If the server is not reachable or does not have the correct -# status remove it from the array and start again. -# -# 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 -done - -echo "Selected VIRL servers: ${VIRL_SERVER[@]}" - -# Temporarily download VPP and DPDK packages from nexus.fd.io -DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)_amd64 -VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_UBUNTU) -VPP_CLASSIFIER="-deb" -if [ "${#}" -ne "0" ]; then - arr=(${@}) - echo ${arr[0]} - SKIP_PATCH="skip_patchORskip_vpp_patch" - # Download DPDK parts not included in dpdk plugin of vpp build - wget -q "${VPP_REPO_URL}/vpp-dpdk-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.deb" || exit -else - rm -f *.deb - VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU) - 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-dkms/${DPDK_STABLE_VER}/vpp-dpdk-dkms-${DPDK_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 -fi - -VPP_DEBS=(*.deb) -echo ${VPP_DEBS[@]} -VIRL_DIR_LOC="/tmp" -VPP_DEBS_FULL=(${VPP_DEBS[@]}) - -# 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}]} -done - -echo "Updated file names: " ${VPP_DEBS_FULL[@]} - -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 "VPP deb files have already been copied to the VIRL host ${VIRL_SERVER[${index}]}" - else - scp ${SSH_OPTIONS} *.deb \ - ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/ - - result=$? - if [ "${result}" -ne "0" ]; then - echo "Failed to copy VPP deb files to VIRL host ${VIRL_SERVER[${index}]}" - echo ${result} - exit ${result} - else - echo "VPP deb files 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, cleanup the simulation execution -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 -vv --copy ${VIRL_TOPOLOGY} \ - --release ${VIRL_RELEASE} ${VPP_DEBS_FULL[@]}") - retval=$? - if [ ${retval} -ne "0" ]; then - echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}" - exit ${retval} - fi - if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then - echo "No VIRL session ID reported." - exit 127 - fi - echo "VIRL simulation started on ${VIRL_SERVER[${index}]}" - - ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\ - cat /scratch/${VIRL_SID[${index}]}/topology.yaml - - # Download the topology file from VIRL session and rename it - scp ${SSH_OPTIONS} \ - ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \ - topologies/enabled/topology${index}.yaml - - retval=$? - 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 -done - -echo ${VIRL_SID[@]} - -virtualenv --system-site-packages env -. env/bin/activate - -echo pip install -pip install -r ${SCRIPT_DIR}/requirements.txt - -for index in "${!VIRL_SERVER[@]}"; do - pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \ - -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \ - -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \ - -vvv - if [ "$?" -ne "0" ]; then - echo "Topology${index} schema validation failed." - echo "However, the tests will start." - fi -done - -function run_test_set() { - set +x - OLDIFS=$IFS - IFS="," - nr=$(echo $1) - rm -f ${LOG_PATH}/test_run${nr}.log - exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \ - >> ${LOG_PATH}/test_run${nr}.log; done;) - suite_str="" - for suite in ${TEST_GROUPS[${nr}]}; do - suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}" - done - IFS=$OLDIFS - - echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\ - -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \ - ${suite_str} \ - --include vm_envAND3_node_single_link_topo \ - --include vm_envAND3_node_double_link_topo \ - --exclude PERFTEST \ - --exclude ${SKIP_PATCH} \ - --noncritical EXPECTED_FAILING \ - --output ${LOG_PATH}/log_test_set_run${nr} \ - tests/" - - PYTHONPATH=`pwd` pybot -L TRACE -W 136\ - -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \ - ${suite_str} \ - --include vm_envAND3_node_single_link_topo \ - --include vm_envAND3_node_double_link_topo \ - --exclude PERFTEST \ - --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} - set -x -} - -set +x -# Send to background an instance of the run_test_set() function for each number, -# record the pid. -for index in "${!VIRL_SERVER[@]}"; do - run_test_set ${index} & - pid=$! - echo "Sent to background: Test_set${index} (pid=$pid)" - pids[$pid]=$index -done - -echo -echo -n "Waiting..." - -# Watch the stable of background processes. -# If a pid goes away, remove it from the array. -while [ -n "${pids[*]}" ]; do - for i in $(seq 0 9); do - sleep 1 - echo -n "." - done - for pid in "${!pids[@]}"; do - if ! ps "$pid" >/dev/null; then - echo -e "\n" - echo "Test_set${pids[$pid]} with PID $pid finished." - unset pids[$pid] - fi - done - if [ -z "${!pids[*]}" ]; then - break - fi - echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..." -done - -echo -echo "All test set runs finished." -echo - -set -x - -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=$((RC+RC_PARTIAL_RUN)) - rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index} - rm -f ${LOG_PATH}/test_run${index}.log - echo -done - -# Log the final result -if [ "${RC}" -eq "0" ]; then - set +x - echo - echo "========================================================================================================================================" - echo "Final result of all test loops: | PASS |" - echo "All critical tests have passed." - echo "========================================================================================================================================" - echo - set -x -else - if [ "${RC}" -eq "1" ]; then - HLP_STR="test has" - else - HLP_STR="tests have" - fi - set +x - echo - echo "========================================================================================================================================" - echo "Final result of all test loops: | FAIL |" - echo "${RC} critical ${HLP_STR} failed." - echo "========================================================================================================================================" - echo - set -x -fi - -echo Post-processing test data... - -partial_logs="" -for index in "${!VIRL_SERVER[@]}"; do - partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml" -done - -# Rebot output post-processing -rebot --noncritical EXPECTED_FAILING \ - --output output.xml ${partial_logs} - -# Remove unnecessary log files -rm -f ${partial_logs} - -echo Post-processing finished. - -if [ ${RC} -eq 0 ]; then - RETURN_STATUS=0 -else - RETURN_STATUS=1 -fi - -exit ${RETURN_STATUS} diff --git a/bootstrap.sh b/bootstrap.sh index 9c4c467753..b7525754fc 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -18,9 +18,441 @@ cat /etc/hostname cat /etc/hosts SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export PYTHONPATH=${SCRIPT_DIR} if [ -f "/etc/redhat-release" ]; then - ${SCRIPT_DIR}/bootstrap-centos.sh $@ + DISTRO="CENTOS" + sudo yum install -y python-devel python-virtualenv + VPP_ARTIFACTS="vpp vpp-debuginfo vpp-devel vpp-lib vpp-plugins" + DPDK_ARTIFACTS="" + PACKAGE="rpm" + VPP_CLASSIFIER="" + DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER).x86_64 + VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_CENTOS) + VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_CENTOS) + VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_CENTOS) + VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_CENTOS) + SHARED_MEMORY_PATH="/dev/shm" else - ${SCRIPT_DIR}/bootstrap-ubuntu.sh $@ + DISTRO="UBUNTU" + export DEBIAN_FRONTEND=noninteractive + sudo apt-get -y update + sudo apt-get -y install libpython2.7-dev python-virtualenv + VPP_ARTIFACTS="vpp vpp-dbg vpp-dev vpp-lib vpp-plugins" + DPDK_ARTIFACTS="vpp-dpdk-dkms" + PACKAGE="deb" + VPP_CLASSIFIER="-deb" + DPDK_STABLE_VER=$(cat ${SCRIPT_DIR}/DPDK_STABLE_VER)_amd64 + VPP_REPO_URL=$(cat ${SCRIPT_DIR}/VPP_REPO_URL_UBUNTU) + VPP_STABLE_VER=$(cat ${SCRIPT_DIR}/VPP_STABLE_VER_UBUNTU) + VIRL_TOPOLOGY=$(cat ${SCRIPT_DIR}/VIRL_TOPOLOGY_UBUNTU) + VIRL_RELEASE=$(cat ${SCRIPT_DIR}/VIRL_RELEASE_UBUNTU) + SHARED_MEMORY_PATH="/run/shm" 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:74" + "10.30.51.30:74" ) +VMS_PER_VIRL=( "10.30.51.28:36" + "10.30.51.29:36" + "10.30.51.30:36" ) +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_vm_nr() { + virl_server=$1 + VM_VALUE="0" + for item in "${VMS_PER_VIRL[@]}" ; do + if [ "${item%%:*}" == "${virl_server}" ] + then + VM_VALUE=${item#*:} + break + fi + done + echo "$VM_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=("gre,ipv6,lisp,policer,rpf,softwire" "dhcp,ipsec,l2bd,l2xc,telemetry,vrf,vxlan" "cop,fds,honeycomb,iacl,ipv4,tap,vhost,vlan") +SUITE_PATH="tests.func" +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} <<EOF +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEA+IHXq87GcqMR1C47rzx6Cbip5Ghq8pKrbqKrP5Nf41HcYrT6 +GOXl9nFWKsMOzIlIn+8y7Il27eZh7csQGApbg8QLiHMtcYEmWNzKZpkqg4nuAPxX +VXwlKgnKX902SrET9Gp9TDayiHtCRWVfrlPPPSA0UEXW6BjLN/uHJ+W/Xzrrab+9 +asBVa05vT2W6n0KJ66zfCaeDM912mQ6SttscAwFoWDmdHlegiVqrlIG2ABxOvxxz +L3dM3iSmlmQlzv9bThjo+nI4KFYh6m5wrZmAo5r/4q9CIJc21HVnTqkGOWJIZz6J +73lePJVSq5gYqaoGw3swFEA/MDkOx7baWKSoLQIDAQABAoIBAQCNBeolNp+JWJ76 +gQ4fwLsknyXSV6sxYyhkDW4PEwwcTU06uqce0AAzXVffxne0fMe48x47+zqBgPbb +4huM+Pu8B9nfojUMr5TaYtl9Zbgpk3F8H7dT7LKOa6XrxvZTZrADSRc30+Z26zPN +e9zTaf42Gvt0/l0Zs1BHwbaOXqO+XuwJ3/F9Sf3PQYWXD3EOWjpHDP/X/1vAs6lV +SLkm6J/9KKE1m6I6LTYjIXuYt4SXybW6N2TSy54hhQtYcDUnIU2hR/PHVWKrGA0J +kELgrtTNTdbML27O5gFWU4PLUEYTZ9fN11D6qUZKxLcPOiPPHXkiILMRCCnG5DYI +ksBAU/YlAoGBAPxZO9VO18TYc8THV1nLKcvT2+1oSs1UcA2wNQMU55t910ZYinRa +MRwUhMOf8Mv5wOeiZaRICQB1PnVWtDVmGECgPpK6jUxqAwn8rgJcnoafLGL5YKMY +RVafTe6N5LXgCaOcJrk21wxs6v7ninEbUxxc575urOvZMBkymDw91dwbAoGBAPwa +YRhKhrzFKZzdK0RadVjnxKvolUllpoqqg3XuvmeAJHAOAnaOgVWq68NAcp5FZJv0 +2D2Up7TX8pjf9MofP1SJbcraKBpK4NzfNkA0dSdEi+FhVofAJ9umB2o5LW1n7sab +UIrjsdzSJK/9Zb9yTTHPyibYzNEgaJV1HsbxfEFXAoGAYO2RmvRm0phll18OQVJV +IpKk9kLKAKZ/R/K32hAsikBC8SVPQTPniyaifFWx81diblalff2hX4ipTf7Yx24I +wMIMZuW7Im/R7QMef4+94G3Bad7p7JuE/qnAEHJ2OBnu+eYfxaK35XDsrq6XMazS +NqHE7hOq3giVfgg+C12hCKMCgYEAtu9dbYcG5owbehxzfRI2/OCRsjz/t1bv1seM +xVMND4XI6xb/apBWAZgZpIFrqrWoIBM3ptfsKipZe91ngBPUnL9s0Dolx452RVAj +yctHB8uRxWYgqDkjsxtzXf1HnZBBkBS8CUzYj+hdfuddoeKLaY3invXLCiV+PpXS +U4KAK9kCgYEAtSv0m5+Fg74BbAiFB6kCh11FYkW94YI6B/E2D/uVTD5dJhyEUFgZ +cWsudXjMki8734WSpMBqBp/J8wG3C9ZS6IpQD+U7UXA+roB7Qr+j4TqtWfM+87Rh +maOpG56uAyR0w5Z9BhwzA3VakibVk9KwDgZ29WtKFzuATLFnOtCS46E= +-----END RSA PRIVATE KEY----- +EOF +chmod 600 ${VIRL_PKEY} + +# +# The server must be reachable and have a "status" file with +# the content "PRODUCTION" to be selected. +# +# If the server is not reachable or does not have the correct +# status remove it from the array and start again. +# +# Abort if there are no more servers left in the array. +# +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 + +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 VPP and DPDK packages from nexus.fd.io +if [ "${#}" -ne "0" ]; then + arr=(${@}) + echo ${arr[0]} + SKIP_PATCH="skip_patchORskip_vpp_patch" + # Download DPDK parts not included in dpdk plugin of vpp build + for ARTIFACT in ${DPDK_ARTIFACTS}; do + wget -q "${VPP_REPO_URL}/${ARTIFACT}/${DPDK_STABLE_VER}/${ARTIFACT}-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.${PACKAGE}" || exit + done +else + rm -f *.${PACKAGE} + for ARTIFACT in ${DPDK_ARTIFACTS}; do + wget -q "${VPP_REPO_URL}/${ARTIFACT}/${DPDK_STABLE_VER}/${ARTIFACT}-${DPDK_STABLE_VER}${VPP_CLASSIFIER}.${PACKAGE}" || exit + done + for ARTIFACT in ${VPP_ARTIFACTS}; do + wget -q "${VPP_REPO_URL}/${ARTIFACT}/${VPP_STABLE_VER}/${ARTIFACT}-${VPP_STABLE_VER}${VPP_CLASSIFIER}.${PACKAGE}" || exit + done +fi + +VPP_PKGS=(*.$PACKAGE) +echo ${VPP_PKGS[@]} +VIRL_DIR_LOC="/tmp" +VPP_PKGS_FULL=(${VPP_PKGS[@]}) + +# Prepend directory location at remote host to package file list +for index in "${!VPP_PKGS_FULL[@]}"; do + VPP_PKGS_FULL[${index}]=${VIRL_DIR_LOC}/${VPP_PKGS_FULL[${index}]} +done + +echo "Updated file names: " ${VPP_PKGS_FULL[@]} + +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 "VPP packages have already been copied to the VIRL host ${VIRL_SERVER[${index}]}" + else + scp ${SSH_OPTIONS} *.${PACKAGE} \ + ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:${VIRL_DIR_LOC}/ + + result=$? + if [ "${result}" -ne "0" ]; then + echo "Failed to copy VPP packages to VIRL host ${VIRL_SERVER[${index}]}" + echo ${result} + exit ${result} + else + echo "VPP packages 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, cleanup the simulation execution +trap stop_virl_simulation EXIT + +for index in "${!VIRL_SERVER[@]}"; do + echo "Starting simulation nr. ${index} on VIRL server ${VIRL_SERVER[${index}]}" + # Get given VIRL server limits for max. number of VMs and IPs + max_ips=$(get_max_ip_nr ${VIRL_SERVER[${index}]}) + max_ips_from_vms=$(($(get_max_vm_nr ${VIRL_SERVER[${index}]})*IPS_PER_SIMULATION)) + # Set quota to lower value + IP_QUOTA=$([ $max_ips -le $max_ips_from_vms ] && echo "$max_ips" || echo "$max_ips_from_vms") + # 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[@]}") + retval=$? + if [ ${retval} -ne "0" ]; then + echo "VIRL simulation start failed on ${VIRL_SERVER[${index}]}" + exit ${retval} + fi + if [[ ! "${VIRL_SID[${index}]}" =~ session-[a-zA-Z0-9_]{6} ]]; then + echo "No VIRL session ID reported." + exit 127 + fi + echo "VIRL simulation nr. ${index} started on ${VIRL_SERVER[${index}]}" + + ssh_do ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}\ + cat /scratch/${VIRL_SID[${index}]}/topology.yaml + + # Download the topology file from VIRL session and rename it + scp ${SSH_OPTIONS} \ + ${VIRL_USERNAME}@${VIRL_SERVER[${index}]}:/scratch/${VIRL_SID[${index}]}/topology.yaml \ + topologies/enabled/topology${index}.yaml + + retval=$? + 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 +done + +echo ${VIRL_SID[@]} + +virtualenv --system-site-packages env +. env/bin/activate + +echo pip install +pip install -r ${SCRIPT_DIR}/requirements.txt + +for index in "${!VIRL_SERVER[@]}"; do + pykwalify -s ${SCRIPT_DIR}/resources/topology_schemas/3_node_topology.sch.yaml \ + -s ${SCRIPT_DIR}/resources/topology_schemas/topology.sch.yaml \ + -d ${SCRIPT_DIR}/topologies/enabled/topology${index}.yaml \ + -vvv + if [ "$?" -ne "0" ]; then + echo "Topology${index} schema validation failed." + echo "However, the tests will start." + fi +done + +function run_test_set() { + set +x + OLDIFS=$IFS + IFS="," + nr=$(echo $1) + rm -f ${LOG_PATH}/test_run${nr}.log + exec &> >(while read line; do echo "$(date +'%H:%M:%S') $line" \ + >> ${LOG_PATH}/test_run${nr}.log; done;) + suite_str="" + for suite in ${TEST_GROUPS[${nr}]}; do + suite_str="${suite_str} --suite ${SUITE_PATH}.${suite}" + done + IFS=$OLDIFS + + echo "PYTHONPATH=`pwd` pybot -L TRACE -W 136\ + -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \ + ${suite_str} \ + --include vm_envAND3_node_single_link_topo \ + --include vm_envAND3_node_double_link_topo \ + --exclude PERFTEST \ + --exclude ${SKIP_PATCH} \ + --noncritical EXPECTED_FAILING \ + --output ${LOG_PATH}/log_test_set_run${nr} \ + tests/" + + PYTHONPATH=`pwd` pybot -L TRACE -W 136\ + -v TOPOLOGY_PATH:${SCRIPT_DIR}/topologies/enabled/topology${nr}.yaml \ + ${suite_str} \ + --include vm_envAND3_node_single_link_topo \ + --include vm_envAND3_node_double_link_topo \ + --exclude PERFTEST \ + --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} + set -x +} + +set +x +# Send to background an instance of the run_test_set() function for each number, +# record the pid. +for index in "${!VIRL_SERVER[@]}"; do + run_test_set ${index} & + pid=$! + echo "Sent to background: Test_set${index} (pid=$pid)" + pids[$pid]=$index +done + +echo +echo -n "Waiting..." + +# Watch the stable of background processes. +# If a pid goes away, remove it from the array. +while [ -n "${pids[*]}" ]; do + for i in $(seq 0 9); do + sleep 1 + echo -n "." + done + for pid in "${!pids[@]}"; do + if ! ps "$pid" >/dev/null; then + echo -e "\n" + echo "Test_set${pids[$pid]} with PID $pid finished." + unset pids[$pid] + fi + done + if [ -z "${!pids[*]}" ]; then + break + fi + echo -n -e "\nStill waiting for test set(s): ${pids[*]} ..." +done + +echo +echo "All test set runs finished." +echo + +set -x + +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=$((RC+RC_PARTIAL_RUN)) + rm -f ${SHARED_MEMORY_PATH}/rc_test_run${index} + rm -f ${LOG_PATH}/test_run${index}.log + echo +done + +# Log the final result +if [ "${RC}" -eq "0" ]; then + set +x + echo + echo "========================================================================================================================================" + echo "Final result of all test loops: | PASS |" + echo "All critical tests have passed." + echo "========================================================================================================================================" + echo + set -x +else + if [ "${RC}" -eq "1" ]; then + HLP_STR="test has" + else + HLP_STR="tests have" + fi + set +x + echo + echo "========================================================================================================================================" + echo "Final result of all test loops: | FAIL |" + echo "${RC} critical ${HLP_STR} failed." + echo "========================================================================================================================================" + echo + set -x +fi + +echo Post-processing test data... + +partial_logs="" +for index in "${!VIRL_SERVER[@]}"; do + partial_logs="${partial_logs} ${LOG_PATH}/log_test_set_run${index}.xml" +done + +# Rebot output post-processing +rebot --noncritical EXPECTED_FAILING \ + --output output.xml ${partial_logs} + +# Remove unnecessary log files +rm -f ${partial_logs} + +echo Post-processing finished. + +if [ ${RC} -eq 0 ]; then + RETURN_STATUS=0 +else + RETURN_STATUS=1 +fi + +exit ${RETURN_STATUS} diff --git a/resources/tools/virl/bin/list-testcases b/resources/tools/virl/bin/list-testcases new file mode 100755 index 0000000000..73c05303fe --- /dev/null +++ b/resources/tools/virl/bin/list-testcases @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright (c) 2017 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: +# +# 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. + +VIRL_USER="tb4-virl" # VIRL credentials (what one would enter in VMMaestro) +VIRL_PASSWORD="Cisco1234" + +virl_std_client --json --quiet -u $VIRL_USER -p $VIRL_PASSWORD simengine-list diff --git a/resources/tools/virl/bin/start-testcase b/resources/tools/virl/bin/start-testcase index 0d9c49e049..f6c3cc32b8 100755 --- a/resources/tools/virl/bin/start-testcase +++ b/resources/tools/virl/bin/start-testcase @@ -17,18 +17,21 @@ __author__ = 'ckoester@cisco.com' -import sys -import re -import os import argparse -import tempfile +import netifaces +import os +import paramiko +import random +import re import shutil +import sys +import tempfile import time -import paramiko -import netifaces import requests +IPS_PER_SIMULATION = 5 + def indent(lines, amount, fillchar=' '): """Indent the string by amount of fill chars. @@ -57,6 +60,66 @@ def print_to_stderr(msg, end='\n'): except ValueError: pass +def get_assigned_interfaces(args, network="flat"): + """Retrieve assigned interfaces in openstack network. + + :param args: Command line params. + :param network: Openstack network. + :type args: ArgumentParser + :type network: str + :returns: Assigned interfaces. + :rtype: list + :raises RuntimeError: If response is not 200. + """ + req = requests.get('http://{}/openstack/rest/ports/{}' + .format(args.virl_ip, network), + auth=(args.username, args.password)) + if req.status_code == 200: + return req.json() + else: + raise RuntimeError("ERROR: Retrieving ports in use - " + "Status other than 200 HTTP OK:\n{}" + .format(req.content)) + +def get_assigned_interfaces_count(args, network="flat"): + """Count assigned interfaces in openstack network. + + :param args: Command line params. + :param network: Openstack network. + :type args: ArgumentParser + :type network: str + :returns: Assigned interfaces count. + :rtype: int + """ + return len(get_assigned_interfaces(args, network=network)) + +def check_ip_addresses(args): + """Check IP address availability. + + :param args: Command line params. + :type args: ArgumentParser + :raises RuntimeError: If not enough free addresses available. + """ + for i in range(args.wait_count): + if (args.quota - \ + get_assigned_interfaces_count(args) >= IPS_PER_SIMULATION): + break + if args.verbosity >= 2: + print_to_stderr("DEBUG: - Attempt {} out of {}, waiting for free " + "IP addresses".format(i, args.wait_count)) + # Wait random amount of time within range 1-3 minutes + time.sleep(random.randint(60,180)) + else: + raise RuntimeError("ERROR: Not enough IP addresses to run simulation") + +def check_virl_resources(args): + """Check virl resources availability. + + :param args: Command line params. + :type args: ArgumentParser + """ + check_ip_addresses(args) + # # FIXME: Right now, this is really coded like a shell script, as one big # function executed in sequence. This should be broken down into multiple @@ -123,6 +186,9 @@ def main(): default="csit-ubuntu-16.04.1_2016-12-19_1.6") parser.add_argument("--topology-directory", help="Topology directory", default="/home/jenkins-in/testcase-infra/topologies") + parser.add_argument("-q", "--quota", + help="VIRL quota for max number of allowed IPs", + type=int, default=74) args = parser.parse_args() @@ -181,6 +247,7 @@ def main(): try: data = open(temp_topology, 'rb') + check_virl_resources(args) req = requests.post('http://' + args.virl_ip + '/simengine/rest/launch', auth=(args.username, args.password), data=data) @@ -310,7 +377,7 @@ def main(): shutil.rmtree(scratch_directory) except shutil.Error: print_to_stderr("ERROR: Removing scratch directory") - print "{}".format(session_id) + print "{}".format(session_id) sys.exit(1) if args.verbosity >= 2: @@ -348,7 +415,7 @@ def main(): shutil.rmtree(scratch_directory) except shutil.Error: print_to_stderr("ERROR: Removing scratch directory") - print "{}".format(session_id) + print "{}".format(session_id) sys.exit(1) data = req.json() @@ -423,7 +490,7 @@ def main(): shutil.rmtree(scratch_directory) except shutil.Error: print_to_stderr("ERROR: Removing scratch directory") - print "{}".format(session_id) + print "{}".format(session_id) sys.exit(1) # |