Merge "Create Stable Branch Jobs for bottlenecks"
[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 DOCKER_TAG=${DOCKER_TAG:-$([[ ${BRANCH##*/} == "master" ]] && echo "latest" || echo ${BRANCH##*/})}
12
13 check_os_deployment() {
14     FUNCTEST_IMAGE=${REPO}/functest-healthcheck:${DOCKER_TAG}
15     echo "Functest: Pulling Functest Docker image ${FUNCTEST_IMAGE} ..."
16     docker pull ${FUNCTEST_IMAGE}>/dev/null
17     cmd="docker run --rm ${volumes} ${FUNCTEST_IMAGE} check_deployment"
18     echo "Checking deployment, CMD: ${cmd}"
19     eval ${cmd}
20     ret_value=$?
21     if [ ${ret_value} != 0 ]; then
22         echo "ERROR: Problem while checking OpenStack deployment."
23         exit 1
24     else
25         echo "OpenStack deployment OK."
26     fi
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     for tier in ${tiers[@]}; do
35         FUNCTEST_IMAGE=${REPO}/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  ${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                 skip_tests=1
47                 break
48             fi
49         fi
50     done
51 }
52
53 run_test() {
54     test_name=$1
55     cmd_opt="run_tests -t ${test_name}"
56     # Determine which Functest image should be used for the test case
57     case ${test_name} in
58         connection_check|tenantnetwork1|tenantnetwork2|vmready1|vmready2|singlevm1|singlevm2|vping_ssh|vping_userdata|cinder_test|odl|api_check|snaps_health_check)
59             FUNCTEST_IMAGE=${REPO}/functest-healthcheck:${DOCKER_TAG} ;;
60         tempest_smoke_serial|tempest_smoke|neutron-tempest-plugin-api|rally_sanity|refstack_defcore|patrole|snaps_smoke|neutron_trunk|networking-bgpvpn|networking-sfc|barbican)
61             FUNCTEST_IMAGE=${REPO}/functest-smoke:${DOCKER_TAG} ;;
62         shaker|vmtp)
63             FUNCTEST_IMAGE=${REPO}/functest-benchmarking:${DOCKER_TAG} ;;
64         tempest_full_parallel|tempest_full|tempest_scenario|rally_full)
65             FUNCTEST_IMAGE=${REPO}/functest-components:${DOCKER_TAG} ;;
66         cloudify|cloudify_ims|heat_ims|vyos_vrouter|juju_epc)
67             FUNCTEST_IMAGE=${REPO}/functest-vnf:${DOCKER_TAG} ;;
68         doctor-notification|bgpvpn|functest-odl-sfc|barometercollectd|fds|vgpu|stor4nfv_os)
69             FUNCTEST_IMAGE=${REPO}/functest-features:${DOCKER_TAG} ;;
70         *)
71             echo "Unkown test case $test_name"
72             exit 1
73             ;;
74     esac
75     echo "Functest: Pulling Functest Docker image ${FUNCTEST_IMAGE} ..."
76     docker pull ${FUNCTEST_IMAGE}>/dev/null
77     cmd="docker run --rm ${envs} ${volumes} ${TESTCASE_OPTIONS} ${FUNCTEST_IMAGE} /bin/bash -c '${cmd_opt}'"
78     echo "Running Functest test case '${test_name}'. CMD: ${cmd}"
79     eval ${cmd}
80     ret_value=$?
81     if [ ${ret_value} != 0 ]; then
82       echo ${ret_value} > ${ret_val_file}
83     fi
84 }
85
86
87 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
88 FUNCTEST_DIR=/home/opnfv/functest
89 DEPLOY_TYPE=baremetal
90 [[ $BUILD_TAG =~ "virtual" ]] && DEPLOY_TYPE=virt
91 HOST_ARCH=$(uname -m)
92
93 # Prepare OpenStack credentials volume
94 rc_file=${HOME}/opnfv-openrc.sh
95
96 if [[ ${INSTALLER_TYPE} == 'joid' ]]; then
97     rc_file=$LAB_CONFIG/admin-openrc
98 elif [[ ${INSTALLER_TYPE} == 'compass' ]]; then
99     cacert_file_vol="-v ${HOME}/os_cacert:${FUNCTEST_DIR}/conf/os_cacert"
100     echo "export OS_CACERT=${FUNCTEST_DIR}/conf/os_cacert" >> ${HOME}/opnfv-openrc.sh
101 elif [[ ${INSTALLER_TYPE} == 'fuel' && ${DEPLOY_TYPE} == 'baremetal' ]]; then
102     cacert_file_vol="-v ${HOME}/os_cacert:/etc/ssl/certs/mcp_os_cacert"
103 fi
104
105 rc_file_vol="-v ${rc_file}:${FUNCTEST_DIR}/conf/env_file"
106
107 echo "Functest: Start Docker and prepare environment"
108
109 echo "Functest: Download images that will be used by test cases"
110 images_dir="${HOME}/opnfv/functest/images"
111 download_script=${WORKSPACE}/functest/ci/download_images.sh
112 if [[ ! -f ${download_script} ]]; then
113     # to support Danube as well
114     wget https://git.opnfv.org/functest/plain/functest/ci/download_images.sh -O ${download_script} 2> ${redirect}
115 fi
116 chmod +x ${download_script}
117 ${download_script} ${images_dir} ${DEPLOY_SCENARIO} ${HOST_ARCH} 2> ${redirect}
118
119 images_vol="-v ${images_dir}:${FUNCTEST_DIR}/images"
120
121 dir_result="${HOME}/opnfv/functest/results/${BRANCH##*/}"
122 mkdir -p ${dir_result}
123 sudo rm -rf ${dir_result}/*
124 results_vol="-v ${dir_result}:${FUNCTEST_DIR}/results"
125 custom_params=
126 test -f ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG} && custom_params=$(cat ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG})
127
128 envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP} \
129     -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \
130     -e BUILD_TAG=${BUILD_TAG} -e DEPLOY_TYPE=${DEPLOY_TYPE} -e CI_LOOP=${CI_LOOP} \
131     -e TEST_DB_URL=${TEST_DB_URL} -e ENERGY_RECORDER_API_URL=${ENERGY_RECORDER_API_URL}"
132
133 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
134
135 if [ "${INSTALLER_TYPE}" == 'fuel' ]; then
136     COMPUTE_ARCH=$(ssh -l ubuntu ${INSTALLER_IP} -i ${SSH_KEY} ${ssh_options} \
137         "sudo salt 'cmp*' grains.get cpuarch --out yaml | awk '{print \$2; exit}'")
138     IMAGE_PROPERTIES="hw_disk_bus:scsi,hw_scsi_model:virtio-scsi"
139     envs="${envs} -e POD_ARCH=${COMPUTE_ARCH}"
140 fi
141
142 if [[ ${INSTALLER_TYPE} == 'fuel' && ${DEPLOY_SCENARIO} == 'os-nosdn-nofeature-noha' ]]; then
143     libvirt_vol="-v ${ssh_key}:${FUNCTEST_DIR}/conf/libvirt_key"
144     envs="${envs} -e LIBVIRT_USER=ubuntu -e LIBVIRT_KEY_PATH=${FUNCTEST_DIR}/conf/libvirt_key"
145 fi
146
147 if [[ ${INSTALLER_TYPE} == 'compass' && ${DEPLOY_SCENARIO} =~ 'sfc' ]]; then
148     ssh_key="/tmp/id_rsa"
149     user_config="/tmp/openstack_user_config.yml"
150     docker cp compass-tasks:/root/.ssh/id_rsa $ssh_key
151     docker cp compass-tasks:/etc/openstack_deploy/openstack_user_config.yml $user_config
152     sshkey_vol="-v ${ssh_key}:/root/.ssh/id_rsa"
153     userconfig_vol="-v ${user_config}:${user_config}"
154     envs="${envs} -e EXTERNAL_NETWORK=${EXTERNAL_NETWORK}"
155 fi
156
157 if [[ ${DEPLOY_SCENARIO} == *"ovs"* ]] || [[ ${DEPLOY_SCENARIO} == *"fdio"* ]]; then
158     if [[ -n ${IMAGE_PROPERTIES} ]]; then
159         IMAGE_PROPERTIES="${IMAGE_PROPERTIES},hw_mem_page_size:large"
160     else
161         IMAGE_PROPERTIES="hw_mem_page_size:large"
162     fi
163     FLAVOR_EXTRA_SPECS="hw:mem_page_size:large"
164 fi
165
166 if [[ -n ${IMAGE_PROPERTIES} ]] || [[ -n ${FLAVOR_EXTRA_SPECS} ]]; then
167     envs="${envs} -e IMAGE_PROPERTIES=${IMAGE_PROPERTIES} -e FLAVOR_EXTRA_SPECS=${FLAVOR_EXTRA_SPECS}"
168 fi
169
170 tempest_conf_yaml=$(mktemp)
171 case ${INSTALLER_TYPE} in
172 apex)
173     cat << EOF > "${tempest_conf_yaml}"
174 ---
175 compute-feature-enabled:
176     shelve: false
177     vnc_console: true
178 identity-feature-enabled:
179     api_v2: false
180     api_v2_admin: false
181 image-feature-enabled:
182     api_v2: true
183     api_v1: false
184 volume:
185     storage_protocol: ceph
186 volume-feature-enabled:
187     backup: false
188 EOF
189     ;;
190 compass)
191     cat << EOF > "${tempest_conf_yaml}"
192 ---
193 compute-feature-enabled:
194     shelve: false
195     vnc_console: false
196     spice_console: true
197 identity-feature-enabled:
198     api_v2: false
199     api_v2_admin: false
200 image-feature-enabled:
201     api_v2: true
202     api_v1: false
203 volume:
204     storage_protocol: ceph
205 volume-feature-enabled:
206     backup: false
207 EOF
208     ;;
209 fuel)
210     cat << EOF > "${tempest_conf_yaml}"
211 ---
212 compute-feature-enabled:
213     shelve: false
214     vnc_console: false
215     spice_console: true
216 identity-feature-enabled:
217     api_v2: false
218     api_v2_admin: false
219 image-feature-enabled:
220     api_v2: true
221     api_v1: false
222 volume:
223     storage_protocol: iSCSI
224 volume-feature-enabled:
225     backup: false
226 EOF
227     ;;
228 *)
229     cat << EOF > "${tempest_conf_yaml}"
230 ---
231 compute-feature-enabled:
232     shelve: false
233     vnc_console: false
234 identity-feature-enabled:
235     api_v2: false
236     api_v2_admin: false
237 image-feature-enabled:
238     api_v2: true
239     api_v1: false
240 volume:
241     storage_protocol: iSCSI
242 volume-feature-enabled:
243     backup: false
244 EOF
245     ;;
246 esac
247 echo "tempest_conf.yaml:" && cat "${tempest_conf_yaml}"
248
249 volumes="${images_vol} ${results_vol} ${sshkey_vol} ${libvirt_vol} \
250     ${userconfig_vol} ${rc_file_vol} ${cacert_file_vol} \
251     -v ${tempest_conf_yaml}:/usr/lib/python2.7/site-packages/functest/opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml"
252
253 ret_val_file="${HOME}/opnfv/functest/results/${BRANCH##*/}/return_value"
254 echo 0 > ${ret_val_file}
255
256 set +e
257
258 if [ ${FUNCTEST_MODE} == 'testcase' ]; then
259     echo "FUNCTEST_MODE=testcase, FUNCTEST_SUITE_NAME=${FUNCTEST_SUITE_NAME}"
260     run_test ${FUNCTEST_SUITE_NAME}
261 elif [ ${FUNCTEST_MODE} == 'tier' ]; then
262     echo "FUNCTEST_MODE=tier, FUNCTEST_TIER=${FUNCTEST_TIER}"
263     tiers=(${FUNCTEST_TIER})
264     run_tiers ${tiers}
265 else
266     tests=(tempest_full tempest_scenario)
267     skip_tests=0
268     if [ ${DEPLOY_TYPE} == 'baremetal' ] && [ "${HOST_ARCH}" != "aarch64" ]; then
269         if [[ ${BRANCH} == "stable/fraser" ]]; then
270             tiers=(healthcheck smoke features vnf parser)
271             tests=(tempest_full_parallel)
272         else
273             tiers=(healthcheck smoke benchmarking features vnf)
274         fi
275     else
276         if [[ ${BRANCH} == "stable/fraser" ]]; then
277             tiers=(healthcheck smoke features parser)
278             tests=(tempest_full_parallel)
279         else
280             tiers=(healthcheck smoke benchmarking features)
281         fi
282     fi
283     run_tiers ${tiers}
284     if [ ${skip_tests} -eq 0 ]; then
285         for test in "${tests[@]}"; do
286             run_test "$test"
287         done
288     fi
289 fi