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