Merge "Donot exit if k8s tests fail"
[releng.git] / jjb / functest / functest-k8.sh
1 #!/bin/bash
2
3 set -e
4 set +u
5 set +o pipefail
6
7 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
8 FUNCTEST_DIR=/home/opnfv/functest
9
10 rc_file=${HOME}/k8.creds
11 sudo rm -rf $rc_file
12
13 if [[ ${INSTALLER_TYPE} == 'compass' ]]; then
14     admin_conf_file_vol="-v ${HOME}/admin.conf:/root/.kube/config"
15     echo "export KUBECONFIG=/root/.kube/config" >> $rc_file
16     echo "export KUBERNETES_PROVIDER=local" >> $rc_file
17     KUBE_MASTER_URL=$(cat ${HOME}/admin.conf|grep server| awk '{print $2}')
18     echo "export KUBE_MASTER_URL=$KUBE_MASTER_URL" >> $rc_file
19     KUBE_MASTER_IP=$(echo $KUBE_MASTER_URL|awk -F'https://|:[0-9]+' '$0=$2')
20     echo "export KUBE_MASTER_IP=$KUBE_MASTER_IP" >> $rc_file
21 elif [[ ${INSTALLER_TYPE} == 'joid' && ${BRANCH} == 'master' ]]; then
22     admin_conf_file_vol="-v ${HOME}/joid_config/config:/root/joid_config/config"
23     rc_file=${HOME}/joid_config/k8config
24 else
25     echo "Not supported by other installers yet"
26     exit 1
27 fi
28
29 rc_file_vol="-v ${rc_file}:${FUNCTEST_DIR}/conf/env_file"
30
31 dir_result="${HOME}/opnfv/functest/results/${BRANCH##*/}"
32 mkdir -p ${dir_result}
33 sudo rm -rf ${dir_result}/*
34 results_vol="-v ${dir_result}:${FUNCTEST_DIR}/results"
35
36 volumes="${rc_file_vol} ${results_vol} ${admin_conf_file_vol}"
37
38 # Set iptables rule to allow forwarding return traffic for container
39 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
40     sudo iptables -I FORWARD -j RETURN
41 fi
42
43 envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} \
44     -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \
45     -e BUILD_TAG=${BUILD_TAG} -e DEPLOY_TYPE=${DEPLOY_TYPE}"
46
47 DOCKER_TAG=`[[ ${BRANCH##*/} == "master" ]] && echo "latest" || echo ${BRANCH##*/}`
48
49 set +e
50
51 FUNCTEST_IMAGE=opnfv/functest-kubernetes:${DOCKER_TAG}
52 echo "Pulling Docker image ${FUNCTEST_IMAGE} ..."
53 docker pull ${FUNCTEST_IMAGE}>/dev/null
54 cmd_opt="run_tests -r -t all"
55 cmd="docker run --rm --privileged=true ${envs} ${volumes} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'"
56 echo "Running Functest k8s test cases, CMD: ${cmd}"
57 eval ${cmd}
58 ret_value=$?
59 if [ ${ret_value} != 0 ]; then
60   echo ${ret_value} > ${ret_val_file}
61 fi