ipv6 testcase to support fuel
[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 # Extract network name from EXTERNAL_NETWORK
19 #  e.g. EXTERNAL_NETWORK='ext-net;flat;192.168.0.2;192.168.0.253;192.168.0.1;192.168.0.0/24'
20 export EXTERNAL_NETWORK=$(echo $EXTERNAL_NETWORK | cut -f1 -d \;)
21
22 # Create openstack credentials
23 echo "INFO: Creating openstack credentials .."
24 OPENRC=/home/opnfv/openrc
25 INSTALLERS=(apex compass fuel joid)
26
27 if [ ! -f $OPENRC ]; then
28     # credentials file is not given, check if environment variables are set
29     # to get the creds using fetch_os_creds.sh later on
30     echo "INFO: Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
31     if [ -z ${INSTALLER_TYPE} ]; then
32         echo "environment variable 'INSTALLER_TYPE' is not defined."
33         exit 1
34     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
35         echo "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
36     else
37         echo "Invalid env variable INSTALLER_TYPE=${INSTALLER_TYPE}"
38         exit 1
39     fi
40
41     if [ "$DEPLOY_TYPE" == "virt" ]; then
42         FETCH_CRED_ARG="-v -d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
43     else
44         FETCH_CRED_ARG="-d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
45     fi
46
47     $RELENG_REPO_DIR/utils/fetch_os_creds.sh $FETCH_CRED_ARG
48
49 fi
50
51 source $OPENRC
52
53 export EXTERNAL_NETWORK INSTALLER_TYPE DEPLOY_TYPE NODE_NAME
54
55 # Prepare a admin-rc file for StorPerf integration
56 $YARDSTICK_REPO_DIR/tests/ci/prepare_storperf_admin-rc.sh
57
58 # copy a admin-rc file for StorPerf integration to the deployment location
59 if [ "$NODE_NAME" == "huawei-pod1" ]; then
60     bash $YARDSTICK_REPO_DIR/tests/ci/scp_storperf_admin-rc.sh
61 fi
62
63 # Fetching id_rsa file from jump_server..."
64 verify_connectivity() {
65     local ip=$1
66     echo "Verifying connectivity to $ip..."
67     for i in $(seq 0 10); do
68         if ping -c 1 -W 1 $ip > /dev/null; then
69             echo "$ip is reachable!"
70             return 0
71         fi
72         sleep 1
73     done
74     error "Can not talk to $ip."
75 }
76
77 YARD_IMG_ARCH=amd64
78 export YARD_IMG_ARCH
79
80 if ! grep -q "Defaults env_keep += \"YARD_IMG_ARCH\"" "/etc/sudoers"; then
81     sudo echo "Defaults env_keep += \"YARD_IMG_ARCH YARDSTICK_REPO_DIR\"" >> /etc/sudoers
82 fi
83
84 ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
85
86 if [ "$INSTALLER_TYPE" == "fuel" ]; then
87     #ip_fuel="10.20.0.2"
88     verify_connectivity $INSTALLER_IP
89     echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
90     sshpass -p r00tme scp 2>/dev/null $ssh_options \
91     root@${INSTALLER_IP}:~/.ssh/id_rsa /root/.ssh/id_rsa &> /dev/null
92
93     ARCH_SCRIPT="test -f /etc/fuel_openstack_arch && grep -q arm64 /etc/fuel_openstack_arch"
94     sshpass -p r00tme ssh $ssh_options -l root $INSTALLER_IP "${ARCH_SCRIPT}" && YARD_IMG_ARCH=arm64
95
96     sshpass -p r00tme ssh 2>/dev/null $ssh_options \
97         root@${INSTALLER_IP} fuel node>fuel_node
98
99     # update fuel node id and ip info according to the CI env
100     controller_IDs=($(cat fuel_node|grep controller|awk '{print $1}'))
101     compute_IDs=($(cat fuel_node|grep compute|awk '{print $1}'))
102     controller_ips=($(cat fuel_node|grep controller|awk '{print $10}'))
103     compute_ips=($(cat fuel_node|grep compute|awk '{print $10}'))
104
105     pod_yaml="./etc/yardstick/nodes/fuel_baremetal/pod.yaml"
106     node_line_num=($(grep -n node[1-5] $pod_yaml | awk -F: '{print $1}'))
107
108     if [[ ${controller_ips[0]} ]]; then
109         sed -i "${node_line_num[0]}s/node1/node${controller_IDs[0]}/;s/ip1/${controller_ips[0]}/" $pod_yaml;
110     fi
111     if [[ ${controller_ips[1]} ]]; then
112         sed -i "${node_line_num[1]}s/node2/node${controller_IDs[1]}/;s/ip2/${controller_ips[1]}/" $pod_yaml;
113     fi
114     if [[ ${controller_ips[2]} ]]; then
115         sed -i "${node_line_num[2]}s/node3/node${controller_IDs[2]}/;s/ip3/${controller_ips[2]}/" $pod_yaml;
116     fi
117     if [[ ${compute_ips[0]} ]]; then
118         sed -i "${node_line_num[3]}s/node4/node${compute_IDs[0]}/;s/ip4/${compute_ips[0]}/" $pod_yaml;
119     fi
120     if [[ ${compute_ips[1]} ]]; then
121         sed -i "${node_line_num[4]}s/node5/node${compute_IDs[1]}/;s/ip5/${compute_ips[1]}/" $pod_yaml;
122     fi
123
124 fi