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 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
28 instack_mac=$(sudo virsh domiflist undercloud | grep default | \
29 grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
30 INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
31 sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
32 if [[ -n $(sudo iptables -L FORWARD |grep "REJECT"|grep "reject-with icmp-port-unreachable") ]]; then
33 #note: this happens only in opnfv-lf-pod1
34 sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
35 sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
37 elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
38 # If production lab then creds may be retrieved dynamically
39 # creds are on the jumphost, always in the same folder
40 sudo cp $LAB_CONFIG/admin-openrc $OPENRC
41 # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
42 # replace the default one by the customized one provided by jenkins config
45 # Set iptables rule to allow forwarding return traffic for container
46 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
47 sudo iptables -I FORWARD -j RETURN
50 releng_repo=${WORKSPACE}/releng
51 [ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
52 git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
54 if [[ ${INSTALLER_TYPE} != 'joid' ]]; then
55 echo "SUT branch is $SUT_BRANCH"
56 echo "dovetail branch is $BRANCH"
58 export BRANCH=$SUT_BRANCH
59 ${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} >${redirect}
60 export BRANCH=$BRANCH_BACKUP
63 if [[ -f $OPENRC ]]; then
64 echo "INFO: openstack credentials path is $OPENRC"
67 echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
68 sudo ls -al ${DOVETAIL_CONFIG}
74 sudo pip install virtualenv
76 cd ${releng_repo}/modules
78 source venv/bin/activate
79 sudo pip install -e ./ >/dev/null
80 sudo pip install netaddr
82 if [[ ${INSTALLER_TYPE} == compass ]]; then
83 options="-u root -p root"
84 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
85 options="-u root -p r00tme"
86 elif [[ ${INSTALLER_TYPE} == apex ]]; then
87 options="-u stack -k /root/.ssh/id_rsa"
89 echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
90 echo "HA test cases may not run properly."
93 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
94 -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
104 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
105 echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
106 cat ${DOVETAIL_CONFIG}/pod.yaml
108 echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
109 sudo ls -al ${DOVETAIL_CONFIG}
110 echo "HA test cases may not run properly."
113 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
115 if [ "$INSTALLER_TYPE" == "fuel" ]; then
116 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
117 sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
120 if [ "$INSTALLER_TYPE" == "apex" ]; then
121 echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
122 sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
125 # sdnvpn test case needs to download this image first before running
126 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
127 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${DOVETAIL_CONFIG}
129 opts="--privileged=true -id"
131 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
132 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
134 # Pull the image with correct tag
135 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
136 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
138 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
139 ${sshkey} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
140 echo "Dovetail: running docker run command: ${cmd}"
143 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
144 echo "Container ID=${container_id}"
145 if [ -z ${container_id} ]; then
146 echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
150 echo "Container Start: docker start ${container_id}"
151 docker start ${container_id}
153 docker ps >${redirect}
154 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
155 echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
159 list_cmd="dovetail list ${TESTSUITE}"
160 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
161 echo "Container exec command: ${list_cmd}"
162 docker exec $container_id ${list_cmd}
163 echo "Container exec command: ${run_cmd}"
164 docker exec $container_id ${run_cmd}
166 sudo cp -r ${DOVETAIL_HOME}/results ./
167 # To make sure the file owner is the current user, for the copied results files in the above line
168 # if not, there will be error when next time to wipe workspace
169 # CURRENT_USER=${SUDO_USER:-$USER}
170 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
171 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
173 #remove useless workspace from yardstick to save disk space
174 sudo rm -rf ./results/workspace
176 echo "Dovetail: done!"