Tagging SampleVNF stable/gambia branch for Gambia 7.2.0
[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|tempest_smoke)
59             FUNCTEST_IMAGE=${REPO}/functest-healthcheck:${DOCKER_TAG} ;;
60         neutron-tempest-plugin-api|rally_sanity|refstack_defcore|tempest_full|tempest_scenario|patrole|snaps_smoke|neutron_trunk|networking-bgpvpn|networking-sfc|barbican)
61             FUNCTEST_IMAGE=${REPO}/functest-smoke:${DOCKER_TAG} ;;
62         rally_jobs|shaker|vmtp)
63             FUNCTEST_IMAGE=${REPO}/functest-benchmarking:${DOCKER_TAG} ;;
64         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 redirect="/dev/stdout"
89 FUNCTEST_DIR=/home/opnfv/functest
90 DEPLOY_TYPE=baremetal
91 [[ $BUILD_TAG =~ "virtual" ]] && DEPLOY_TYPE=virt
92 HOST_ARCH=$(uname -m)
93
94 # Prepare OpenStack credentials volume
95 rc_file=${HOME}/opnfv-openrc.sh
96
97 if [[ ${INSTALLER_TYPE} == 'joid' ]]; then
98     rc_file=$LAB_CONFIG/admin-openrc
99 elif [[ ${INSTALLER_TYPE} == 'compass' ]]; then
100     cacert_file_vol="-v ${HOME}/os_cacert:${FUNCTEST_DIR}/conf/os_cacert"
101     echo "export OS_CACERT=${FUNCTEST_DIR}/conf/os_cacert" >> ${HOME}/opnfv-openrc.sh
102 elif [[ ${INSTALLER_TYPE} == 'fuel' ]] && [[ "${DEPLOY_SCENARIO}" =~ -ha$ ]]; then
103     cacert_file_vol="-v ${HOME}/os_cacert:/etc/ssl/certs/mcp_os_cacert"
104 fi
105
106 rc_file_vol="-v ${rc_file}:${FUNCTEST_DIR}/conf/env_file"
107
108 echo "Functest: Start Docker and prepare environment"
109
110 echo "Functest: Download images that will be used by test cases"
111 env
112 pwd
113 ls -l
114 images_dir="${HOME}/opnfv/functest/images"
115 download_script=${WORKSPACE}/functest/ci/download_images.sh
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 [[ ${INSTALLER_TYPE} == 'compass' ]] || [[ ${DEPLOY_SCENARIO} == *"odl"* ]]; then
158       envs="${envs} -e SDN_CONTROLLER_RESTCONFPORT=8080"
159 fi
160
161 if [[ ${DEPLOY_SCENARIO} == *"ovs"* ]] || [[ ${DEPLOY_SCENARIO} == *"fdio"* ]]; then
162     if [[ -n ${IMAGE_PROPERTIES} ]]; then
163         IMAGE_PROPERTIES="${IMAGE_PROPERTIES},hw_mem_page_size:large"
164     else
165         IMAGE_PROPERTIES="hw_mem_page_size:large"
166     fi
167     FLAVOR_EXTRA_SPECS="hw:mem_page_size:large"
168 fi
169
170 if [[ -n ${IMAGE_PROPERTIES} ]] || [[ -n ${FLAVOR_EXTRA_SPECS} ]]; then
171     envs="${envs} -e IMAGE_PROPERTIES=${IMAGE_PROPERTIES} -e FLAVOR_EXTRA_SPECS=${FLAVOR_EXTRA_SPECS}"
172 fi
173
174 tempest_conf_yaml=$(mktemp)
175 case ${INSTALLER_TYPE} in
176 apex)
177     cat << EOF > "${tempest_conf_yaml}"
178 ---
179 compute-feature-enabled:
180     shelve: false
181     vnc_console: true
182 identity-feature-enabled:
183     api_v2: false
184     api_v2_admin: false
185 image-feature-enabled:
186     api_v2: true
187     api_v1: false
188 volume:
189     storage_protocol: ceph
190 volume-feature-enabled:
191     backup: false
192 EOF
193     ;;
194 compass)
195     cat << EOF > "${tempest_conf_yaml}"
196 ---
197 compute-feature-enabled:
198     shelve: false
199     vnc_console: false
200     spice_console: true
201 identity-feature-enabled:
202     api_v2: false
203     api_v2_admin: false
204 image-feature-enabled:
205     api_v2: true
206     api_v1: false
207 volume:
208     storage_protocol: ceph
209 volume-feature-enabled:
210     backup: false
211 EOF
212     ;;
213 fuel)
214     cat << EOF > "${tempest_conf_yaml}"
215 ---
216 compute-feature-enabled:
217     shelve: false
218     vnc_console: false
219     spice_console: true
220 identity-feature-enabled:
221     api_v2: false
222     api_v2_admin: false
223 image-feature-enabled:
224     api_v2: true
225     api_v1: false
226 volume:
227     storage_protocol: iSCSI
228 volume-feature-enabled:
229     backup: false
230 EOF
231     ;;
232 *)
233     cat << EOF > "${tempest_conf_yaml}"
234 ---
235 compute-feature-enabled:
236     shelve: false
237     vnc_console: false
238 identity-feature-enabled:
239     api_v2: false
240     api_v2_admin: false
241 image-feature-enabled:
242     api_v2: true
243     api_v1: false
244 volume:
245     storage_protocol: iSCSI
246 volume-feature-enabled:
247     backup: false
248 EOF
249     ;;
250 esac
251 echo "tempest_conf.yaml:" && cat "${tempest_conf_yaml}"
252
253 volumes="${images_vol} ${results_vol} ${sshkey_vol} ${libvirt_vol} \
254     ${userconfig_vol} ${rc_file_vol} ${cacert_file_vol} \
255     -v ${tempest_conf_yaml}:/usr/lib/python2.7/site-packages/functest/opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml"
256
257 ret_val_file="${HOME}/opnfv/functest/results/${BRANCH##*/}/return_value"
258 echo 0 > ${ret_val_file}
259
260 set +e
261
262 if [ ${FUNCTEST_MODE} == 'testcase' ]; then
263     echo "FUNCTEST_MODE=testcase, FUNCTEST_SUITE_NAME=${FUNCTEST_SUITE_NAME}"
264     run_test ${FUNCTEST_SUITE_NAME}
265 elif [ ${FUNCTEST_MODE} == 'tier' ]; then
266     echo "FUNCTEST_MODE=tier, FUNCTEST_TIER=${FUNCTEST_TIER}"
267     tiers=(${FUNCTEST_TIER})
268     run_tiers ${tiers}
269 else
270     tests=()
271     skip_tests=0
272     if [ ${DEPLOY_TYPE} == 'baremetal' ] && [ "${HOST_ARCH}" != "aarch64" ]; then
273         if [[ ${BRANCH} == "stable/fraser" ]]; then
274             tiers=(healthcheck smoke features vnf parser)
275             tests=(tempest_full_parallel)
276         else
277             tiers=(healthcheck smoke benchmarking features vnf components)
278         fi
279     else
280         if [[ ${BRANCH} == "stable/fraser" ]]; then
281             tiers=(healthcheck smoke features parser)
282             tests=(tempest_full_parallel)
283         else
284             tiers=(healthcheck smoke benchmarking features components)
285         fi
286     fi
287     run_tiers ${tiers}
288     if [ ${skip_tests} -eq 0 ]; then
289         for test in "${tests[@]}"; do
290             run_test "$test"
291         done
292     fi
293 fi