b1aa71738e3f3e581b71b8ba97597b2558f028b6
[functest.git] / docker / prepare_env.sh
1 #!/bin/bash
2
3 #
4 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 #
6 # Installs the Functest framework within the Docker container
7 # and run the tests automatically
8 #
9 #
10 # All rights reserved. This program and the accompanying materials
11 # are made available under the terms of the Apache License, Version 2.0
12 # which accompanies this distribution, and is available at
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15
16 usage="Script to prepare the Functest environment.
17
18 usage:
19     bash $(basename "$0") [-h|--help] [-t <test_name>]
20
21 where:
22     -h|--help         show this help text
23
24 examples:
25     $(basename "$0")"
26
27
28 # Parse parameters
29 while [[ $# > 0 ]]
30     do
31     key="$1"
32     case $key in
33         -h|--help)
34             echo "$usage"
35             exit 0
36             shift
37         ;;
38         *)
39             error "unknown option $1"
40             exit 1
41         ;;
42     esac
43     shift # past argument or value
44 done
45
46 BASEDIR=`dirname $0`
47 source ${BASEDIR}/common.sh
48
49
50 info "######### Preparing Functest environment #########"
51
52 # definition of available installer names
53 INSTALLERS=(fuel compass apex joid)
54
55 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
56     # If credentials file is not given, check if environment variables are set
57     # to get the creds using fetch_os_creds.sh later on
58     info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
59     if [ -z ${INSTALLER_TYPE} ]; then
60         error "Environment variable 'INSTALLER_TYPE' is not defined."
61     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
62         info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
63     else
64         error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
65     fi
66
67     if [ -z ${INSTALLER_IP} ]; then
68         error "Environment variable 'INSTALLER_IP' is not defined."
69     fi
70     info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
71 fi
72
73
74 # Create directories
75 mkdir -p ${FUNCTEST_CONF_DIR}
76 mkdir -p ${FUNCTEST_DATA_DIR}
77 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
78
79
80 # Create Openstack credentials file
81 # $creds is an env varialbe in the docker container pointing to
82 # /home/opnfv/functest/conf/openstack.creds
83 if [ ! -f ${creds} ]; then
84     ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${creds} \
85         -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
86     retval=$?
87     if [ $retval != 0 ]; then
88         error "Cannot retrieve credentials file from installation. Check logs."
89         exit $retval
90     fi
91 else
92     info "OpenStack credentials file given to the docker and stored in ${FUNCTEST_CONF_DIR}/openstack.creds."
93 fi
94
95 # If we use SSL, by default use option OS_INSECURE=true which means that
96 # the cacert will be self-signed
97 if grep -Fq "OS_CACERT" ${creds}; then
98     echo "OS_INSECURE=true">>${creds};
99 fi
100
101 # Source credentials
102 source ${creds}
103
104 # Check OpenStack
105 info "Checking that the basic OpenStack services are functional..."
106 ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/check_os.sh
107 RETVAL=$?
108 if [ $RETVAL -ne 0 ]; then
109     exit 1
110 fi
111
112 # Prepare Functest Environment
113 info "Preparing Functest environment..."
114 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py --debug start
115 retval=$?
116 if [ $retval != 0 ]; then
117     error "Error when configuring Functest environment"
118     exit $retval
119 fi
120
121
122 # Generate OpenStack defaults
123 info "Generating OpenStack defaults..."
124 python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/generate_defaults.py -d
125
126 ifconfig eth0 mtu 1450
127
128 echo "1" > ${FUNCTEST_CONF_DIR}/env_active