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