Ignore create_pod_file failure for Compass latest deployment
[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     echo "SUT branch is $SUT_BRANCH"
56     echo "dovetail branch is $BRANCH"
57     BRANCH_BACKUP=$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
61 fi
62
63 if [[ -f $OPENRC ]]; then
64     echo "INFO: openstack credentials path is $OPENRC"
65     cat $OPENRC
66 else
67     echo "ERROR: cannot find file $OPENRC. Please check if it is existing."
68     sudo ls -al ${DOVETAIL_CONFIG}
69     exit 1
70 fi
71
72 set +e
73
74 sudo pip install virtualenv
75
76 cd ${releng_repo}/modules
77 sudo virtualenv venv
78 source venv/bin/activate
79 sudo pip install -e ./ >/dev/null
80 sudo pip install netaddr
81
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 else
87     echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
88     echo "HA test cases may not run properly."
89 fi
90
91 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
92      -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
93 echo ${cmd}
94 ${cmd}
95
96 deactivate
97
98 set -e
99
100 cd ${WORKSPACE}
101
102 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
103     echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
104     cat ${DOVETAIL_CONFIG}/pod.yaml
105 else
106     echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
107     sudo ls -al ${DOVETAIL_CONFIG}
108     echo "HA test cases may not run properly."
109 fi
110
111 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
112
113 if [ "$INSTALLER_TYPE" == "fuel" ]; then
114     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
115     sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
116 fi
117
118 # sdnvpn test case needs to download this image first before running
119 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
120 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${DOVETAIL_CONFIG}
121
122 opts="--privileged=true -id"
123
124 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
125 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
126
127 # Pull the image with correct tag
128 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
129 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
130
131 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
132      ${sshkey} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
133 echo "Dovetail: running docker run command: ${cmd}"
134 ${cmd} >${redirect}
135 sleep 5
136 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
137 echo "Container ID=${container_id}"
138 if [ -z ${container_id} ]; then
139     echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
140     docker ps -a
141     exit 1
142 fi
143 echo "Container Start: docker start ${container_id}"
144 docker start ${container_id}
145 sleep 5
146 docker ps >${redirect}
147 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
148     echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
149     exit 1
150 fi
151
152 list_cmd="dovetail list ${TESTSUITE}"
153 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
154 echo "Container exec command: ${list_cmd}"
155 docker exec $container_id ${list_cmd}
156 echo "Container exec command: ${run_cmd}"
157 docker exec $container_id ${run_cmd}
158
159 sudo cp -r ${DOVETAIL_HOME}/results ./
160 # To make sure the file owner is the current user, for the copied results files in the above line
161 # if not, there will be error when next time to wipe workspace
162 # CURRENT_USER=${SUDO_USER:-$USER}
163 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
164 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
165
166 echo "Dovetail: done!"
167