Bugfix: Fix a bug that cause yardstick-trusty-server image build fail
[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 if [ "$NODE_NAME" == "huawei-pod1" ]; then
61     bash $YARDSTICK_REPO_DIR/tests/ci/scp_storperf_admin-rc.sh
62 fi
63
64 # Fetching id_rsa file from jump_server..."
65 verify_connectivity() {
66     local ip=$1
67     echo "Verifying connectivity to $ip..."
68     for i in $(seq 0 10); do
69         if ping -c 1 -W 1 $ip > /dev/null; then
70             echo "$ip is reachable!"
71             return 0
72         fi
73         sleep 1
74     done
75     error "Can not talk to $ip."
76 }
77
78 YARD_IMG_ARCH=amd64
79 export YARD_IMG_ARCH
80
81 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
82
83 if [ "$INSTALLER_TYPE" == "fuel" ]; then
84     #ip_fuel="10.20.0.2"
85     verify_connectivity $INSTALLER_IP
86     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
87     sshpass -p r00tme scp 2>/dev/null $ssh_options \
88     root@${INSTALLER_IP}:~/.ssh/id_rsa /root/.ssh/id_rsa &> /dev/null
89
90     ARCH_SCRIPT="test -f /etc/fuel_openstack_arch && grep -q arm64 /etc/fuel_openstack_arch"
91     sshpass -p r00tme ssh $ssh_options -l root $INSTALLER_IP "${ARCH_SCRIPT}" && YARD_IMG_ARCH=arm64
92     export YARD_IMG_ARCH
93
94     if ! grep -q "Defaults env_keep += \"YARD_IMG_ARCH\"" "/etc/sudoers"; then
95         sudo echo "Defaults env_keep += \"YARD_IMG_ARCH YARDSTICK_REPO_DIR\"" >> /etc/sudoers
96     fi
97
98     sshpass -p r00tme ssh 2>/dev/null $ssh_options \
99         root@${INSTALLER_IP} fuel node>fuel_node
100
101     controller_ips=($(cat fuel_node|grep controller|awk '{print $10}'))
102     compute_ips=($(cat fuel_node|grep compute|awk '{print $10}'))
103
104     pod_yaml="./etc/yardstick/nodes/fuel_baremetal/pod.yaml"
105
106     if [[ ${controller_ips[0]} ]]; then
107         sed -i "s/ip1/${controller_ips[0]}/" $pod_yaml;
108     fi
109     if [[ ${controller_ips[1]} ]]; then
110         sed -i "s/ip2/${controller_ips[1]}/" $pod_yaml;
111     fi
112     if [[ ${controller_ips[2]} ]]; then
113         sed -i "s/ip3/${controller_ips[2]}/" $pod_yaml;
114     fi
115     if [[ ${compute_ips[0]} ]]; then
116         sed -i "s/ip4/${compute_ips[0]}/" $pod_yaml;
117     fi
118     if [[ ${compute_ips[1]} ]]; then
119         sed -i "s/ip5/${compute_ips[1]}/" $pod_yaml;
120     fi
121
122 fi
123