Add local support for config preparation before testing
[bottlenecks.git] / utils / env_prepare / config_prepare.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 # This file is to prepare the openstack certs and pod description that required
11 # for Bottlenecks tests.
12 usage="Script to prepare the configurations before testing.
13
14 usage:
15     bash $(basename "$0") [-h|--help] [-i <installer>] [--debug]
16
17 where:
18     -h|--help         show the help text
19     -i|--installer    input the name of the installer
20       <installer>         one of the following:
21                               (compass, fuel, joid, apex)
22     --debug
23                       debug option switch
24 examples:
25     $(basename "$0") -i compass"
26
27 # Debug option
28 redirect="/dev/null"
29
30 # Process input variables
31 while [[ $# > 0 ]]
32     do
33     key="$1"
34     case $key in
35         -h|--help)
36             echo "$usage"
37             exit 0
38             shift
39         ;;
40         -i|--installer)
41             INSTALLER_TYPE="$2"
42             shift
43         ;;
44         --debug)
45             redirect="/dev/stdout"
46             shift
47         ;;
48     esac
49     shift
50 done
51
52 # Define alias for log printing
53 info () {
54     logger -s -t "BOTTLENECKS INFO" "$*"
55 }
56
57 error () {
58     logger -s -t "BOTTLENECKS ERROR" "$*"
59     exit 1
60 }
61
62 # Define Variables
63 echo "BOTTLENECKS INFO: Downloading Releng"
64 RELENG_REPO="/home/releng"
65 [ -d ${RELENG_REPO} ] && rm -rf ${RELENG_REPO}
66 git clone https://gerrit.opnfv.org/gerrit/releng ${RELENG_REPO} >${redirect}
67
68 echo "BOTTLENECKS INFO: Downloading Yardstick"
69 YARDSTICK_REPO="/home/yardstick"
70 [ -d ${YARDSTICK_REPO} ] && rm -rf ${YARDSTICK_REPO}
71 git clone https://gerrit.opnfv.org/gerrit/yardstick ${YARDSTICK_REPO} >${redirect}
72
73 BOTTLENECKS_CONFIG=/tmp
74
75 OPENRC=${BOTTLENECKS_CONFIG}/admin_rc.sh
76 OS_CACERT=${BOTTLENECKS_CONFIG}/os_cacert
77
78 # Preparing configuration files for testing
79 if [[ ${INSTALLER_TYPE} != "" ]]; then
80     # Preparing OpenStack RC and Cacert files
81     info "fetching os credentials from $INSTALLER_TYPE"
82     if [[ $INSTALLER_TYPE == 'compass' ]]; then
83         export BRANCH="master"
84         INSTALLER_IP=192.168.200.2
85         if [[ ${BRANCH} == 'master' ]]; then
86             ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${OS_CACERT} >${redirect}
87             if [[ -f ${OS_CACERT} ]]; then
88                 echo "BOTTLENECKS INFO: successfully fetching os_cacert for openstack: ${OS_CACERT}"
89             else
90                 echo "BOTTLENECKS ERROR: couldn't find os_cacert file: ${OS_CACERT}, please check if the it's been properly provided."
91                 exit 1
92             fi
93         else
94             ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}  >${redirect}
95         fi
96     else
97         error "The isntaller is not specified"
98         exit 1
99     fi
100
101     if [[ -f ${OPENRC} ]]; then
102         echo "BOTTLENECKS INFO: openstack credentials path is ${OPENRC}"
103         if [[ $INSTALLER_TYPE == 'compass' && ${BRANCH} == 'master' ]]; then
104             echo "BOTTLENECKS INFO: writing ${OS_CACERT} to ${OPENRC}"
105             echo "export OS_CACERT=${OS_CACERT}" >> ${OPENRC}
106         fi
107         cat ${OPENRC}
108     else
109         echo "BOTTLENECKS ERROR: couldn't find openstack rc file: ${OPENRC}, please check if the it's been properly provided."
110         exit 1
111     fi
112
113     # Finding and crearting POD description files from different deployments
114     ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
115
116     if [ "$INSTALLER_TYPE" == "fuel" ]; then
117         echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
118         sshpass -p r00tme sudo scp $ssh_options root@${INSTALLER_IP}:~/.ssh/id_rsa ${BOTTLENECKS_CONFIG}/id_rsa
119     fi
120
121     if [ "$INSTALLER_TYPE" == "apex" ]; then
122         echo "Fetching id_rsa file from jump_server $INSTALLER_IP..."
123         sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${BOTTLENECKS_CONFIG}/id_rsa
124     fi
125
126     if [[ ${INSTALLER_TYPE} == compass ]]; then
127         options="-u root -p root"
128     elif [[ ${INSTALLER_TYPE} == fuel ]]; then
129         options="-u root -p r00tme"
130     elif [[ ${INSTALLER_TYPE} == apex ]]; then
131         options="-u stack -k /root/.ssh/id_rsa"
132     else
133         echo "Don't support to generate pod.yaml on ${INSTALLER_TYPE} currently."
134     fi
135
136     if [[ ${INSTALLER_TYPE} != compass ]]; then
137         cmd="sudo python ${RELENG_REPO}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
138          -i ${INSTALLER_IP} ${options} -f ${BOTTLENECKS_CONFIG}/pod.yaml \
139          -s ${BOTTLENECKS_CONFIG}/id_rsa"
140         echo ${cmd}
141         ${cmd}
142     else
143         cmd="sudo cp ${YARDSTICK_REPO}/etc/yardstick/nodes/compass_sclab_virtual/pod.yaml \
144         ${BOTTLENECKS_CONFIG}"
145         echo ${cmd}
146         ${cmd}
147     fi
148
149     if [ -f ${BOTTLENECKS_CONFIG}/pod.yaml ]; then
150         echo "FILE: ${BOTTLENECKS_CONFIG}/pod.yaml:"
151         cat ${BOTTLENECKS_CONFIG}/pod.yaml
152     else
153         echo "ERROR: cannot find file ${BOTTLENECKS_CONFIG}/pod.yaml. Please check if it is existing."
154         sudo ls -al ${BOTTLENECKS_CONFIG}
155     fi
156 fi