dovetail: to support multi_testsuite
[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       -e INSTALLER_TYPE=${INSTALLER_TYPE} \
38       -e INSTALLER_IP=${INSTALLER_IP} \
39       -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \
40       -e DEPLOY_TYPE=${DEPLOY_TYPE} \
41       -v /var/run/docker.sock:/var/run/docker.sock \
42       -v /home/opnfv/dovetail/results:/home/opnfv/dovetail/results"
43
44 # Pull the image with correct tag
45 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
46 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
47
48 # Run docker
49 echo "Dovetail: docker running..."
50 cmds = "${DOVETAIL_REPO_DIR}/dovetail/run.py --testsuite $TESTSUITE"
51 sudo docker run ${opts} ${envs} ${labconfig} ${sshkey} opnfv/dovetail:${DOCKER_TAG} ${cmds}
52
53 echo "Dovetail: store results..."
54 sudo cp -r /home/opnfv/dovetail/results ./
55 #To make sure the file owner is jenkins, for the copied results files in the above line
56 #if not, there will be error when next time to wipe workspace
57 sudo chown -R jenkins:jenkins ${WORKSPACE}/results
58
59 echo "Dovetail: done!"