Refactor Functest docker container
[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 BASEDIR=`dirname $0`
11 source ${BASEDIR}/common.sh
12
13 # Support for Functest offline
14 # NOTE: Still not 100% working when running the tests
15 offline=false
16 if [ ! -z "$1" ] && [ $1 == "--offline" ]; then
17     offline=true
18 fi
19
20 info "######### Preparing Functest environment #########"
21 if [ $offline == false ]; then
22     info "MODE: online"
23 else
24     info "MODE: offline"
25 fi
26
27
28 # Check if environment variables are set
29 info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
30 if [ -z ${INSTALLER_TYPE} ]; then
31     error "Environment variable 'INSTALLER_TYPE' is not defined."
32 elif [ "${INSTALLER_TYPE}" != "fuel" ] && [ "${INSTALLER_TYPE}" != "foreman" ]; then
33     error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
34 fi
35 info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
36
37 if [ -z ${INSTALLER_IP} ]; then
38     error "Environment variable 'INSTALLER_IP' is not defined."
39 fi
40 info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
41
42
43 if [ $offline == false ]; then
44     # Update repos
45     info "Updating Functest repository...."
46     cd ${FUNCTEST_REPO_DIR}
47     if [ ${FUNCTEST_BRANCH} != "master" ]; then
48         info "Functest repo: checkout ${FUNCTEST_BRANCH} branch..."
49         git checkout ${FUNCTEST_BRANCH}
50     fi
51     info "Functest repo: pulling to latest..."
52     git pull
53     if [ ${FUNCTEST_COMMIT} != "latest" ]; then
54         info "Functest repo: given commit is ${FUNCTEST_COMMIT}. Reseting..."
55         git reset --hard ${FUNCTEST_COMMIT}
56     fi
57
58     info "Updating Releng repository...."
59     cd ${RELENG_REPO_DIR}
60     if [ ${RELENG_BRANCH} != "master" ]; then
61         info "Releng repo: checkout ${RELENG_BRANCH} branch..."
62         git checkout ${RELENG_BRANCH}
63     fi
64     info "Releng repo: pulling to latest..."
65     git pull
66     if [ ${RELENG_COMMIT} != "latest" ]; then
67         info "Releng repo: given commit is ${RELENG_COMMIT}. Reseting..."
68         git reset --hard ${RELENG_COMMIT}
69     fi
70
71     info "Updating Rally repository...."
72     cd ${RALLY_REPO_DIR}
73     info "Rally repo: pulling to latest..."
74     git pull
75 fi
76
77 # We do this regardless if its online or offline mode.
78 if [ ${RALLY_COMMIT} != "latest" ]; then
79     info "Rally repo: given commit is ${RALLY_COMMIT}. Reseting..."
80     git reset --hard ${RALLY_COMMIT}
81 fi
82
83
84 # Create directories
85 mkdir -p ${FUNCTEST_CONF_DIR}
86 mkdir -p ${FUNCTEST_DATA_DIR}
87 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
88
89 # Detect type of installer
90 # NOTE: this is tricky, since the IPs will have to be the same ALWAYS
91
92
93 # Create Openstack credentials file
94 ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${FUNCTEST_CONF_DIR}/openstack.creds \
95     -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
96 retval=$?
97 if [ $retval != 0 ]; then
98     echo "Cannot retrieve credentials file from installation. Check logs."
99     exit $retval
100 fi
101
102
103 # Source credentials
104 source ${FUNCTEST_CONF_DIR}/openstack.creds
105
106
107 # Prepare Functest Environment
108 echo "Functest: prepare Functest environment"
109 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py --debug ${FUNCTEST_REPO_DIR}/ start
110 retval=$?
111 if [ $retval != 0 ]; then
112     echo "Error when configuring Functest environment"
113     exit $retval
114 fi
115
116 echo "1" > ${FUNCTEST_CONF_DIR}/env_active