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