Merge "Change functest branch to stable/brahmaputra"
[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 usage="Script to prepare the Functest environment.
11
12 usage:
13     bash $(basename "$0") [--offline] [-h|--help] [-t <test_name>]
14
15 where:
16     -o|--offline      optional offline mode (experimental)
17     -h|--help         show this help text
18
19 examples:
20     $(basename "$0")
21     $(basename "$0") --offline"
22
23 offline=false
24
25 # Parse parameters
26 while [[ $# > 0 ]]
27     do
28     key="$1"
29     case $key in
30         -h|--help)
31             echo "$usage"
32             exit 0
33             shift
34         ;;
35         -o|--offline)
36             offline=true
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 # Support for Functest offline
50 # NOTE: Still not 100% working when running the tests
51
52 info "######### Preparing Functest environment #########"
53 if [ $offline == false ]; then
54     info "MODE: online"
55 else
56     info "MODE: offline"
57 fi
58
59 # definition of available installer names
60 INSTALLERS=(fuel compass apex joid)
61
62 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
63     # If credentials file is not given, check if environment variables are set
64     # to get the creds using fetch_os_creds.sh later on
65     info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
66     if [ -z ${INSTALLER_TYPE} ]; then
67         error "Environment variable 'INSTALLER_TYPE' is not defined."
68     elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
69         info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
70     else
71         error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
72     fi
73
74     if [ -z ${INSTALLER_IP} ]; then
75         error "Environment variable 'INSTALLER_IP' is not defined."
76     fi
77     info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
78 fi
79
80
81 if [ $offline == false ]; then
82     # Update repos
83     info "Updating Functest repository...."
84     cd ${FUNCTEST_REPO_DIR}
85     info "Functest repo: pulling to latest..."
86     git pull
87     if [ ${FUNCTEST_COMMIT} != "latest" ]; then
88         info "Functest repo: given commit is ${FUNCTEST_COMMIT}. Reseting..."
89         git reset --hard ${FUNCTEST_COMMIT}
90     fi
91     source ${BASEDIR}/common.sh
92
93     info "Updating Releng repository...."
94     cd ${RELENG_REPO_DIR}
95     if [ ${RELENG_BRANCH} != "master" ]; then
96         info "Releng repo: checkout ${RELENG_BRANCH} branch..."
97         git checkout ${RELENG_BRANCH}
98     fi
99     info "Releng repo: pulling to latest..."
100     git pull
101     if [ ${RELENG_COMMIT} != "latest" ]; then
102         info "Releng repo: given commit is ${RELENG_COMMIT}. Reseting..."
103         git reset --hard ${RELENG_COMMIT}
104     fi
105
106     info "Updating Rally repository...."
107     cd ${RALLY_REPO_DIR}
108     if [ ${RALLY_BRANCH} != "master" ]; then
109         info "Rally repo: checkout ${RALLY_BRANCH} branch..."
110         git checkout ${RALLY_BRANCH}
111     fi
112     info "Rally repo: pulling to latest..."
113     git pull
114     # We leave the reset command for later.
115
116     info "Updating vIMS test repository...."
117     cd ${VIMS_REPO_DIR}
118     if [ ${VIMS_BRANCH} != "stable" ]; then
119         info "Releng repo: checkout ${VIMS_TEST_BRANCH} branch..."
120         git checkout ${VIMS_BRANCH}
121     fi
122     info "vIMS test repo: pulling to latest..."
123     git pull
124     if [ ${VIMS_COMMIT} != "latest" ]; then
125         info "vIMS test repo: given commit is ${VIMS_TEST_COMMIT}. Reseting..."
126         git reset --hard ${VIMS_COMMIT}
127     fi
128
129     info "Updating BGPVPN repository...."
130     cd ${BGPVPN_REPO_DIR}
131     if [ ${BGPVPN_BRANCH} != "master" ]; then
132         info "BGPVPN repo: checkout ${BGPVPN_BRANCH} branch..."
133         git checkout ${BGPVPN_BRANCH}
134     fi
135     info "BGPVPN repo: pulling to latest..."
136     git pull
137     if [ ${BGPVPN_COMMIT} != "latest" ]; then
138         info "BGPVPN repo: given commit is ${BGPVPN_COMMIT}. Reseting..."
139         git reset --hard ${BGPVPN_COMMIT}
140     fi
141
142     info "Updating ONOS repository...."
143     cd ${ONOS_REPO_DIR}
144     if [ ${ONOS_BRANCH} != "master" ]; then
145         info "ONOS repo: checkout ${ONOS} branch..."
146         git checkout ${ONOS_BRANCH}
147     fi
148     info "ONOS repo: pulling to latest..."
149     git pull
150     if [ ${ONOS_COMMIT} != "latest" ]; then
151         info "ONOS repo: given commit is ${ONOS_COMMIT}. Reseting..."
152         git reset --hard ${ONOS_COMMIT}
153     fi
154
155     info "Updating PROMISE repository...."
156     cd ${PROMISE_REPO_DIR}
157     if [ ${PROMISE_BRANCH} != "master" ]; then
158         info "PROMISE repo: checkout ${PROMISE} branch..."
159         git checkout ${PROMISE_BRANCH}
160     fi
161     info "PROMISE repo: pulling to latest..."
162     git pull
163     if [ ${PROMISE_COMMIT} != "latest" ]; then
164         info "PROMISE repo: given commit is ${PROMISE_COMMIT}. Reseting..."
165         git reset --hard ${PROMISE_COMMIT}
166     fi
167
168 fi
169
170 # We do this regardless if its online or offline mode.
171 # Assumption: the docker image contains a newer rally repo than the given commit.
172 if [ ${RALLY_COMMIT} != "latest" ]; then
173     cd ${RALLY_REPO_DIR}
174     info "Rally repo: given commit is ${RALLY_COMMIT}. Reseting..."
175     git reset --hard ${RALLY_COMMIT}
176 fi
177
178
179 # Create directories
180 mkdir -p ${FUNCTEST_CONF_DIR}
181 mkdir -p ${FUNCTEST_DATA_DIR}
182 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
183
184
185
186 # Create Openstack credentials file
187 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
188     ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${FUNCTEST_CONF_DIR}/openstack.creds \
189         -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
190     retval=$?
191     if [ $retval != 0 ]; then
192         error "Cannot retrieve credentials file from installation. Check logs."
193         exit $retval
194     fi
195 else
196     info "OpenStack credentials file given to the docker and stored in ${FUNCTEST_CONF_DIR}/openstack.creds."
197 fi
198 # Source credentials
199 source ${FUNCTEST_CONF_DIR}/openstack.creds
200
201 # Check OpenStack
202 info "Checking that the basic OpenStack services are functional..."
203 ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/check_os.sh
204 RETVAL=$?
205 if [ $RETVAL -ne 0 ]; then
206     exit 1
207 fi
208
209 # Prepare Functest Environment
210 info "Functest: prepare Functest environment"
211 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py --debug start
212 retval=$?
213 if [ $retval != 0 ]; then
214     error "Error when configuring Functest environment"
215     exit $retval
216 fi
217
218 ifconfig eth0 mtu 1450
219
220 echo "1" > ${FUNCTEST_CONF_DIR}/env_active