BugFix: fix storperf_admin-rc problem
[yardstick.git] / tests / ci / prepare_env.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB, Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Perepare the environment to run yardstick ci
12
13 : ${DEPLOY_TYPE:='bm'} # Can be any of 'bm' (Bare Metal) or 'virt' (Virtual)
14
15 : ${NODE_NAME:='unknown'}
16 : ${EXTERNAL_NETWORK:='admin_floating_net'}
17
18
19 # Extract network name from EXTERNAL_NETWORK
20 #  e.g. EXTERNAL_NETWORK='ext-net;flat;192.168.0.2;192.168.0.253;192.168.0.1;192.168.0.0/24'
21 export EXTERNAL_NETWORK=$(echo $EXTERNAL_NETWORK | cut -f1 -d \;)
22
23 # Create openstack credentials
24 echo "INFO: Creating openstack credentials .."
25 OPENRC=/home/opnfv/openrc
26 INSTALLERS=(apex compass fuel joid)
27
28 if [ ! -f $OPENRC ]; then
29     # credentials file is not given, check if environment variables are set
30     # to get the creds using fetch_os_creds.sh later on
31     echo "INFO: Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
32     if [ -z ${INSTALLER_TYPE} ]; then
33         echo "environment variable 'INSTALLER_TYPE' is not defined."
34         exit 1
35     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
36         echo "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
37     else
38         echo "Invalid env variable INSTALLER_TYPE=${INSTALLER_TYPE}"
39         exit 1
40     fi
41
42     if [ "$DEPLOY_TYPE" == "virt" ]; then
43         FETCH_CRED_ARG="-v -d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
44     else
45         FETCH_CRED_ARG="-d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
46     fi
47
48     $RELENG_REPO_DIR/utils/fetch_os_creds.sh $FETCH_CRED_ARG
49
50 fi
51
52 source $OPENRC
53
54 export EXTERNAL_NETWORK INSTALLER_TYPE DEPLOY_TYPE NODE_NAME
55
56 # Prepare a admin-rc file for StorPerf integration
57 $YARDSTICK_REPO_DIR/tests/ci/prepare_storperf_admin-rc.sh
58
59 # copy a admin-rc file for StorPerf integration to the deployment location
60 expect $YARDSTICK_REPO_DIR/tests/ci/scp_storperf_admin-rc.sh
61
62 # Fetching id_rsa file from jump_server..."
63 verify_connectivity() {
64     local ip=$1
65     echo "Verifying connectivity to $ip..."
66     for i in $(seq 0 10); do
67         if ping -c 1 -W 1 $ip > /dev/null; then
68             echo "$ip is reachable!"
69             return 0
70         fi
71         sleep 1
72     done
73     error "Can not talk to $ip."
74 }
75
76 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
77
78 if [ "$INSTALLER_TYPE" == "fuel" ]; then
79     #ip_fuel="10.20.0.2"
80     verify_connectivity $INSTALLER_IP
81     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
82     sshpass -p r00tme scp 2>/dev/null $ssh_options \
83     root@${INSTALLER_IP}:~/.ssh/id_rsa /root/.ssh/id_rsa &> /dev/null
84 fi
85