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