add python verify job for doctor
[releng.git] / jjb / dovetail / dovetail-run.sh
1 #!/bin/bash
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 ##############################################################################
9
10 #the noun INSTALLER is used in community, here is just the example to run.
11 #multi-platforms are supported.
12
13 set -e
14 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
15
16 DOVETAIL_HOME=${WORKSPACE}/cvp
17 [ -d ${DOVETAIL_HOME} ] && sudo rm -rf ${DOVETAIL_HOME}
18
19 mkdir -p ${DOVETAIL_HOME}
20
21 DOVETAIL_CONFIG=${DOVETAIL_HOME}/pre_config
22 mkdir -p ${DOVETAIL_CONFIG}
23
24 sshkey=""
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
36     fi
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
43 fi
44
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
48 fi
49
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
53
54 if [[ ${INSTALLER_TYPE} != 'joid' ]]; then
55     ${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} >${redirect}
56 fi
57
58 if [[ -f $OPENRC ]]; then
59     echo "INFO: openstack credentials path is $OPENRC"
60     cat $OPENRC
61 else
62     echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
63     sudo ls -al ${DOVETAIL_CONFIG}
64     exit 1
65 fi
66
67 sudo pip install virtualenv
68
69 cd ${releng_repo}/modules
70 sudo virtualenv venv
71 source venv/bin/activate
72 sudo pip install -e ./ >/dev/null
73 sudo pip install netaddr
74
75 if [[ ${INSTALLER_TYPE} == compass ]]; then
76     options="-u root -p root"
77 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
78     options="-u root -p r00tme"
79 else
80     echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
81     echo "HA test cases may not run properly."
82 fi
83
84 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
85      -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
86 echo ${cmd}
87 ${cmd}
88
89 deactivate
90
91 cd ${WORKSPACE}
92
93 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
94     echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
95     cat ${DOVETAIL_CONFIG}/pod.yaml
96 else
97     echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
98     sudo ls -al ${DOVETAIL_CONFIG}
99     echo "HA test cases may not run properly."
100 fi
101
102 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
103
104 if [ "$INSTALLER_TYPE" == "fuel" ]; then
105     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
106     sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
107 fi
108
109 # sdnvpn test case needs to download this image first before running
110 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
111 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${DOVETAIL_CONFIG}
112
113 opts="--privileged=true -id"
114
115 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
116 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
117
118 # Pull the image with correct tag
119 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
120 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
121
122 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
123      ${sshkey} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
124 echo "Dovetail: running docker run command: ${cmd}"
125 ${cmd} >${redirect}
126 sleep 5
127 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
128 echo "Container ID=${container_id}"
129 if [ -z ${container_id} ]; then
130     echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
131     docker ps -a
132     exit 1
133 fi
134 echo "Container Start: docker start ${container_id}"
135 docker start ${container_id}
136 sleep 5
137 docker ps >${redirect}
138 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
139     echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
140     exit 1
141 fi
142
143 list_cmd="dovetail list ${TESTSUITE}"
144 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
145 echo "Container exec command: ${list_cmd}"
146 docker exec $container_id ${list_cmd}
147 echo "Container exec command: ${run_cmd}"
148 docker exec $container_id ${run_cmd}
149
150 sudo cp -r ${DOVETAIL_HOME}/results ./
151 # To make sure the file owner is the current user, for the copied results files in the above line
152 # if not, there will be error when next time to wipe workspace
153 # CURRENT_USER=${SUDO_USER:-$USER}
154 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
155 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
156
157 echo "Dovetail: done!"
158