Small adaptations in prepare_env,run_tests and common
[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 debug=""
50 if [[ "${CI_DEBUG,,}" == "true" ]];then
51     debug="--debug"
52 fi
53
54
55 info "######### Preparing Functest environment #########"
56
57 # definition of available installer names
58 INSTALLERS=(fuel compass apex joid)
59
60 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
61     # If credentials file is not given, check if environment variables are set
62     # to get the creds using fetch_os_creds.sh later on
63     info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
64     if [ -z ${INSTALLER_TYPE} ]; then
65         error "Environment variable 'INSTALLER_TYPE' is not defined."
66     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
67         info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
68     else
69         error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
70     fi
71
72     if [ -z ${INSTALLER_IP} ]; then
73         error "Environment variable 'INSTALLER_IP' is not defined."
74     fi
75     info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
76 fi
77
78
79 # Create directories
80 mkdir -p ${FUNCTEST_CONF_DIR}
81 mkdir -p ${FUNCTEST_DATA_DIR}
82 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
83
84
85 # Create Openstack credentials file
86 # $creds is an env varialbe in the docker container pointing to
87 # /home/opnfv/functest/conf/openstack.creds
88 if [ ! -f ${creds} ]; then
89     ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${creds} \
90         -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
91     retval=$?
92     if [ $retval != 0 ]; then
93         error "Cannot retrieve credentials file from installation. Check logs."
94         exit $retval
95     fi
96 else
97     info "OpenStack credentials file given to the docker and stored in ${FUNCTEST_CONF_DIR}/openstack.creds."
98 fi
99
100 # If we use SSL, by default use option OS_INSECURE=true which means that
101 # the cacert will be self-signed
102 if grep -Fq "OS_CACERT" ${creds}; then
103     echo "OS_INSECURE=true">>${creds};
104 fi
105
106 # Source credentials
107 source ${creds}
108
109 # Check OpenStack
110 info "Checking that the basic OpenStack services are functional..."
111 ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/check_os.sh
112 RETVAL=$?
113 if [ $RETVAL -ne 0 ]; then
114     exit 1
115 fi
116
117 # Prepare Functest Environment
118 info "Preparing Functest environment..."
119 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py $debug start
120 retval=$?
121 if [ $retval != 0 ]; then
122     error "Error when configuring Functest environment"
123     exit $retval
124 fi
125
126
127 # Generate OpenStack defaults
128 info "Generating OpenStack defaults..."
129 python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/generate_defaults.py -d
130
131 ifconfig eth0 mtu 1450
132
133 echo "1" > ${FUNCTEST_CONF_DIR}/env_active