2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 #the noun INSTALLER is used in community, here is just the example to run.
11 #multi-platforms are supported.
14 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
16 DOVETAIL_HOME=${WORKSPACE}/cvp
17 [ -d ${DOVETAIL_HOME} ] && sudo rm -rf ${DOVETAIL_HOME}
19 mkdir -p ${DOVETAIL_HOME}
21 DOVETAIL_CONFIG=${DOVETAIL_HOME}/pre_config
22 mkdir -p ${DOVETAIL_CONFIG}
25 # The path of openrc.sh is defined in fetch_os_creds.sh
26 OPENRC=${DOVETAIL_CONFIG}/env_config.sh
27 CACERT=${DOVETAIL_CONFIG}/os_cacert
28 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
29 instack_mac=$(sudo virsh domiflist undercloud | grep default | \
30 grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
31 INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
32 sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
33 if [[ -n $(sudo iptables -L FORWARD |grep "REJECT"|grep "reject-with icmp-port-unreachable") ]]; then
34 #note: this happens only in opnfv-lf-pod1
35 sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
36 sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
38 elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
39 # If production lab then creds may be retrieved dynamically
40 # creds are on the jumphost, always in the same folder
41 sudo cp $LAB_CONFIG/admin-openrc $OPENRC
42 # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
43 # replace the default one by the customized one provided by jenkins config
46 # Set iptables rule to allow forwarding return traffic for container
47 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
48 sudo iptables -I FORWARD -j RETURN
51 releng_repo=${WORKSPACE}/releng
52 [ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
53 git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
55 if [[ ${INSTALLER_TYPE} != 'joid' ]]; then
56 echo "SUT branch is $SUT_BRANCH"
57 echo "dovetail branch is $BRANCH"
59 export BRANCH=$SUT_BRANCH
60 ${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${CACERT} >${redirect}
61 export BRANCH=$BRANCH_BACKUP
64 if [[ -f $OPENRC ]]; then
65 echo "INFO: openstack credentials path is $OPENRC"
66 if [[ ! "${SUT_BRANCH}" =~ "danube" && ${INSTALLER_TYPE} == "compass" ]]; then
67 if [[ -f ${CACERT} ]]; then
68 echo "INFO: ${INSTALLER_TYPE} openstack cacert file is ${CACERT}"
69 echo "export OS_CACERT=${CACERT}" >> ${OPENRC}
71 echo "ERROR: Can't find ${INSTALLER_TYPE} openstack cacert file. Please check if it is existing."
72 sudo ls -al ${DOVETAIL_CONFIG}
78 echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
79 sudo ls -al ${DOVETAIL_CONFIG}
83 if [[ ! "${SUT_BRANCH}" =~ "danube" && ${INSTALLER_TYPE} == "compass" ]]; then
84 cat << EOF >${DOVETAIL_CONFIG}/pod.yaml
86 - {ip: 10.1.0.52, name: node1, password: root, role: controller, user: root}
87 - {ip: 10.1.0.51, name: node2, password: root, role: controller, user: root}
88 - {ip: 10.1.0.50, name: node3, password: root, role: controller, user: root}
89 - {ip: 10.1.0.54, name: node4, password: root, role: compute, user: root}
90 - {ip: 10.1.0.53, name: node5, password: root, role: compute, user: root}
95 if [[ ! -f ${DOVETAIL_CONFIG}/pod.yaml ]]; then
98 sudo pip install virtualenv
100 cd ${releng_repo}/modules
102 source venv/bin/activate
103 sudo pip install -e ./ >/dev/null
104 sudo pip install netaddr
106 if [[ ${INSTALLER_TYPE} == compass ]]; then
107 options="-u root -p root"
108 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
109 options="-u root -p r00tme"
110 elif [[ ${INSTALLER_TYPE} == apex ]]; then
111 options="-u stack -k /root/.ssh/id_rsa"
113 echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
114 echo "HA test cases may not run properly."
117 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
118 -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
129 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
130 echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
131 cat ${DOVETAIL_CONFIG}/pod.yaml
133 echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
134 sudo ls -al ${DOVETAIL_CONFIG}
135 echo "HA test cases may not run properly."
138 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
140 if [ "$INSTALLER_TYPE" == "fuel" ]; then
141 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
142 sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
145 if [ "$INSTALLER_TYPE" == "apex" ]; then
146 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
147 sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
150 image_path=${HOME}/opnfv/dovetail/images
151 if [[ ! -d ${image_path} ]]; then
152 mkdir -p ${image_path}
154 # sdnvpn test case needs to download this image first before running
155 ubuntu_image=${image_path}/ubuntu-16.04-server-cloudimg-amd64-disk1.img
156 if [[ ! -f ${ubuntu_image} ]]; then
157 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
158 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${image_path}
160 sudo cp ${ubuntu_image} ${DOVETAIL_CONFIG}
162 # functest needs to download this image first before running
163 cirros_image=${image_path}/cirros-0.3.5-x86_64-disk.img
164 if [[ ! -f ${cirros_image} ]]; then
165 echo "Download image cirros-0.3.5-x86_64-disk.img ..."
166 wget -q -nc http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img -P ${image_path}
168 sudo cp ${cirros_image} ${DOVETAIL_CONFIG}
171 opts="--privileged=true -id"
173 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
174 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
176 # Pull the image with correct tag
177 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
178 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
180 env4bgpvpn="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP}"
182 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
183 ${sshkey} ${env4bgpvpn} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
184 echo "Dovetail: running docker run command: ${cmd}"
187 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
188 echo "Container ID=${container_id}"
189 if [ -z ${container_id} ]; then
190 echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
194 echo "Container Start: docker start ${container_id}"
195 docker start ${container_id}
197 docker ps >${redirect}
198 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
199 echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
203 # Modify tempest_conf.yaml file
204 tempest_conf_file=${DOVETAIL_CONFIG}/tempest_conf.yaml
205 if [[ ${INSTALLER_TYPE} == 'compass' || ${INSTALLER_TYPE} == 'apex' ]]; then
211 cat << EOF >$tempest_conf_file
215 volume_device_name: ${volume_device}
219 echo "${tempest_conf_file}..."
220 cat ${tempest_conf_file}
222 cp_tempest_cmd="docker cp ${DOVETAIL_CONFIG}/tempest_conf.yaml $container_id:/home/opnfv/dovetail/dovetail/userconfig"
223 echo "exec command: ${cp_tempest_cmd}"
226 list_cmd="dovetail list ${TESTSUITE}"
227 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
228 echo "Container exec command: ${list_cmd}"
229 docker exec $container_id ${list_cmd}
230 echo "Container exec command: ${run_cmd}"
231 docker exec $container_id ${run_cmd}
233 sudo cp -r ${DOVETAIL_HOME}/results ./
234 # To make sure the file owner is the current user, for the copied results files in the above line
235 # if not, there will be error when next time to wipe workspace
236 # CURRENT_USER=${SUDO_USER:-$USER}
237 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
238 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
240 #remove useless workspace from yardstick to save disk space
241 sudo rm -rf ./results/workspace
243 echo "Dovetail: done!"