Merge "Rally test case troubleshooting"
[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 foreman 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     if [ ${FUNCTEST_BRANCH} != "master" ]; then
86         info "Functest repo: checkout ${FUNCTEST_BRANCH} branch..."
87         git checkout ${FUNCTEST_BRANCH}
88     fi
89     info "Functest repo: pulling to latest..."
90     git pull
91     if [ ${FUNCTEST_COMMIT} != "latest" ]; then
92         info "Functest repo: given commit is ${FUNCTEST_COMMIT}. Reseting..."
93         git reset --hard ${FUNCTEST_COMMIT}
94     fi
95     source ${BASEDIR}/common.sh
96
97     info "Updating Releng repository...."
98     cd ${RELENG_REPO_DIR}
99     if [ ${RELENG_BRANCH} != "master" ]; then
100         info "Releng repo: checkout ${RELENG_BRANCH} branch..."
101         git checkout ${RELENG_BRANCH}
102     fi
103     info "Releng repo: pulling to latest..."
104     git pull
105     if [ ${RELENG_COMMIT} != "latest" ]; then
106         info "Releng repo: given commit is ${RELENG_COMMIT}. Reseting..."
107         git reset --hard ${RELENG_COMMIT}
108     fi
109
110     info "Updating Rally repository...."
111     cd ${RALLY_REPO_DIR}
112     if [ ${RALLY_BRANCH} != "master" ]; then
113         info "Rally repo: checkout ${RALLY_BRANCH} branch..."
114         git checkout ${RALLY_BRANCH}
115     fi
116     info "Rally repo: pulling to latest..."
117     git pull
118     # We leave the reset command for later.
119
120     info "Updating vIMS test repository...."
121     cd ${VIMS_REPO_DIR}
122     if [ ${VIMS_BRANCH} != "stable" ]; then
123         info "Releng repo: checkout ${VIMS_TEST_BRANCH} branch..."
124         git checkout ${VIMS_BRANCH}
125     fi
126     info "vIMS test repo: pulling to latest..."
127     git pull
128     if [ ${VIMS_COMMIT} != "latest" ]; then
129         info "vIMS test repo: given commit is ${VIMS_TEST_COMMIT}. Reseting..."
130         git reset --hard ${VIMS_COMMIT}
131     fi
132
133     info "Updating BGPVPN repository...."
134     cd ${BGPVPN_REPO_DIR}
135     if [ ${BGPVPN_BRANCH} != "master" ]; then
136         info "BGPVPN repo: checkout ${BGPVPN_BRANCH} branch..."
137         git checkout ${BGPVPN_BRANCH}
138     fi
139     info "BGPVPN repo: pulling to latest..."
140     git pull
141     if [ ${BGPVPN_COMMIT} != "latest" ]; then
142         info "BGPVPN repo: given commit is ${BGPVPN_COMMIT}. Reseting..."
143         git reset --hard ${BGPVPN_COMMIT}
144     fi
145
146     info "Updating ONOS repository...."
147     cd ${ONOS_REPO_DIR}
148     if [ ${ONOS_BRANCH} != "master" ]; then
149         info "ONOS repo: checkout ${ONOS} branch..."
150         git checkout ${ONOS_BRANCH}
151     fi
152     info "ONOS repo: pulling to latest..."
153     git pull
154     if [ ${ONOS_COMMIT} != "latest" ]; then
155         info "ONOS repo: given commit is ${ONOS_COMMIT}. Reseting..."
156         git reset --hard ${ONOS_COMMIT}
157     fi
158
159     info "Updating PROMISE repository...."
160     cd ${PROMISE_REPO_DIR}
161     if [ ${PROMISE_BRANCH} != "master" ]; then
162         info "PROMISE repo: checkout ${PROMISE} branch..."
163         git checkout ${PROMISE_BRANCH}
164     fi
165     info "PROMISE repo: pulling to latest..."
166     git pull
167     if [ ${PROMISE_COMMIT} != "latest" ]; then
168         info "PROMISE repo: given commit is ${PROMISE_COMMIT}. Reseting..."
169         git reset --hard ${PROMISE_COMMIT}
170     fi
171
172 fi
173
174 # We do this regardless if its online or offline mode.
175 # Assumption: the docker image contains a newer rally repo than the given commit.
176 if [ ${RALLY_COMMIT} != "latest" ]; then
177     cd ${RALLY_REPO_DIR}
178     info "Rally repo: given commit is ${RALLY_COMMIT}. Reseting..."
179     git reset --hard ${RALLY_COMMIT}
180 fi
181
182 # Ugly hack:
183 # After the 'git functest pull', we move the given yaml file to the repo directory,
184 # since some of the scripts will use that one, and not the one in
185 # /home/opnfv/functest/conf/
186 given_config_file=/home/opnfv/functest/conf/config_functest.yaml
187 default_config_file=$(find /home/opnfv/repos -name config_functest.yaml)
188 if [ -f ${given_config_file} ]; then
189     info "Copying given config_functest.yaml to the repository directory"
190     cp ${given_config_file} ${default_config_file}
191 else
192     info "config_functest.yaml not provided. Using default one: ${default_config_file}"
193 fi
194
195
196 # Create directories
197 mkdir -p ${FUNCTEST_CONF_DIR}
198 mkdir -p ${FUNCTEST_DATA_DIR}
199 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
200
201
202
203 # Create Openstack credentials file
204 if [ ! -f ${FUNCTEST_CONF_DIR}/openstack.creds ]; then
205     ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${FUNCTEST_CONF_DIR}/openstack.creds \
206         -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
207     retval=$?
208     if [ $retval != 0 ]; then
209         error "Cannot retrieve credentials file from installation. Check logs."
210         exit $retval
211     fi
212 else
213     info "OpenStack credentials file given to the docker and stored in ${FUNCTEST_CONF_DIR}/openstack.creds."
214 fi
215 # Source credentials
216 source ${FUNCTEST_CONF_DIR}/openstack.creds
217
218 # Check OpenStack
219 info "Checking that the basic OpenStack services are functional..."
220 ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/check_os.sh
221 RETVAL=$?
222 if [ $RETVAL -ne 0 ]; then
223     exit 1
224 fi
225
226 # Prepare Functest Environment
227 info "Functest: prepare Functest environment"
228 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py --debug start
229 retval=$?
230 if [ $retval != 0 ]; then
231     error "Error when configuring Functest environment"
232     exit $retval
233 fi
234
235 echo "1" > ${FUNCTEST_CONF_DIR}/env_active