Fixed destintation path used for stackrc
[releng.git] / jjb / functest / set-functest-env.sh
1 #!/bin/bash
2
3 set -e
4 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
5 # labconfig is used only for joid
6 labconfig=""
7 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
8     if sudo virsh list | grep instack; then
9         instack_mac=$(sudo virsh domiflist instack | grep default | \
10                       grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
11     elif sudo virsh list | grep undercloud; then
12         instack_mac=$(sudo virsh domiflist undercloud | grep default | \
13                       grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
14     else
15         echo "No available installer VM exists...exiting"
16         exit 1
17     fi
18     INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
19     sshkey="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
20     sudo scp root@${INSTALLER_IP}:/home/stack/stackrc .
21     stackrc="-v ./stackrc:/home/opnfv/functest/conf/stackrc"
22
23     if sudo iptables -C FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable 2> ${redirect}; then
24         sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
25     fi
26     if sudo iptables -C FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable 2> ${redirect}; then
27         sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
28     fi
29 elif [[ ${INSTALLER_TYPE} == 'joid' ]]; then
30     # If production lab then creds may be retrieved dynamically
31     # creds are on the jumphost, always in the same folder
32     labconfig="-v $LAB_CONFIG/admin-openrc:/home/opnfv/functest/conf/openstack.creds"
33     # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
34     # replace the default one by the customized one provided by jenkins config
35 fi
36 echo "Functest: Start Docker and prepare environment"
37 envs="-e INSTALLER_TYPE=${INSTALLER_TYPE} -e INSTALLER_IP=${INSTALLER_IP} \
38     -e NODE_NAME=${NODE_NAME} -e DEPLOY_SCENARIO=${DEPLOY_SCENARIO} \
39     -e BUILD_TAG=${BUILD_TAG} -e CI_DEBUG=${CI_DEBUG}"
40 branch=${GIT_BRANCH##*/}
41 dir_result="${HOME}/opnfv/functest/results/${branch}"
42 mkdir -p ${dir_result}
43 sudo rm -rf ${dir_result}/*
44 res_volume="-v ${dir_result}:/home/opnfv/functest/results"
45 custom_params=
46 test -f ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG} && custom_params=$(cat ${HOME}/opnfv/functest/custom/params_${DOCKER_TAG})
47
48 echo "Functest: Pulling image opnfv/functest:${DOCKER_TAG}"
49 docker pull opnfv/functest:$DOCKER_TAG >/dev/null
50
51 cmd="sudo docker run --privileged=true -id ${envs} ${labconfig} ${sshkey} ${res_volume} ${custom_params} ${stackrc} opnfv/functest:${DOCKER_TAG} /bin/bash"
52 echo "Functest: Running docker run command: ${cmd}"
53 ${cmd} >${redirect}
54 sleep 5
55 container_id=$(docker ps | grep "opnfv/functest:${DOCKER_TAG}" | awk '{print $1}' | head -1)
56 echo "Container ID=${container_id}"
57 if [ -z ${container_id} ]; then
58     echo "Cannot find opnfv/functest container ID ${container_id}. Please check if it is existing."
59     docker ps -a
60     exit 1
61 fi
62 echo "Starting the container: docker start ${container_id}"
63 docker start ${container_id}
64 sleep 5
65 docker ps >${redirect}
66 if [ $(docker ps | grep "opnfv/functest:${DOCKER_TAG}" | wc -l) == 0 ]; then
67     echo "The container opnfv/functest with ID=${container_id} has not been properly started. Exiting..."
68     exit 1
69 fi
70 if [[ ${branch} == *"brahmaputra"* ]]; then
71     cmd="${FUNCTEST_REPO_DIR}/docker/prepare_env.sh"
72 else
73     cmd="python ${FUNCTEST_REPO_DIR}/ci/prepare_env.py start"
74 fi
75 echo "Executing command inside the docker: ${cmd}"
76 docker exec ${container_id} ${cmd}