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