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