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}
85 sudo pip install virtualenv
87 cd ${releng_repo}/modules
89 source venv/bin/activate
90 sudo pip install -e ./ >/dev/null
91 sudo pip install netaddr
93 if [[ ${INSTALLER_TYPE} == compass ]]; then
94 options="-u root -p root"
95 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
96 options="-u root -p r00tme"
97 elif [[ ${INSTALLER_TYPE} == apex ]]; then
98 options="-u stack -k /root/.ssh/id_rsa"
100 echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
101 echo "HA test cases may not run properly."
104 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
105 -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
115 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
116 echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
117 cat ${DOVETAIL_CONFIG}/pod.yaml
119 echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
120 sudo ls -al ${DOVETAIL_CONFIG}
121 echo "HA test cases may not run properly."
124 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
126 if [ "$INSTALLER_TYPE" == "fuel" ]; then
127 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
128 sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
131 if [ "$INSTALLER_TYPE" == "apex" ]; then
132 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
133 sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
136 image_path=${HOME}/opnfv/dovetail/images
137 if [[ ! -d ${image_path} ]]; then
138 mkdir -p ${image_path}
140 # sdnvpn test case needs to download this image first before running
141 ubuntu_image=${image_path}/ubuntu-16.04-server-cloudimg-amd64-disk1.img
142 if [[ ! -f ${ubuntu_image} ]]; then
143 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
144 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${image_path}
146 sudo cp ${ubuntu_image} ${DOVETAIL_CONFIG}
148 # functest needs to download this image first before running
149 cirros_image=${image_path}/cirros-0.3.5-x86_64-disk.img
150 if [[ ! -f ${cirros_image} ]]; then
151 echo "Download image cirros-0.3.5-x86_64-disk.img ..."
152 wget -q -nc http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img -P ${image_path}
154 sudo cp ${cirros_image} ${DOVETAIL_CONFIG}
157 opts="--privileged=true -id"
159 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
160 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
162 # Pull the image with correct tag
163 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
164 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
166 env4bgpvpn="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP}"
168 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
169 ${sshkey} ${env4bgpvpn} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
170 echo "Dovetail: running docker run command: ${cmd}"
173 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
174 echo "Container ID=${container_id}"
175 if [ -z ${container_id} ]; then
176 echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
180 echo "Container Start: docker start ${container_id}"
181 docker start ${container_id}
183 docker ps >${redirect}
184 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
185 echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
189 # Modify tempest_conf.yaml file
190 tempest_conf_file=${DOVETAIL_CONFIG}/tempest_conf.yaml
191 if [[ ${INSTALLER_TYPE} == 'compass' || ${INSTALLER_TYPE} == 'apex' ]]; then
197 cat << EOF >$tempest_conf_file
201 volume_device_name: ${volume_device}
205 echo "${tempest_conf_file}..."
206 cat ${tempest_conf_file}
208 cp_tempest_cmd="docker cp ${DOVETAIL_CONFIG}/tempest_conf.yaml $container_id:/home/opnfv/dovetail/dovetail/userconfig"
209 echo "exec command: ${cp_tempest_cmd}"
212 list_cmd="dovetail list ${TESTSUITE}"
213 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
214 echo "Container exec command: ${list_cmd}"
215 docker exec $container_id ${list_cmd}
216 echo "Container exec command: ${run_cmd}"
217 docker exec $container_id ${run_cmd}
219 sudo cp -r ${DOVETAIL_HOME}/results ./
220 # To make sure the file owner is the current user, for the copied results files in the above line
221 # if not, there will be error when next time to wipe workspace
222 # CURRENT_USER=${SUDO_USER:-$USER}
223 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
224 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
226 #remove useless workspace from yardstick to save disk space
227 sudo rm -rf ./results/workspace
229 echo "Dovetail: done!"