bugfix: copy hosts file
[bottlenecks.git] / ci / prepare_env.sh
1 #!/bin/bash
2 ###############################################################################
3 # Copyright (c) 2016 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 BASEDIR=`dirname $0`
11 source ${BASEDIR}/../common.sh
12
13 info "============ Preparing bottlenecks environment ==========="
14
15 # definition of available installer names
16 INSTALLERS=(fuel compass apex joid)
17
18 if [ ! -f ${BOTTLENECKS_REPO_DIR}/config/openstack.creds ]; then
19     # If credentials file is not given, check if environment variables are set
20     # to get the creds using fetch_os_creds.sh later on
21     info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
22     if [ -z ${INSTALLER_TYPE} ]; then
23         error "Environment variable 'INSTALLER_TYPE' is not defined."
24     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
25         info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
26     else
27         error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
28     fi
29
30     if [ -z ${INSTALLER_IP} ]; then
31         error "Environment variable 'INSTALLER_IP' is not defined."
32     fi
33     info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
34 fi
35
36 # Create Openstack credentials file
37 # $creds is an env varialbe in the docker container pointing to
38 # /home/opnfv/bottlenecks/config/openstack.creds
39 if [ ! -f ${creds} ]; then
40     ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${creds} \
41         -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
42     retval=$?
43     if [ $retval != 0 ]; then
44         error "Cannot retrieve credentials file from installation. Check logs."
45         exit $retval
46     fi
47 else
48     info "OpenStack credentials file given to the docker"
49 fi
50
51 # If we use SSL, by default use option OS_INSECURE=true which means that
52 # the cacert will be self-signed
53 if grep -Fq "OS_CACERT" ${creds}; then
54     echo "OS_INSECURE=true">>${creds};
55 fi
56
57 # Source credentials
58 source ${creds}