Merge "Integrate functest with ARM Architecture"
[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 elif [[ ${INSTALLER_TYPE} == apex ]]; then
87     options="-u stack -k /root/.ssh/id_rsa"
88 else
89     echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
90     echo "HA test cases may not run properly."
91 fi
92
93 cmd="sudo python ${releng_repo}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
94      -i ${INSTALLER_IP} ${options} -f ${DOVETAIL_CONFIG}/pod.yaml"
95 echo ${cmd}
96 ${cmd}
97
98 deactivate
99
100 set -e
101
102 cd ${WORKSPACE}
103
104 if [ -f ${DOVETAIL_CONFIG}/pod.yaml ]; then
105     echo "file ${DOVETAIL_CONFIG}/pod.yaml:"
106     cat ${DOVETAIL_CONFIG}/pod.yaml
107 else
108     echo "Error: cannot find file ${DOVETAIL_CONFIG}/pod.yaml. Please check if it is existing."
109     sudo ls -al ${DOVETAIL_CONFIG}
110     echo "HA test cases may not run properly."
111 fi
112
113 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
114
115 if [ "$INSTALLER_TYPE" == "fuel" ]; then
116     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
117     sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
118 fi
119
120 if [ "$INSTALLER_TYPE" == "apex" ]; then
121     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
122     sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${DOVETAIL_CONFIG}/id_rsa
123 fi
124
125 # sdnvpn test case needs to download this image first before running
126 echo "Download image ubuntu-16.04-server-cloudimg-amd64-disk1.img ..."
127 wget -q -nc http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ${DOVETAIL_CONFIG}
128
129 # functest needs to download this image first before running
130 echo "Download image cirros-0.3.5-x86_64-disk.img ..."
131 wget -q -nc http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img -P ${DOVETAIL_CONFIG}
132
133 opts="--privileged=true -id"
134
135 docker_volume="-v /var/run/docker.sock:/var/run/docker.sock"
136 dovetail_home_volume="-v ${DOVETAIL_HOME}:${DOVETAIL_HOME}"
137
138 # Pull the image with correct tag
139 echo "Dovetail: Pulling image opnfv/dovetail:${DOCKER_TAG}"
140 docker pull opnfv/dovetail:$DOCKER_TAG >$redirect
141
142 cmd="docker run ${opts} -e DOVETAIL_HOME=${DOVETAIL_HOME} ${docker_volume} ${dovetail_home_volume} \
143      ${sshkey} opnfv/dovetail:${DOCKER_TAG} /bin/bash"
144 echo "Dovetail: running docker run command: ${cmd}"
145 ${cmd} >${redirect}
146 sleep 5
147 container_id=$(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | awk '{print $1}' | head -1)
148 echo "Container ID=${container_id}"
149 if [ -z ${container_id} ]; then
150     echo "Cannot find opnfv/dovetail container ID ${container_id}. Please check if it is existing."
151     docker ps -a
152     exit 1
153 fi
154 echo "Container Start: docker start ${container_id}"
155 docker start ${container_id}
156 sleep 5
157 docker ps >${redirect}
158 if [ $(docker ps | grep "opnfv/dovetail:${DOCKER_TAG}" | wc -l) == 0 ]; then
159     echo "The container opnfv/dovetail with ID=${container_id} has not been properly started. Exiting..."
160     exit 1
161 fi
162
163 # Modify tempest_conf.yaml file
164 tempest_conf_file=${DOVETAIL_CONFIG}/tempest_conf.yaml
165 if [ ${INSTALLER_TYPE} == 'compass' ]; then
166     volume_device='vdb'
167 else
168     volume_device='vdc'
169 fi
170
171 cat << EOF >$tempest_conf_file
172
173 compute:
174     min_compute_nodes: 2
175     volume_device_name: ${volume_device}
176     min_microversion: 2.2
177     max_microversion: latest
178
179 compute-feature-enabled:
180     live_migration: True
181     block_migration_for_live_migration: True
182     block_migrate_cinder_iscsi: True
183     attach_encrypted_volume: True
184
185 EOF
186
187 echo "${tempest_conf_file}..."
188 cat ${tempest_conf_file}
189
190 cp_tempest_cmd="docker cp ${DOVETAIL_CONFIG}/tempest_conf.yaml $container_id:/home/opnfv/dovetail/dovetail/userconfig"
191 echo "exec command: ${cp_tempest_cmd}"
192 $cp_tempest_cmd
193
194 list_cmd="dovetail list ${TESTSUITE}"
195 run_cmd="dovetail run --testsuite ${TESTSUITE} -d"
196 echo "Container exec command: ${list_cmd}"
197 docker exec $container_id ${list_cmd}
198 echo "Container exec command: ${run_cmd}"
199 docker exec $container_id ${run_cmd}
200
201 sudo cp -r ${DOVETAIL_HOME}/results ./
202 # To make sure the file owner is the current user, for the copied results files in the above line
203 # if not, there will be error when next time to wipe workspace
204 # CURRENT_USER=${SUDO_USER:-$USER}
205 # PRIMARY_GROUP=$(id -gn $CURRENT_USER)
206 # sudo chown -R ${CURRENT_USER}:${PRIMARY_GROUP} ${WORKSPACE}/results
207
208 #remove useless workspace from yardstick to save disk space
209 sudo rm -rf ./results/workspace
210
211 echo "Dovetail: done!"
212