-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun
executable file
·289 lines (253 loc) · 7.84 KB
/
run
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
#!/bin/bash
# sourcing configuration file.
. conf
# Almost nothing happens here. Functionality is defined in ./functions.
CWD="$(pwd)"
echo "Adding functions."
for file in ./functions/*.sh
do
. "$file"
done
# Setting and recreating the work folder.
if [ ! -d "$WORK_DIR" ]
then
mkdir -p "$WORK_DIR"
fi
cd "$WORK_DIR" || exit 1
echo "Work dir: $(pwd)"
START=$(date +%s)
export LIBGUESTFS_BACKEND=direct
# This is where functions are executed.
LOG_FILE="${BASE_LOG_FILE}_$1.log"
run ()
{
echo "[$(date +%T)] Running $1 $2" | tee -a "$LOG_FILE"
SECONDS=0
$1
echo "$1 finished with no errors and ran for $(time_diff $SECONDS)" | \
tee -a "$LOG_FILE"
}
# Installation step names
STEP_NAME=(clean host uc-prep uc-inst uc-post oc-prep oc-depl oc-post)
LAST_STEP=${#STEP_NAME[@]}
# Special commands
SPECIAL=(tests once until bnr full func-ls)
STEP=$(echo ${STEP_NAME[@]} | tr " " "\n" | grep -n $1 2> /dev/null | cut -d ":" -f 1)
SPECIAL=$(echo ${SPECIAL[@]} | tr " " "\n" | grep -n $1 2> /dev/null | cut -d ":" -f 1)
# If step was not found in any of the arrays, print help and exit.
if [ -z "$STEP" ] && [ -z "$SPECIAL" ]
then
echo -ne "$HELP"
exit 1
fi
# Building STEP_RUN and setting it to false
declare INSTALLATION_STEP
for i in $(seq 1 $LAST_STEP)
do
INSTALLATION_STEP[$(( i - 1 ))]=false
done
# If its an installation step, enable only it.
if [ ! -z "$STEP" ]
then
INSTALLATION_STEP[$(( STEP - 1 ))]=true
fi
host_clean ()
{
run clean
run clean_vms
run clean_vnets
run clean_pool
run clean_vbmc
}
host_preprerations ()
{
# Editing the host prior to do anything else.
run install_host_packages "$LONG"
run install_extra_packages
run discover_puddle_version
run set_puddle_params
run update_os "$LONG"
run host_tweaks
run fix_host_ssh
run fix_virt_access
run fix_host_kvm
echo -e "Host prepared in $(time_diff $(( $(date +%s) - START)))\n"
}
virt_setup ()
{
# Re-creating virtual resources.
run restart_libvirt
run create_vnet
echo -e "Cleaned old resources in $(time_diff $(( $(date +%s) - START)))\n"
}
create_installation_images ()
{
# If no installation images are available, create them for the requested version.
if $CREATE_IMAGES
then
run get_ntpd_settings
run proto_create
run proto_prerun
run proto_firstrun
run proto_start "$LONG"
run proto_clean
run "clean_vms proto"
run package_puddle_image
run upload_puddle_image
echo -e "Created installation images in $(time_diff $(( $(date +%s) - START)))\n"
fi
}
create_virtual_environment ()
{
# Creating the virtual environment as set in conf.
run get_undercloud_image
run create_node_images
run define_nodes
run "fetch_vbmc ${NODES[0]}-0"
run vbmc_add
run "vbmc_stat down"
run vbmc_start
run "vbmc_stat running"
run "undercloud_firstboot ${NODES[0]}-0"
echo -e "Created virtual environment in $(time_diff $(( $(date +%s) - START)))\n"
}
prepare_main_undercloud ()
{
# Preparing the main Undercloud machine.
run "vm_power ${NODES[0]}-0 start" "$LONG"
run "undercloud_wait ${NODES[0]}-0" "$LONG"
run "undercloud_ssh_access ${NODES[0]}-0 root $ROOT_PASS"
run "undercloud_ssh_access ${NODES[0]}-0 stack stack"
run "pre_uc_install_wa ${NODES[0]}-0"
if [ $OS_VER -gt 11 ]
then
run "undercloud_container ${NODES[0]}-0"
fi
run "undercloud_gen_conf ${NODES[0]}-0"
echo -e "Undercloud preparations finished in $(time_diff $(( $(date +%s) - START)))\n"
}
install_main_undercloud ()
{
# Installing the main Undercloud machine.
run "undercloud_install ${NODES[0]}-0" "This should take 40-50 minutes."
echo -e "Undercloud installed in $(time_diff $(( $(date +%s) - START)))\n"
}
post_install_main_undercloud ()
{
# Installing the main Undercloud machine.
run "post_uc_install_wa ${NODES[0]}-0"
run "post_uc_install_tweaks ${NODES[0]}-0"
echo -e "Undercloud post installation tasks finished in $(time_diff $(( $(date +%s) - START)))\n"
}
predeploy_overcloud ()
{
# Running steps prior to deploying the Overcloud.
run "define_flavors ${NODES[0]}-0"
run "add_templates ${NODES[0]}-0"
run "prepare_director_images ${NODES[0]}-0" "$LONG"
run "create_json ${NODES[0]}-0"
run "overcloud_predeploy ${NODES[0]}-0" "$LONG"
echo -e "Finished deployment preperations in $(time_diff $(( $(date +%s) - START)))\n"
}
deploy_overcloud ()
{
# Running overcloud deploy and waiting for deployment to finish.
run "pre_oc_deploy_wa ${NODES[0]}-0"
run "overcloud_deploy ${NODES[0]}-0" "This takes about 60-80 minutes."
echo -e "Overcloud deployed in $(time_diff $(( $(date +%s) - START)))\n"
}
post_deploy_overcloud ()
{
# Running post deploy tasks.
run "post_oc_deploy_wa ${NODES[0]}-0"
run "populate_hosts ${NODES[0]}-0"
run "post_oc_deploy_int_net ${NODES[0]}-0"
run "post_oc_deploy_ext_net ${NODES[0]}-0"
run "post_oc_deploy_repos ${NODES[0]}-0"
echo -e "Overcloud post deploy tasks finished in $(time_diff $(( $(date +%s) - START)))\n"
}
undercloud_backup ()
{
# Backup the main Undercloud machine.
run "backup_undercloud ${NODES[0]}-0"
run "vm_power ${NODES[0]}-0 stop"
echo -e "Undercloud backed up in $(time_diff $(( $(date +%s) - START)))\n"
}
undercloud_restore ()
{
# Restoring the old Undercloud data onto a new Undercloud machine.
run "upload_backup ${NODES[0]}-1"
run "undercloud_firstboot ${NODES[0]}-1"
run "vm_power ${NODES[0]}-1 start" "$LONG"
run "undercloud_wait ${NODES[0]}-1" "$LONG"
run "undercloud_ssh_access ${NODES[0]}-1 root $ROOT_PASS"
run "undercloud_ssh_access ${NODES[0]}-1 stack stack"
run "restore_undercloud ${NODES[0]}-1"
run "undercloud_install ${NODES[0]}-1" "$LONG"
run "populate_hosts ${NODES[0]}-1"
echo -e "Undercloud restored in $(time_diff $(( $(date +%s) - START)))\n"
}
run_automation ()
{
# Run automation tests
run "run_tests $1 stack overcloud"
}
# Handeling non-installation-steps arguments.
if [ ! -z "$SPECIAL" ]
then
case $SPECIAL in
1) run_automation "${NODES[0]}-0" ;;
2)
if [ ! -z "$2" ]
then
run $2 $3 $4 $5
fi
;;
3)
if [ -z "$2" ]
then
echo -ne "$HELP"
exit 1
fi
STEP_2=$(echo ${STEP_NAME[@]} | tr " " "\n" | grep -n $2 2> /dev/null | cut -d ":" -f 1)
for i in $(seq 1 $STEP_2 )
do
INSTALLATION_STEP[$(( i - 1 ))]=true
done
;;
4)
undercloud_backup
undercloud_restore
;;
5)
for i in $(seq 1 $LAST_STEP)
do
INSTALLATION_STEP[$(( i - 1 ))]=true
done
;;
6) head -qn 1 $CWD/functions/*.sh ;;
esac
fi
# Step 0 - clean.
if ${INSTALLATION_STEP[0]}; then host_clean; fi
# Step 1 - host and puddle preparation.
if ${INSTALLATION_STEP[1]}
then
host_preprerations
virt_setup
create_installation_images
create_virtual_environment
fi
# Step 2 - preparing the undercloud machine.
if ${INSTALLATION_STEP[2]}; then prepare_main_undercloud; fi
# Step 3 - installing the undercloud.
if ${INSTALLATION_STEP[3]}; then install_main_undercloud; fi
# Step 4 - post installation tweaks.
if ${INSTALLATION_STEP[4]} ; then post_install_main_undercloud; fi
# Step 5 - predeploy tasks.
if ${INSTALLATION_STEP[5]}; then predeploy_overcloud; fi
# Step 6 - overcloud deploy.
if ${INSTALLATION_STEP[6]}; then deploy_overcloud; fi
# Step 7 - post deploy tweaks.
if ${INSTALLATION_STEP[7]}; then post_deploy_overcloud; fi
echo "ALL DONE in $(time_diff $(( $(date +%s) - START)))"