Merge "bug-fix: add BRANCH var for apex config prep"
[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                               (apex, compass, fuel, joid)
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         *)
49             echo "unkown option $1 $2"
50             exit 1
51         ;;
52     esac
53     shift
54 done
55
56 # Define alias for log printing
57 info () {
58     logger -s -t "BOTTLENECKS INFO" "$*"
59 }
60
61 error () {
62     logger -s -t "BOTTLENECKS ERROR" "$*"
63     exit 1
64 }
65
66 # Repo and configs
67 RELENG_REPO="/home/releng"
68 BOTTLENECKS_CONFIG=/tmp
69 OPENRC=${BOTTLENECKS_CONFIG}/admin_rc.sh
70 OS_CACERT=${BOTTLENECKS_CONFIG}/os_cacert
71
72
73 ##############################################################################
74 # Preparing scripts for openstack and pod configs for OPNFV Installers
75 ##############################################################################
76 # Define Variables
77 info "Downloading Releng fetch_os_creds script for openstack/pod configs of OPNFV installers"
78
79 [ -d ${RELENG_REPO} ] && rm -rf ${RELENG_REPO}
80 git clone https://gerrit.opnfv.org/gerrit/releng ${RELENG_REPO} >${redirect}
81
82 info "Downloading Yardstick for pod configs of OPNFV installers"
83 YARDSTICK_REPO="/home/yardstick"
84 [ -d ${YARDSTICK_REPO} ] && rm -rf ${YARDSTICK_REPO}
85 git clone https://gerrit.opnfv.org/gerrit/yardstick ${YARDSTICK_REPO} >${redirect}
86
87 # Preparing configuration files for testing
88 if [[ ${INSTALLER_TYPE} != "" ]]; then
89     # Preparing OpenStack RC and Cacert files
90     info "fetching os credentials from $INSTALLER_TYPE"
91     if [[ $INSTALLER_TYPE == 'compass' ]]; then
92         export BRANCH="master"
93         INSTALLER_IP=192.168.200.2
94         if [[ ${BRANCH} == 'master' ]]; then
95             ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${OS_CACERT} >${redirect}
96         else
97             ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}  >${redirect}
98         fi
99     elif [[ $INSTALLER_TYPE == 'apex' ]]; then
100         export BRANCH="stable/fraser"
101         INSTALLER_IP=$(sudo virsh domifaddr undercloud | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
102         ${RELENG_REPO}/utils/fetch_os_creds.sh -d ${OPENRC} -i ${INSTALLER_TYPE} -a ${INSTALLER_IP} -o ${OS_CACERT} >${redirect}
103         echo ${cmd}
104         ${cmd}
105     else
106         error "The installer is not specified"
107         exit 1
108     fi
109
110     # Finding and crearting POD description files from different deployments
111     if [[ ${INSTALLER_TYPE} == 'compass' ]]; then
112         cmd="sudo cp ${YARDSTICK_REPO}/etc/yardstick/nodes/compass_sclab_virtual/pod.yaml \
113         ${BOTTLENECKS_CONFIG}"
114         info ${cmd}
115         ${cmd}
116     elif [[ ${INSTALLER_TYPE} == 'apex' ]]; then
117         sudo pip install virtualenv
118
119         sudo virtualenv venv
120         source venv/bin/activate
121         sudo pip install -e ${RELENG_REPO}/modules/ >/dev/null
122         sudo pip install netaddr
123
124         options="-u stack -k /root/.ssh/id_rsa"
125         cmd="sudo python ${RELENG_REPO}/utils/create_pod_file.py -t ${INSTALLER_TYPE} \
126          -i ${INSTALLER_IP} ${options} -f ${BOTTLENECKS_CONFIG}/pod.yaml"
127         info ${cmd}
128         ${cmd}
129
130         ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
131         cmd="sudo scp $ssh_options stack@${INSTALLER_IP}:~/.ssh/id_rsa ${BOTTLENECKS_CONFIG}/id_rsa"
132         info ${cmd}
133         ${cmd}
134
135         deactivate
136     fi
137
138
139     ##############################################################################
140     # Check the existence of the output configs for OPNFV Installers
141     ##############################################################################
142     # Checking the pod decription file
143     if [ -f ${BOTTLENECKS_CONFIG}/pod.yaml ]; then
144         info "FILE - ${BOTTLENECKS_CONFIG}/pod.yaml:"
145         cat ${BOTTLENECKS_CONFIG}/pod.yaml
146     else
147         error "Cannot find file ${BOTTLENECKS_CONFIG}/pod.yaml. Please check if it is existing."
148         sudo ls -al ${BOTTLENECKS_CONFIG}
149     fi
150
151     # Checking the openstack rc and os_cacert file
152     if [[ -f ${OPENRC} ]]; then
153         info "Opentack credentials path is ${OPENRC}"
154         if [[ -f ${OS_CACERT} ]]; then
155             info "Writing ${OS_CACERT} to ${OPENRC}"
156             echo "export OS_CACERT=${OS_CACERT}" >> ${OPENRC}
157             cat ${OPENRC}
158         else
159            info "Couldn't find openstack cacert file: ${OS_CACERT}, please check if the it's been properly provided."
160        fi
161     else
162         error "Couldn't find openstack rc file: ${OPENRC}, please check if the it's been properly provided."
163         exit 1
164     fi
165
166     # Checking ssh key id_rsa
167     if [[ -f "/tmp/id_rsa" ]]; then
168         info "Path of ssh key file for openstack nodes is /tmp/id_rsa"
169     else
170         info "Couldn't find the ssh key file for openstack nodes. If you are using user/pwd in pod.yaml, please ignore."
171     fi
172 fi