forked from cmyster/coti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·220 lines (196 loc) · 5.71 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
#!/bin/bash
# conf file is where everything else is defined.
source conf
# Gathiring run time arguments.
SYS_CLEAN=false
SYS_PREP=false
UC_INSTALL=false
OC_PREP=false
OC_DEPLOY=false
RUN_TESTS=false
BCK_RES=false
case "$1" in
-h)
echo -ne $HELP && exit 0 ;;
--help)
echo -ne $HELP && exit 0 ;;
--clean)
SYS_CLEAN=true ;;
--sp)
SYS_PREP=true ;;
--uc)
UC_INSTALL=true ;;
--op)
OC_PREP=true ;;
--oc)
OC_DEPLOY=true ;;
--test)
RUN_TESTS=true ;;
--bnr)
BCK_RES=true ;;
--full)
SYS_CLEAN=true
SYS_PREP=true
UC_INSTALL=true
OC_PREP=true
OC_DEPLOY=true
RUN_TESTS=true
BCK_RES=true
;;
*)
echo -ne $HELP && exit 0 ;;
esac
# Almost nothing happens here, all the functions are defined elsewhere.
for file in $(ls functions/*.sh)
do
echo "Adding function: $(head -n 1 $file | cut -d " " -f 1)"
source $file
done
# Setting current location and recreating the work folder.
CWD=$(pwd)
if [ ! -d $WORK_DIR ]
then
mkdir -p $WORK_DIR
fi
cd $WORK_DIR
echo "Work dir: $(pwd)"
START=$(date +%s)
# This is where functions are executed.
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
}
host_clean ()
{
run clean
run clean_vms
run clean_vnets
run clean_pool
}
host_preprerations ()
{
# Editing the host prior to do anything else.
run install_host_packages "$LONG"
run install_extra_packages
run "discover_puddle_version $OS_VER"
run set_puddle_params
run update_os "$LONG"
run host_tweaks
run fix_host_ssh
run fix_virt_access
run fix_host_kvm
run add_user_stack
echo -e "Prepared host after $(time_diff $(( $(date +%s) - $START)))\n"
}
virt_setup ()
{
# Re-creating virtual resources.
run restart_libvirt
#run clean_vms
#run clean_pool
#run clean_vnets
#run restart_libvirt
run create_vnet
echo -e "Cleaned old resources after $(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 $OBTAIN_IMAGES "$LONG"
run package_puddle_images
run upload_puddle
echo -e "Created installation images after $(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 "undercloud_firstboot ${NODES[0]}-0"
echo -e "Creates virtual environment after $(time_diff $(( $(date +%s) - $START)))\n"
}
install_main_undercloud ()
{
# Installing 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 "undercloud_install ${NODES[0]}-0" "$LONG"
echo -e "Undercloud installed after $(time_diff $(( $(date +%s) - $START)))\n"
}
predeploy_overcloud ()
{
# Running steps prior to deploying the Overcloud.
run "define_flavors ${NODES[0]}-0"
run "create_json ${NODES[0]}-0"
run "add_templates ${NODES[0]}-0"
run "overcloud_predeploy ${NODES[0]}-0" "$LONG"
echo -e "Finished deployment preperations after $(time_diff $(( $(date +%s) - $START)))\n"
}
deploy_overcloud ()
{
# Running overcloud deploy and waiting for deployment to finish.
run "overcloud_deploy ${NODES[0]}-0"
run "overcloud_wait ${NODES[0]}-0" "$LONG"
run "populate_hosts ${NODES[0]}-0"
echo -e "Overcloud deployed after $(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 after $(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 after $(time_diff $(( $(date +%s) - $START)))\n"
}
run_automation ()
{
# Run automation tests
run "run_tests $1 stack overcloud"
}
if $SYS_CLEAN; then host_clean; fi
if $SYS_PREP
then
host_preprerations
virt_setup
create_installation_images
create_virtual_environment
fi
if $UC_INSTALL; then install_main_undercloud; fi
if $OC_PREP; then predeploy_overcloud; fi
if $OC_DEPLOY; then deploy_overcloud; fi
if $BCK_RES
then
undercloud_backup
undercloud_restore
fi
if $RUN_TESTS; then run_automation ${NODES[0]}-0; fi
echo "ALL DONE in $(time_diff $(( $(date +%s) - $START)))"