454ba4e3b760a3b7ab4fa705f19afcea8fe93ba3
[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
60 # Check if environment variables are set
61 info "Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
62 if [ -z ${INSTALLER_TYPE} ]; then
63     error "Environment variable 'INSTALLER_TYPE' is not defined."
64 elif [ "${INSTALLER_TYPE}" != "fuel" ] && [ "${INSTALLER_TYPE}" != "foreman" ]; then
65     error "Invalid environment variable INSTALLER_TYPE=${INSTALLER_TYPE}"
66 fi
67 info "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
68
69 if [ -z ${INSTALLER_IP} ]; then
70     error "Environment variable 'INSTALLER_IP' is not defined."
71 fi
72 info "INSTALLER_IP env variable found: ${INSTALLER_IP}"
73
74
75 if [ $offline == false ]; then
76     # Update repos
77     info "Updating Functest repository...."
78     cd ${FUNCTEST_REPO_DIR}
79     if [ ${FUNCTEST_BRANCH} != "master" ]; then
80         info "Functest repo: checkout ${FUNCTEST_BRANCH} branch..."
81         git checkout ${FUNCTEST_BRANCH}
82     fi
83     info "Functest repo: pulling to latest..."
84     git pull
85     if [ ${FUNCTEST_COMMIT} != "latest" ]; then
86         info "Functest repo: given commit is ${FUNCTEST_COMMIT}. Reseting..."
87         git reset --hard ${FUNCTEST_COMMIT}
88     fi
89
90     info "Updating Releng repository...."
91     cd ${RELENG_REPO_DIR}
92     if [ ${RELENG_BRANCH} != "master" ]; then
93         info "Releng repo: checkout ${RELENG_BRANCH} branch..."
94         git checkout ${RELENG_BRANCH}
95     fi
96     info "Releng repo: pulling to latest..."
97     git pull
98     if [ ${RELENG_COMMIT} != "latest" ]; then
99         info "Releng repo: given commit is ${RELENG_COMMIT}. Reseting..."
100         git reset --hard ${RELENG_COMMIT}
101     fi
102
103     info "Updating Rally repository...."
104     cd ${RALLY_REPO_DIR}
105     if [ ${RALLY_BRANCH} != "master" ]; then
106         info "Rally repo: checkout ${RALLY_BRANCH} branch..."
107         git checkout ${RALLY_BRANCH}
108     fi
109     info "Rally repo: pulling to latest..."
110     git pull
111     # We leave the reset command for later.
112
113     info "Updating vIMS test repository...."
114     cd ${VIMS_REPO_DIR}
115     if [ ${VIMS_BRANCH} != "stable" ]; then
116         info "Releng repo: checkout ${VIMS_TEST_BRANCH} branch..."
117         git checkout ${VIMS_BRANCH}
118     fi
119     info "vIMS test repo: pulling to latest..."
120     git pull
121     if [ ${VIMS_COMMIT} != "latest" ]; then
122         info "vIMS test repo: given commit is ${VIMS_TEST_COMMIT}. Reseting..."
123         git reset --hard ${VIMS_COMMIT}
124     fi
125
126 fi
127
128 # We do this regardless if its online or offline mode.
129 # Assumption: the docker image contains a newer rally repo than the given commit.
130 if [ ${RALLY_COMMIT} != "latest" ]; then
131     cd ${RALLY_REPO_DIR}
132     info "Rally repo: given commit is ${RALLY_COMMIT}. Reseting..."
133     git reset --hard ${RALLY_COMMIT}
134 fi
135
136
137 # Create directories
138 mkdir -p ${FUNCTEST_CONF_DIR}
139 mkdir -p ${FUNCTEST_DATA_DIR}
140 mkdir -p ${FUNCTEST_RESULTS_DIR}/ODL
141
142
143
144 # Create Openstack credentials file
145 ${REPOS_DIR}/releng/utils/fetch_os_creds.sh -d ${FUNCTEST_CONF_DIR}/openstack.creds \
146     -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}
147 retval=$?
148 if [ $retval != 0 ]; then
149     error "Cannot retrieve credentials file from installation. Check logs."
150     exit $retval
151 fi
152
153
154 # Source credentials
155 source ${FUNCTEST_CONF_DIR}/openstack.creds
156
157
158 # Prepare Functest Environment
159 info "Functest: prepare Functest environment"
160 python ${FUNCTEST_REPO_DIR}/testcases/config_functest.py --debug ${FUNCTEST_REPO_DIR}/ start
161 retval=$?
162 if [ $retval != 0 ]; then
163     error "Error when configuring Functest environment"
164     exit $retval
165 fi
166
167 echo "1" > ${FUNCTEST_CONF_DIR}/env_active