-
Notifications
You must be signed in to change notification settings - Fork 0
/
murano-devbox-devstack.sh
307 lines (230 loc) · 8.1 KB
/
murano-devbox-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
#!/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 {
cat << EOF
********************************************************************************
*
* Got error in "'$3'", line "'$2'", error code "'$1'"
*
********************************************************************************
EOF
}
function exit_handler {
mkdir -p $WORKSPACE/artifacts
echo $BUILD_STATUS_ON_EXIT > $WORKSPACE/artifacts/build_status
cat << EOF
********************************************************************************
*
* Exiting script, exit code "'$1'"
* Build status: $BUILD_STATUS_ON_EXIT
*
********************************************************************************
EOF
set +o xtrace
while [ -f ~/keep-vm-alive ]; do
sleep 5
done
}
trap 'trap_handler ${?} ${LINENO} ${0}' ERR
trap 'exit_handler ${?}' EXIT
#---------------------
# Enable debug output
#--------------------
PS4='+ [$(date --rfc-3339=seconds)] '
set -o xtrace
#--------------------
CI_ROOT_DIR=$(cd $(dirname "$0") && cd .. && pwd)
# This file is generated by Nodepool while building snapshots
# It contains credentials to access RabbitMQ and an OpenStack lab
# This file might be absent if script is not launched by Jenkins
if [ -f ~/credentials ]; then
source ~/credentials
fi
# Defaults
#---------
WORKSPACE=${WORKSPACE:-.}
OPENSTACK_HOST=${OPENSTACK_HOST:-$KEYSTONE_URL}
HYPERVIZOR_HOST=${HYPERVIZOR_HOST:-$OPENSTACK_HOST}
ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
ADMIN_TENANT=${ADMIN_TENANT:-admin}
ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
#---------
# Basic parameters
#-----------------
STACK_HOME='/opt/stack'
GIT_BASE=${GIT_BASE:-https://git.openstack.org}
MURANO_REPO=${MURANO_REPO:-${GIT_BASE}/stackforge/murano}
MURANO_BRANCH=${MURANO_BRANCH:-master}
MURANO_DASHBOARD_REPO=${MURANO_DASHBOARD_REPO:-${GIT_BASE}/stackforge/murano-dashboard}
MURANO_DASHBOARD_BRANCH=${MURANO_DASHBOARD_BRANCH:-master}
MURANO_PYTHONCLIENT_REPO=${MURANO_PYTHONCLIENT_REPO:-${GIT_BASE}/stackforge/python-muranoclient}
MURANO_PYTHONCLIENT_BRANCH=${MURANO_PYTHONCLIENT_BRANCH:-master}
MURANO_APP_INCUBATOR_REPO=${MURANO_APP_INCUBATOR_REPO:-https://github.com/murano-project/murano-app-incubator}
MURANO_APP_INCUBATOR_BRANCH=${MURANO_APP_INCUBATOR_BRANCH:-master}
WORKSPACE=$(cd ${WORKSPACE} && pwd)
TZ_STRING='Europe/Moscow'
#-----------------
# 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 import_murano_apps {
pushd "${WORKSPACE}"
git clone ${MURANO_APP_INCUBATOR_REPO} "${WORKSPACE}/murano-app-incubator"
cd "./murano-app-incubator"
git fetch ${MURANO_APP_INCUBATOR_REPO} ${MURANO_APP_INCUBATOR_BRANCH} && git checkout FETCH_HEAD
set +o xtrace
export OS_USERNAME=${ADMIN_USERNAME}
export OS_PASSWORD=${ADMIN_PASSWORD}
export OS_TENANT_NAME=${ADMIN_TENANT}
export OS_AUTH_URL="http://${OPENSTACK_HOST}:5000/v2.0"
set -o xtrace
sudo rm -f /tmp/parser_table.py
local app
for app in io.murano.*; do
if [ -f "${app}/manifest.yaml" ]; then
murano-manage --config-file /etc/murano/murano.conf import-package ${app}
fi
done
popd
}
function make_murano_package {
local path=$1
if [[ -z "${path}" ]]; then
echo "No directory name provided."
return 1
fi
if [[ ! -d "${path}" ]]; then
echo "Folder '${path}' doesn't exist."
return 1
fi
path=${path%/*}
pushd ${path}
zip -r "../${path}.zip" *
popd
}
function enable_sudo {
local user_name=$(whoami)
echo "${user_name} ALL=(ALL) NOPASSWD:ALL" > ${user_name}.sudoers
chmod 440 ${user_name}.sudoers
sudo mv ${user_name}.sudoers /etc/sudoers.d/${user_name}
}
function git_clone_devstack {
# Assuming the script is run from 'jenkins' user
local user_name=$(whoami)
sudo mkdir -p "${STACK_HOME}"
sudo chown -R ${user_name}:${user_name} "${STACK_HOME}"
git clone https://github.com/openstack-dev/devstack ${STACK_HOME}/devstack
#source ${STACK_HOME}/devstack/functions-common
}
function deploy_devstack {
# Assuming the script is run from 'jenkins' user
local git_dir=/opt/git
cd "${STACK_HOME}"
git clone ${MURANO_REPO}
cd "${STACK_HOME}/murano"
git fetch ${MURANO_REPO} ${MURANO_BRANCH} && git checkout FETCH_HEAD
# NOTE: Source path MUST ends with a slash!
rsync --recursive --exclude README.* "./contrib/devstack/" "${STACK_HOME}/devstack/"
git checkout master
cd "${STACK_HOME}/devstack"
cat << EOF > local.conf
[[local|localrc]]
HOST_IP=${OPENSTACK_HOST} # IP address of OpenStack lab
ADMIN_PASSWORD=${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=${floating_ip_address}
RABBIT_PASSWORD=guest
MURANO_RABBIT_VHOST=/
MURANO_REPO=${MURANO_REPO}
MURANO_BRANCH=${MURANO_BRANCH}
MURANO_DASHBOARD_REPO=${MURANO_DASHBOARD_REPO}
MURANO_DASHBOARD_BRANCH=${MURANO_DASHBOARD_BRANCH}
MURANO_PYTHONCLIENT_REPO=${MURANO_PYTHONCLIENT_REPO}
MURANO_PYTHONCLIENT_BRANCH=${MURANO_PYTHONCLIENT_BRANCH}
RECLONE=True
SCREEN_LOGDIR=/opt/stack/log/
LOGFILE=\$SCREEN_LOGDIR/stack.sh.log
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
echo 'stack:swordfish' | sudo chpasswd
sudo chown -R stack:stack "${STACK_HOME}"
sudo sed -i 's/^PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo service ssh restart
sudo su -c "cd ${STACK_HOME}/devstack && ./stack.sh" stack
# Fix iptables to allow outbound access
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
}
function adjust_time_settings {
sudo sh -c "echo \"${TZ_STRING}\" > /etc/timezone"
sudo dpkg-reconfigure -f noninteractive tzdata
sudo ntpdate -u ru.pool.ntp.org
}
#-------------------------------------------------------------------------------
BUILD_STATUS_ON_EXIT='PREPARATION_FAILED'
enable_sudo
sudo sh -c "echo '127.0.0.1 $(hostname)' >> /etc/hosts"
sudo iptables -F
adjust_time_settings
# Clone devstack first as we will use
# some of its files (functions-common, for example)
git_clone_devstack
get_ip_from_iface eth0
cat << EOF
********************************************************************************
*
* Fixed IP: ${found_ip_address}
* Floating IP: ${floating_ip_address}
* Horizon URL: http://${floating_ip_address}
* SSH connection string: ssh stack@${floating_ip_address} -oPubkeyAuthentication=no
*
********************************************************************************
EOF
BUILD_STATUS_ON_EXIT='DEVSTACK_FAILED'
deploy_devstack
BUILD_STATUS_ON_EXIT='MURANO_APPS_FAILED'
import_murano_apps
BUILD_STATUS_ON_EXIT='SUCCESS'
exit 0