substitute with testapi img
[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 sshkey=""
10 # The path of openrc.sh is defined in fetch_os_creds.sh
11 OPENRC=$WORKSPACE/opnfv-openrc.sh
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     sudo cp $LAB_CONFIG/admin-openrc $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 releng_repo=${WORKSPACE}/releng
36 [ -d ${releng_repo} ] && sudo rm -rf ${releng_repo}
37 git clone https://gerrit.opnfv.org/gerrit/releng ${releng_repo} >/dev/null
38
39 if [[ ${INSTALLER_TYPE} != 'joid' ]]; then
40     ${releng_repo}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} >${redirect}
41 fi
42
43 if [[ -f $OPENRC ]]; then
44     echo "INFO: openstack credentials path is $OPENRC"
45     cat $OPENRC
46 else
47     echo "ERROR: file $OPENRC does not exist."
48     exit 1
49 fi
50
51 sudo pip install virtualenv
52
53 cd ${releng_repo}/modules
54 sudo virtualenv venv
55 source venv/bin/activate
56 sudo pip install -e ./ >/dev/null
57 sudo pip install netaddr
58
59 if [[ ${INSTALLER_TYPE} == compass ]]; then
60     options="-u root -p root"
61 elif [[ ${INSTALLER_TYPE} == fuel ]]; then
62     options="-u root -p r00tme"
63 else
64     echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
65     echo "HA test cases may not run properly."
66 fi
67
68 pod_file_dir="/home/opnfv/dovetail/userconfig"
69 if [ -d ${pod_file_dir} ]; then
70     sudo rm -rf ${pod_file_dir}/*
71 else
72     sudo mkdir -p ${pod_file_dir}
73 fi
74 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} -i ${INSTALLER_IP} ${options} -f ${pod_file_dir}/pod.yaml"
75 echo ${cmd}
76 ${cmd}
77
78 deactivate
79
80 cd ${WORKSPACE}
81
82 if [ -f ${pod_file_dir}/pod.yaml ]; then
83     echo "file ${pod_file_dir}/pod.yaml:"
84     cat ${pod_file_dir}/pod.yaml
85 else
86     echo "Error: There doesn't exist file ${pod_file_dir}/pod.yaml."
87     echo "HA test cases may not run properly."
88 fi
89
90 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
91
92 if [ "$INSTALLER_TYPE" == "fuel" ]; then
93     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
94     sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${pod_file_dir}/id_rsa
95 fi
96
97 opts="--privileged=true -id"
98 results_envs="-v /var/run/docker.sock:/var/run/docker.sock \
99               -v /home/opnfv/dovetail/results:/home/opnfv/dovetail/results"
100 openrc_volume="-v ${OPENRC}:${OPENRC}"
101 userconfig_volume="-v ${pod_file_dir}:${pod_file_dir}"
102
103 # Pull the image with correct tag
104 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
105 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
106
107 cmd="docker run ${opts} ${results_envs} ${openrc_volume} ${userconfig_volume} \
108      ${sshkey} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
109 echo "Dovetail: running docker run command: ${cmd}"
110 ${cmd} >${redirect}
111 sleep 5
112 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
113 echo "Container ID=${container_id}"
114 if [ -z ${container_id} ]; then
115     echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
116     docker ps -a
117     exit 1
118 fi
119 echo "Container Start: docker start ${container_id}"
120 docker start ${container_id}
121 sleep 5
122 docker ps >${redirect}
123 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
124     echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
125     exit 1
126 fi
127
128 list_cmd="dovetail list ${TESTSUITE}"
129 run_cmd="dovetail run --openrc ${OPENRC} --testsuite ${TESTSUITE} -d"
130 echo "Container exec command: ${list_cmd}"
131 docker exec $container_id ${list_cmd}
132 echo "Container exec command: ${run_cmd}"
133 docker exec $container_id ${run_cmd}
134
135 sudo cp -r ${DOVETAIL_REPO_DIR}/results ./
136 # To make sure the file owner is the current user, for the copied results files in the above line
137 # if not, there will be error when next time to wipe workspace
138 # CURRENT_USER=${SUDO_USER:-$USER}
139 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
140 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
141
142 echo "Dovetail: done!"
143