[Functest] Block daily job if healthcheck fails
[releng.git] / jjb / functest / functest-alpine.sh
1 #!/bin/bash
2
3 set -e
4 set +u
5 set +o pipefail
6
7 run_tiers() {
8     cmd_opt='prepare_env start && run_tests -r -t all'
9     [[ $BUILD_TAG =~ "suite" ]] && cmd_opt='prepare_env start && run_tests -t all'
10     ret_val_file="${HOME}/opnfv/functest/results/${BRANCH##*/}/return_value"
11     echo 0 > ${ret_val_file}
12
13     for tier in ${tiers[@]}; do
14         FUNCTEST_IMAGE=opnfv/functest-${tier}
15         echo "Functest: Pulling Functest Docker image ${FUNCTEST_IMAGE} ..."
16         docker pull ${FUNCTEST_IMAGE}>/dev/null
17         cmd="docker run --privileged=true ${envs} ${volumes} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'"
18         echo "Running Functest tier '${tier}'. CMD: ${cmd}"
19         eval ${cmd}
20         ret_value=$?
21         if [ ${ret_value} != 0 ]; then
22             echo ${ret_value} > ${ret_val_file}
23             if [ ${tier} == 'healthcheck' ]; then
24                 echo "Healthcheck tier failed. Exiting Functest..."
25                 exit 1
26             fi
27         fi
28     done
29 }
30
31 run_test() {
32     test_name=$1
33     cmd_opt='prepare_env start && run_tests -r -t $test_name'
34     [[ $BUILD_TAG =~ "suite" ]] && cmd_opt='prepare_env start && run_tests -t $test_name'
35     ret_val_file="${HOME}/opnfv/functest/results/${BRANCH##*/}/return_value"
36     echo 0 > ${ret_val_file}
37     # Determine which Functest image should be used for the test case
38     case ${test_name} in
39         connection_check|api_check|snaps_health_check)
40             FUNCTEST_IMAGE=opnfv/functest-healthcheck ;;
41         vping_ssh|vping_userdata|tempest_smoke_serial|rally_sanity|refstack_defcore|odl|odl_netvirt|fds|snaps_smoke)
42             FUNCTEST_IMAGE=opnfv/functest-smoke ;;
43         tempest_full_parallel|tempest_custom|rally_full)
44             FUNCTEST_IMAGE=opnfv/functest-components ;;
45         cloudify_ims|orchestra_openims|orchestra_clearwaterims|vyos_vrouter)
46             FUNCTEST_IMAGE=opnfv/functest-vnf ;;
47         promise|doctor-notification|bgpvpn|functest-odl-sfc|domino-multinode|barometercollectd)
48             FUNCTEST_IMAGE=opnfv/functest-features ;;
49         parser)
50             FUNCTEST_IMAGE=opnfv/functest-parser ;;
51         *)
52             echo "Unkown test case $test_name"
53             exit 1
54             ;;
55     esac
56     echo "Functest: Pulling Functest Docker image ${FUNCTEST_IMAGE} ..."
57     docker pull ${FUNCTEST_IMAGE}>/dev/null
58     cmd="docker run --privileged=true ${envs} ${volumes} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'"
59     echo "Running Functest test case '${test_name}'. CMD: ${cmd}"
60     eval ${cmd}
61     ret_value=$?
62     if [ ${ret_value} != 0 ]; then
63       echo ${ret_value} > ${ret_val_file}
64     fi
65 }
66
67
68 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
69 FUNCTEST_DIR=/home/opnfv/functest
70 DEPLOY_TYPE=baremetal
71 [[ $BUILD_TAG =~ "virtual" ]] && DEPLOY_TYPE=virt
72 HOST_ARCH=$(uname -m)
73
74 # Prepare OpenStack credentials volume
75 rc_file=${HOME}/opnfv-openrc.sh
76
77 if [[ ${INSTALLER_TYPE} == 'joid' ]]; then
78     rc_file=$LAB_CONFIG/admin-openrc
79 elif [[ ${INSTALLER_TYPE} == 'compass' ]]; then
80     cacert_file_vol="-v ${HOME}/os_cacert:${FUNCTEST_DIR}/conf/os_cacert"
81     echo "export OS_CACERT=${FUNCTEST_DIR}/conf/os_cacert" >> ${HOME}/opnfv-openrc.sh
82 elif [[ ${INSTALLER_TYPE} == 'fuel' && ${DEPLOY_TYPE} == 'baremetal' ]]; then
83     cacert_file_vol="-v ${HOME}/os_cacert:/etc/ssl/certs/mcp_os_cacert"
84 fi
85 rc_file_vol="-v ${rc_file}:${FUNCTEST_DIR}/conf/openstack.creds"
86
87
88 # Set iptables rule to allow forwarding return traffic for container
89 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
90     sudo iptables -I FORWARD -j RETURN
91 fi
92
93 echo "Functest: Start Docker and prepare environment"
94
95 echo "Functest: Download images that will be used by test cases"
96 images_dir="${HOME}/opnfv/functest/images"
97 download_script=${WORKSPACE}/functest/ci/download_images.sh
98 if [[ ! -f ${download_script} ]]; then
99     # to support Danube as well
100     wget https://git.opnfv.org/functest/plain/functest/ci/download_images.sh -O ${download_script} 2> ${redirect}
101 fi
102 chmod +x ${download_script}
103 ${download_script} ${images_dir} ${DEPLOY_SCENARIO} ${HOST_ARCH} 2> ${redirect}
104
105 images_vol="-v ${images_dir}:${FUNCTEST_DIR}/images"
106
107 dir_result="${HOME}/opnfv/functest/results/${BRANCH##*/}"
108 mkdir -p ${dir_result}
109 sudo rm -rf ${dir_result}/*
110 results_vol="-v ${dir_result}:${FUNCTEST_DIR}/results"
111 custom_params=
112 test -f ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG} && custom_params=$(cat ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG})
113
114 envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP} \
115     -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \
116     -e BUILD_TAG=${BUILD_TAG} -e DEPLOY_TYPE=${DEPLOY_TYPE}"
117
118 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
119
120
121 if [ "${INSTALLER_TYPE}" == 'fuel' ]; then
122     COMPUTE_ARCH=$(ssh -l ubuntu ${INSTALLER_IP} -i ${SSH_KEY} ${ssh_options} \
123         "sudo salt 'cmp*' grains.get cpuarch --out yaml | awk '{print \$2; exit}'")
124     envs="${envs} -e POD_ARCH=${COMPUTE_ARCH}"
125 fi
126
127 volumes="${images_vol} ${results_vol} ${sshkey_vol} ${rc_file_vol} ${cacert_file_vol}"
128
129 set +e
130
131
132 if [[ ${DEPLOY_SCENARIO} =~ ^os-.* ]]; then
133     if [ ${FUNCTEST_MODE} == 'testcase' ]; then
134         echo "FUNCTEST_MODE=testcase, FUNCTEST_SUITE_NAME=${FUNCTEST_SUITE_NAME}"
135         run_test ${FUNCTEST_SUITE_NAME}
136     elif [ ${FUNCTEST_MODE} == 'tier' ]; then
137         echo "FUNCTEST_MODE=tier, FUNCTEST_TIER=${FUNCTEST_TIER}"
138         tiers=(${FUNCTEST_TIER})
139         run_tiers ${tiers}
140     else
141         if [ ${DEPLOY_TYPE} == 'baremetal' ]; then
142             tiers=(healthcheck smoke features vnf parser)
143         else
144             tiers=(healthcheck smoke features)
145         fi
146         run_tiers ${tiers}
147     fi
148 else
149     echo "k8 deployment has not been supported by functest yet"
150 fi