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