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