-
Notifications
You must be signed in to change notification settings - Fork 0
/
murano-devstack.sh
331 lines (242 loc) · 8.57 KB
/
murano-devstack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
# Copyright (c) 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Error trapping first
#---------------------
set -o errexit
function trap_handler() {
echo "Got error in '$1' on line '$2', error code '$3'"
}
trap 'trap_handler ${0} ${LINENO} ${?}' ERR
#---------------------
CI_ROOT_DIR=$(cd $(dirname "$0") && cd .. && pwd)
# Include of the common functions library file
source "${CI_ROOT_DIR}/scripts/common.inc"
# This file is generated by Nodepool while building snapshots
# It contains credentials to access RabbitMQ and an OpenStack lab
source ~/credentials
# Basic parameters
#-----------------
STACK_HOME='/opt/stack'
PROJECT_DIR="${STACK_HOME}/murano-dashboard"
TESTS_DIR="muranodashboard/tests/functional"
ZUUL_URL=${ZUUL_URL:-'https://github.com'}
ZUUL_REF=${ZUUL_REF:-'master'}
WORKSPACE=$(cd $WORKSPACE && pwd)
#-----------------
# Commands used in script
#------------------------
PYTHON_CMD=$(which python)
NOSETESTS_CMD=$(which nosetests)
GIT_CMD=$(which git)
NTPDATE_CMD=$(which ntpdate)
PIP_CMD=$(which pip)
SCREEN_CMD=$(which screen)
FW_CMD=$(which iptables)
#------------------------
# Virtual framebuffer settings
#-----------------------------
VFB_DISPLAY_SIZE='1280x1024'
VFB_COLOR_DEPTH=16
VFB_DISPLAY_NUM=22
#-----------------------------
# Functions
#-------------------------------------------------------------------------------
function get_ip_from_iface() {
local iface_name=$1
found_ip_address=$(ifconfig $iface_name | awk -F ' *|:' '/inet addr/{print $4}')
if [ $? -ne 0 ] || [ -z "$found_ip_address" ]; then
echo "Can't obtain ip address from interface $iface_name!"
return 1
else
readonly found_ip_address
fi
}
function prepare_murano_apps() {
local start_dir=$1
local clone_dir="${start_dir}/murano-app-incubator"
local git_url="https://github.com/murano-project/murano-app-incubator"
cd ${start_dir}
$GIT_CMD clone $git_url $clone_dir
if [ $? -ne 0 ]; then
echo "Error occured during git clone $git_url $clone_dir!"
return 1
fi
cd ${clone_dir}
local pkg_counter=0
for package_dir in io.murano.*
do
if [ -f "${package_dir}/manifest.yaml" ]; then
bash make-package.sh $package_dir
pkg_counter=$((pkg_counter + 1))
fi
done
cd ${start_dir}
bash murano-app-incubator/make-package.sh MockApp
if [ $pkg_counter -eq 0 ]; then
echo "Warning: $pkg_counter packages was built at $clone_dir!"
return 1
fi
}
function prepare_tests() {
local retval=0
local tests_dir="${PROJECT_DIR}/${TESTS_DIR}"
if [ ! -d "$tests_dir" ]; then
echo "Directory with tests isn't exist"
return 1
fi
sudo chown -R $USER ${tests_dir}
local tests_config=${tests_dir}/config/config_file.conf
iniset 'common' 'keystone_url' "$(shield_slashes http://${KEYSTONE_URL}:5000/v2.0/)" "$tests_config"
iniset 'common' 'horizon_url' "$(shield_slashes http://${found_ip_address}/)" "$tests_config"
iniset 'common' 'murano_url' "$(shield_slashes http://${found_ip_address}:8082)" "$tests_config"
iniset 'common' 'user' "$ADMIN_USERNAME" "$tests_config"
iniset 'common' 'password' "$ADMIN_PASSWORD" "$tests_config"
iniset 'common' 'tenant' "$ADMIN_TENANT" "$tests_config"
prepare_murano_apps ${tests_dir} || retval=$?
mkdir -p /tmp/murano-artifacts
chmod -R 777 /tmp/murano-artifacts
return $retval
}
function run_tests() {
local retval=0
local tests_dir="${PROJECT_DIR}/${TESTS_DIR}"
# TODO(dteselkin): Remove this workaround as soon as
# https://bugs.launchpad.net/murano/+bug/1349934 is fixed.
sudo rm -f /tmp/parser_table.py
pushd ${tests_dir}
$NOSETESTS_CMD sanity_check -sv || retval=$?
collect_artifacts
popd
return $retval
}
function collect_artifacts() {
local dst=${WORKSPACE}/artifacts
sudo mkdir -p ${dst}
### Add correct Apache log path
if [ $distro_based_on == "redhat" ]; then
apache_log_dir="/var/log/httpd/"
else
apache_log_dir="/var/log/apache2/"
fi
# rsync might fail if there is no file or folder,
# so I disable error catching
set +o errexit
sudo rsync -rLv /tmp/murano-artifacts/ ${dst}
sudo rsync -rLv ${PROJECT_DIR}/${TESTS_DIR}/screenshots/ ${dst}
sudo rsync -rLv --include='murano*.log' --exclude='*' /tmp/ ${dst}
sudo rsync -rLv --include='*.log' --exclude='*' ${STACK_HOME}/log/ ${dst}
sudo rsync -rLv --include='*.log' --exclude='*' ${apache_log_dir} ${dst}
# return error catching back
set -o errexit
sudo chown -R jenkins:jenkins ${dst}
}
function git_clone_devstack() {
# Assuming the script is run from 'jenkins' user
local git_dir=/opt/git
sudo mkdir -p "$git_dir/openstack-dev"
sudo chown -R jenkins:jenkins "$git_dir/openstack-dev"
cd "$git_dir/openstack-dev"
git clone https://github.com/openstack-dev/devstack
#source ./devstack/functions-common
}
function deploy_devstack() {
# Assuming the script is run from 'jenkins' user
local git_dir=/opt/git
sudo mkdir -p "$git_dir/stackforge"
sudo chown -R jenkins:jenkins "$git_dir/stackforge"
cd "$git_dir/stackforge"
git clone https://github.com/stackforge/murano-api
# NOTE: Source path MUST ends with a slash!
rsync --recursive --exclude README.* "$git_dir/stackforge/murano-api/contrib/devstack/" "$git_dir/openstack-dev/devstack/"
cd "$git_dir/openstack-dev/devstack"
cat << EOF > local.conf
[[local|localrc]]
HOST_IP=${KEYSTONE_URL} # IP address of OpenStack lab
ADMIN_PASSWORD=. # This value doesn't matter
MYSQL_PASSWORD=swordfish # Random password for MySQL installation
SERVICE_PASSWORD=${ADMIN_PASSWORD} # Password of service user
SERVICE_TOKEN=. # This value doesn't matter
SERVICE_TENANT_NAME=${ADMIN_TENANT}
MURANO_ADMIN_USER=${ADMIN_USERNAME}
RABBIT_HOST=localhost
RABBIT_PASSWORD=guest
MURANO_RABBIT_VHOST=/
RECLONE=True
SCREEN_LOGDIR=/opt/stack/log/
LOGFILE=\$SCREEN_LOGDIR/stack.sh.log
MURANO_DASHBOARD_REPO=${ZUUL_URL}/stackforge/murano-dashboard
MURANO_DASHBOARD_BRANCH=${ZUUL_REF}
ENABLED_SERVICES=
enable_service mysql
enable_service rabbit
enable_service horizon
enable_service murano
enable_service murano-api
enable_service murano-engine
enable_service murano-dashboard
EOF
sudo ./tools/create-stack-user.sh
sudo chown -R stack:stack "$git_dir/openstack-dev/devstack"
sudo su -c "cd $git_dir/openstack-dev/devstack && ./stack.sh" stack
# Fix iptables to allow outbound access
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
}
function configure_apt_cacher() {
local mode=$1
local apt_proxy_host=${2:-'172.18.124.201'}
local apt_proxy_file=/etc/apt/apt.conf.d/01proxy
case $mode in
enable)
sudo sh -c "echo 'Acquire::http { Proxy \"http://${apt_proxy_host}:3142\"; };' > ${apt_proxy_file}"
sudo apt-get update
;;
disable)
sudo rm -f $apt_proxy_file
sudo apt-get update
;;
esac
}
function start_xvfb_session() {
export DISPLAY=:${VFB_DISPLAY_NUM}
fonts_path="/usr/share/fonts/X11/misc/"
if [ $distro_based_on == "redhat" ]; then
fonts_path="/usr/share/X11/fonts/misc/"
fi
# Start XVFB session
sudo Xvfb -fp ${fonts_path} ${DISPLAY} -screen 0 ${VFB_DISPLAY_SIZE}x${VFB_COLOR_DEPTH} &
# Start VNC server
sudo apt-get install --yes x11vnc
x11vnc -nopw -display ${DISPLAY} &
sudo iptables -I INPUT 1 -p tcp --dport 5900 -j ACCEPT
# Launch window manager
sudo apt-get install --yes openbox
exec openbox &
}
#-------------------------------------------------------------------------------
sudo sh -c "echo '127.0.0.1 $(hostname)' >> /etc/hosts"
sudo $NTPDATE_CMD -u ru.pool.ntp.org
sudo $FW_CMD -F
# Clone devstack first as we will use
# some of its files (functions-common, for example)
git_clone_devstack
get_os
get_ip_from_iface eth0
configure_apt_cacher enable
deploy_devstack
start_xvfb_session
prepare_tests
run_tests
exit 0