Merge "Add export functions to reporting"
[releng.git] / jjb / dovetail / dovetail-run.sh
1 #!/bin/bash
2
3 #the noun INSTALLER is used in community, here is just the example to run.
4 #multi-platforms are supported.
5
6 set -e
7 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
8
9 # labconfig is used only for joid
10 labconfig=""
11 sshkey=""
12 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
13     instack_mac=$(sudo virsh domiflist undercloud | grep default | \
14                   grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
15     INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
16     sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
17     if [[ -n $(sudo iptables -L FORWARD |grep "REJECT"|grep "reject-with icmp-port-unreachable") ]]; then
18         #note: this happens only in opnfv-lf-pod1
19         sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
20         sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
21     fi
22 elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
23     # If production lab then creds may be retrieved dynamically
24     # creds are on the jumphost, always in the same folder
25     labconfig="-v $LAB_CONFIG/admin-openrc:/home/opnfv/openrc"
26     # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
27     # replace the default one by the customized one provided by jenkins config
28 fi
29
30 # Set iptables rule to allow forwarding return traffic for container
31 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
32     sudo iptables -I FORWARD -j RETURN
33 fi
34
35 opts="--privileged=true --rm"
36 envs="-e CI_DEBUG=${CI_DEBUG} \
37       -v /var/run/docker.sock:/var/run/docker.sock \
38       -v /home/opnfv/dovetail/results:/home/opnfv/dovetail/results"
39
40 # Pull the image with correct tag
41 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
42 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
43
44 # Run docker
45 echo "Dovetail: docker running..."
46 sudo docker run ${opts} ${envs} ${labconfig} ${sshkey} opnfv/dovetail:${DOCKER_TAG} \
47 "/home/opnfv/dovetail/scripts/run.py"
48
49 echo "Dovetail: store results..."
50 sudo cp -r /home/opnfv/dovetail/results ./
51 #To make sure the file owner is jenkins, for the copied results files in the above line
52 #if not, there will be error when next time to wipe workspace
53 sudo chown -R jenkins:jenkins ${WORKSPACE}/results
54
55 echo "Dovetail: done!"