09bf6e1aef0af526f134ed6083a4e70fc58277d8
[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 DOVETAIL_HOME=${WORKSPACE}/cvp
10 [ -d ${DOVETAIL_HOME} ] && sudo rm -rf ${DOVETAIL_HOME}
11
12 mkdir -p ${DOVETAIL_HOME}
13
14 DOVETAIL_CONFIG=${DOVETAIL_HOME}/pre_config
15 mkdir -p ${DOVETAIL_CONFIG}
16
17 sshkey=""
18 # The path of openrc.sh is defined in fetch_os_creds.sh
19 OPENRC=${DOVETAIL_CONFIG}/env_config.sh
20 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
21     instack_mac=$(sudo virsh domiflist undercloud | grep default | \
22                   grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
23     INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
24     sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
25     if [[ -n $(sudo iptables -L FORWARD |grep "REJECT"|grep "reject-with icmp-port-unreachable") ]]; then
26         #note: this happens only in opnfv-lf-pod1
27         sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
28         sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
29     fi
30 elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
31     # If production lab then creds may be retrieved dynamically
32     # creds are on the jumphost, always in the same folder
33     sudo cp $LAB_CONFIG/admin-openrc $OPENRC
34     # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
35     # replace the default one by the customized one provided by jenkins config
36 fi
37
38 # Set iptables rule to allow forwarding return traffic for container
39 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
40     sudo iptables -I FORWARD -j RETURN
41 fi
42
43 releng_repo=${WORKSPACE}/releng
44 [ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
45 git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
46
47 if [[ ${INSTALLER_TYPE} != 'joid' ]]; then
48     ${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} >${redirect}
49 fi
50
51 if [[ -f $OPENRC ]]; then
52     echo "INFO: openstack credentials path is $OPENRC"
53     cat $OPENRC
54 else
55     echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
56     sudo ls -al ${DOVETAIL_CONFIG}
57     exit 1
58 fi
59
60 sudo pip install virtualenv
61
62 cd ${releng_repo}/modules
63 sudo virtualenv venv
64 source venv/bin/activate
65 sudo pip install -e ./ >/dev/null
66 sudo pip install netaddr
67
68 if [[ ${INSTALLER_TYPE} == compass ]]; then
69     options="-u root -p root"
70 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
71     options="-u root -p r00tme"
72 else
73     echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
74     echo "HA test cases may not run properly."
75 fi
76
77 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
78      -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
79 echo ${cmd}
80 ${cmd}
81
82 deactivate
83
84 cd ${WORKSPACE}
85
86 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
87     echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
88     cat ${DOVETAIL_CONFIG}/pod.yaml
89 else
90     echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
91     sudo ls -al ${DOVETAIL_CONFIG}
92     echo "HA test cases may not run properly."
93 fi
94
95 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
96
97 if [ "$INSTALLER_TYPE" == "fuel" ]; then
98     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
99     sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
100 fi
101
102 # sdnvpn test case needs to download this image first before running
103 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
104 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${DOVETAIL_CONFIG}
105
106 opts="--privileged=true -id"
107
108 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
109 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
110
111 # Pull the image with correct tag
112 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
113 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
114
115 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
116      ${sshkey} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
117 echo "Dovetail: running docker run command: ${cmd}"
118 ${cmd} >${redirect}
119 sleep 5
120 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
121 echo "Container ID=${container_id}"
122 if [ -z ${container_id} ]; then
123     echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
124     docker ps -a
125     exit 1
126 fi
127 echo "Container Start: docker start ${container_id}"
128 docker start ${container_id}
129 sleep 5
130 docker ps >${redirect}
131 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
132     echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
133     exit 1
134 fi
135
136 list_cmd="dovetail list ${TESTSUITE}"
137 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
138 echo "Container exec command: ${list_cmd}"
139 docker exec $container_id ${list_cmd}
140 echo "Container exec command: ${run_cmd}"
141 docker exec $container_id ${run_cmd}
142
143 sudo cp -r ${DOVETAIL_HOME}/results ./
144 # To make sure the file owner is the current user, for the copied results files in the above line
145 # if not, there will be error when next time to wipe workspace
146 # CURRENT_USER=${SUDO_USER:-$USER}
147 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
148 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
149
150 echo "Dovetail: done!"
151