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