Compass: add cacert file to enable SSL verification
[releng.git] / jjb / functest / set-functest-env.sh
index 569f371..72a9e1e 100755 (executable)
@@ -1,54 +1,23 @@
 #!/bin/bash
 
 set -e
-[[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
-# LAB_CONFIG is used only for joid
+set +u
+set +o pipefail
 
+[[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
 
+# Prepare OpenStack credentials volume
 if [[ ${INSTALLER_TYPE} == 'joid' ]]; then
-    # If production lab then creds may be retrieved dynamically
-    # creds are on the jumphost, always in the same folder
     rc_file_vol="-v $LAB_CONFIG/admin-openrc:/home/opnfv/functest/conf/openstack.creds"
-    # If dev lab, credentials may not be the default ones, just provide a path to put them into docker
-    # replace the default one by the customized one provided by jenkins config
-fi
-
-if [[ ${RC_FILE_PATH} != '' ]] && [[ -f ${RC_FILE_PATH} ]] ; then
-    echo "Credentials file detected: ${RC_FILE_PATH}"
-    # volume if credentials file path is given to Functest
-    rc_file_vol="-v ${RC_FILE_PATH}:/home/opnfv/functest/conf/openstack.creds"
-    RC_FLAG=1
-fi
-
-
-if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
-    ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
-    if sudo virsh list | grep undercloud; then
-        echo "Installer VM detected"
-        undercloud_mac=$(sudo virsh domiflist undercloud | grep default | \
-                      grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
-        INSTALLER_IP=$(/usr/sbin/arp -e | grep ${undercloud_mac} | awk {'print $1'})
-        sshkey_vol="-v /root/.ssh/id_rsa:/root/.ssh/id_rsa"
-        sudo scp $ssh_options root@${INSTALLER_IP}:/home/stack/stackrc ${HOME}/stackrc
-        stackrc_vol="-v ${HOME}/stackrc:/home/opnfv/functest/conf/stackrc"
-
-        if sudo iptables -C FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable 2> ${redirect}; then
-            sudo iptables -D FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-        fi
-        if sudo iptables -C FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable 2> ${redirect}; then
-          sudo iptables -D FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-        fi
-    elif [[ "$RC_FLAG" == 1 ]]; then
-        echo "No available installer VM, but credentials provided...continuing"
-    else
-        echo "No available installer VM exists and no credentials provided...exiting"
-        exit 1
-    fi
-
+elif [[ ${INSTALLER_TYPE} == 'compass' && ${BRANCH} == 'master' ]]; then
+    cacert_file_vol="-v ${HOME}/os_cacert:/home/opnfv/functest/conf/os_cacert"
+    echo "export OS_CACERT=/home/opnfv/functest/conf/os_cacert" >> ${HOME}/opnfv-openrc.sh
+    rc_file_vol="-v ${HOME}/opnfv-openrc.sh:/home/opnfv/functest/conf/openstack.creds"
+else
+    rc_file_vol="-v ${HOME}/opnfv-openrc.sh:/home/opnfv/functest/conf/openstack.creds"
 fi
 
 
-
 # Set iptables rule to allow forwarding return traffic for container
 if ! sudo iptables -C FORWARD -j RETURN 2> ${redirect} || ! sudo iptables -L FORWARD | awk 'NR==3' | grep RETURN 2> ${redirect}; then
     sudo iptables -I FORWARD -j RETURN
@@ -59,6 +28,14 @@ DEPLOY_TYPE=baremetal
 
 echo "Functest: Start Docker and prepare environment"
 
+if [ "$BRANCH" != 'stable/danube' ]; then
+  echo "Functest: Download images that will be used by test cases"
+  images_dir="${HOME}/opnfv/functest/images"
+  chmod +x ${WORKSPACE}/functest/ci/download_images.sh
+  ${WORKSPACE}/functest/ci/download_images.sh ${images_dir} 2> ${redirect}
+  images_vol="-v ${images_dir}:/home/opnfv/functest/images"
+fi
+
 dir_result="${HOME}/opnfv/functest/results/${BRANCH##*/}"
 mkdir -p ${dir_result}
 sudo rm -rf ${dir_result}/*
@@ -80,7 +57,11 @@ if [[ ${INSTALLER_TYPE} == 'compass' && ${DEPLOY_SCENARIO} == *'os-nosdn-openo-h
     envs=${env}" -e OPENO_MSB_ENDPOINT=${openo_msb_endpoint}"
 fi
 
-volumes="${results_vol} ${sshkey_vol} ${stackrc_vol} ${rc_file_vol}"
+if [ "$BRANCH" != 'stable/danube' ]; then
+  volumes="${images_vol} ${results_vol} ${sshkey_vol} ${stackrc_vol} ${rc_file_vol} ${cacert_file_vol}"
+else
+  volumes="${results_vol} ${sshkey_vol} ${stackrc_vol} ${rc_file_vol}"
+fi
 
 HOST_ARCH=$(uname -m)
 FUNCTEST_IMAGE="opnfv/functest"
@@ -88,7 +69,7 @@ if [ "$HOST_ARCH" = "aarch64" ]; then
     FUNCTEST_IMAGE="${FUNCTEST_IMAGE}_${HOST_ARCH}"
 fi
 
-echo "Functest: Pulling image ${FUNCTEST_IMAGE}:${DOCKER_TAG}"
+echo "Functest: Pulling Functest Docker image ${FUNCTEST_IMAGE}:${DOCKER_TAG}"
 docker pull ${FUNCTEST_IMAGE}:$DOCKER_TAG >/dev/null
 
 cmd="sudo docker run --privileged=true -id ${envs} ${volumes} \
@@ -112,12 +93,13 @@ if [ $(docker ps | grep "${FUNCTEST_IMAGE}:${DOCKER_TAG}" | wc -l) == 0 ]; then
     echo "The container ${FUNCTEST_IMAGE} with ID=${container_id} has not been properly started. Exiting..."
     exit 1
 fi
-if [[ "$BRANCH" =~ 'brahmaputra' ]]; then
-    cmd="${FUNCTEST_REPO_DIR}/docker/prepare_env.sh"
-elif [[ "$BRANCH" =~ 'colorado' ]]; then
-    cmd="python ${FUNCTEST_REPO_DIR}/ci/prepare_env.py start"
+
+if [ "$BRANCH" == 'master' ]; then
+    cmd="prepare_env start"
 else
     cmd="python ${FUNCTEST_REPO_DIR}/functest/ci/prepare_env.py start"
 fi
+
+
 echo "Executing command inside the docker: ${cmd}"
 docker exec ${container_id} ${cmd}