This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
chef_vpc_runner.sh.erb
260 lines (207 loc) · 7.52 KB
/
chef_vpc_runner.sh.erb
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
#Global Chef settings
export CHEF_TIMEOUT=900
export CHEF_RESTART_ON_FAILURE="true"
TMP_DIR=$(mktemp -d)
<% job.job_group.smoke_test.test_suites.each do |suite| %>
RUN_<%= suite.name %>=true
<% end %>
function copy_hosts {
# Copy hosts file to each node
rake ssh bash <<-"EOF_COPY_HOSTS"
for IP in $(cat /etc/hosts | cut -f 1); do
[[ "$IP" != "127.0.0.1" ]] && scp /etc/hosts $IP:/etc/hosts
done
EOF_COPY_HOSTS
}
function delete_group {
XEN_DISCONNECT=$1
#for debugging purposes you can touch this file to hang the group
rake ssh bash <<-EOF_BASH
until [ ! -f /tmp/do_not_delete ]; do
sleep 1
done
EOF_BASH
[ -n "$XEN_DISCONNECT" ] && rake xen:disconnect
rake group:delete
}
function setup {
chef-vpc-toolkit -v || \
fail "Please install the Chef VPC Toolkit."
cd $TMP_DIR
if [ -n "$NOVA_URL" ]; then
get_nova_source_git
fi
if [ -n "$KEYSTONE_URL" ]; then
get_keystone_source_git
fi
if [ -n "$GLANCE_URL" ]; then
get_glance_source_git
fi
GIT_ASKPASS=echo \
git clone <%= ENV['OPENSTACK_VPC_URL'] %> openstack_vpc && \
cd openstack_vpc || \
fail "Failed to checkout openstack VPC."
cat > config/chef_installer.yml <<-EOF_CAT
chef_cookbook_repos: $COOKBOOK_URL
# The Chef JSON configuration contains attributes and recipes for nodes.
chef_json_file: config/nodes.json
#databags_json_file: config/databags.json
# Chef server name
chef_server_name: login
EOF_CAT
cp "$SERVER_GROUP_JSON_CONF" config/server_group.json || \
fail "Failed to copy server_group.json"
rake chef:validate_json || fail "Invalid JSON config file(s).";
}
function run_job {
trap "{ delete_group; cd /tmp; rm -Rf $TMP_DIR; }" INT TERM EXIT
if rake group:create && rake group:poll; then
rake nova:build_packages SOURCE_DIR="$TMP_DIR/nova_source" \
DEB_PACKAGER_URL="$NOVA_DEB_PACKAGER_URL" || \
#RPM_PACKAGER_URL="$NOVA_RPM_PACKAGER_URL" || \
fail "Failed to build nova packages."
rake glance:build_packages SOURCE_DIR="$TMP_DIR/glance_source" \
DEB_PACKAGER_URL="$GLANCE_DEB_PACKAGER_URL" || \
#RPM_PACKAGER_URL="$GLANCE_RPM_PACKAGER_URL" || \
fail "Failed to build glance packages."
#rake keystone:build_packages SOURCE_DIR="$TMP_DIR/keystone_source" \
#DEB_PACKAGER_URL="$KEYSTONE_DEB_PACKAGER_URL" || \
#RPM_PACKAGER_URL="$KEYSTONE_RPM_PACKAGER_URL" || \
#fail "Failed to build keystone packages."
# install Chef and the Chef Cookbooks
copy_hosts
rake chef:push_repos && rake chef:install || \
{ rake tail_logs; fail "Failed to install Chef server."; }
rake chef_test || fail "Chef Client/Server setup is invalid!"
# poll for Chef clients to finish runnings
rake chef:poll_clients || \
{ rake tail_logs; fail "Chef client timeout."; }
# run Torpedo API tests (Uses the Ruby openstack-compute gem)
if [ -n "$RUN_TORPEDO" ]; then
rake torpedo SERVER_NAME=nova1 || \
{ rake tail_logs; fail "Hit by Torpedo."; }
fi
# run OS API v1.0 tests (Uses the Ruby openstack-compute gem)
if [ -n "$RUN_RUBY_OSAPI_V10" ]; then
rake nova:ruby_osapi_tests SERVER_NAME=nova1 || \
{ rake tail_logs; fail "OS API tests failed."; }
fi
# run OS API v1.1 tests (Uses the Ruby openstack-compute gem)
if [ -n "$RUN_RUBY_OSAPI_V11" ]; then
rake nova:ruby_osapi_v11_tests SERVER_NAME=nova1 || \
{ rake tail_logs; fail "OS API tests failed."; }
fi
# run smoke tests
if [ -n "$RUN_NOVA_SMOKE_TESTS" ]; then
rake nova:smoke_tests SERVER_NAME=nova1 || \
{ rake tail_logs; fail "Smoke tests failed."; }
fi
# run stacktester
if [ -n "$RUN_STACK_TESTER" ]; then
rake nova:stacktester SERVER_NAME=nova1 || \
{ rake tail_logs; fail "Stacktester failed."; }
fi
else
rake tail_logs
fail "Failed to create server group."
fi
}
function run_xen_hybrid_job {
[ -n "$SERVER_IP_LIST" ] || fail "Xen jobs require a SERVER_IP_LIST env variable."
trap "{ delete_group 'xen_discon'; cd /tmp; rm -Rf $TMP_DIR; }" INT TERM EXIT
if rake group:create && rake group:poll; then
rake nova:build_packages SOURCE_DIR="$TMP_DIR/nova_source" \
DEB_PACKAGER_URL="$NOVA_DEB_PACKAGER_URL" || \
#RPM_PACKAGER_URL="$NOVA_RPM_PACKAGER_URL" || \
fail "Failed to build nova packages."
rake nova:build_rpms SOURCE_DIR="$TMP_DIR/nova_source" || \
fail "Failed to build Xen plugin RPMs."
rake glance:build_packages SOURCE_DIR="$TMP_DIR/glance_source" \
DEB_PACKAGER_URL="$GLANCE_DEB_PACKAGER_URL" || \
#RPM_PACKAGER_URL="$GLANCE_RPM_PACKAGER_URL" || \
fail "Failed to build glance packages."
#rake keystone:build_packages SOURCE_DIR="$TMP_DIR/keystone_source" \
#DEB_PACKAGER_URL="$KEYSTONE_DEB_PACKAGER_URL" || \
#RPM_PACKAGER_URL="$KEYSTONE_RPM_PACKAGER_URL" || \
#fail "Failed to build keystone packages."
# install Chef and the Chef Cookbooks
copy_hosts
rake chef:push_repos && rake chef:install || \
{ rake tail_logs; fail "Failed to install Chef server."; }
rake chef_test || fail "Chef Client/Server setup is invalid!"
# Bootstrap all the Xen Servers
local COUNT=0
for SERVER_IP in $SERVER_IP_LIST; do
COUNT=$(($COUNT + 1))
local SERVER_NAME="xen$COUNT"
rake xen:bootstrap XENSERVER_IP=$SERVER_IP SERVER_NAME=$SERVER_NAME || \
fail "Failed to connect Xen Server: $SERVER_NAME to VPN group."
sleep 10
copy_hosts
rake chef:install SERVER_NAME=$SERVER_NAME || \
fail "Failed to install Chef on $SERVER_NAME."
done
#FIXME: this can come out when compute1.vpc gets a proper domain name
# Ideally we could just use rake:poll_clients (to poll them all)
rake chef:poll_clients SERVER_NAME=nova1 || \
{ rake tail_logs SERVER_NAME=nova1; fail "Chef client timeout: nova1"; }
rake chef:poll_clients SERVER_NAME=glance1 || \
{ rake tail_logs SERVER_NAME=glance1; fail "Chef client timeout: glance1"; }
# Poll Xen Servers to finish Chef'ing
COUNT=0
for SERVER_IP in $SERVER_IP_LIST; do
COUNT=$(($COUNT + 1))
local SERVER_NAME="xen$COUNT"
local COMPUTE_NAME="compute$COUNT"
rake chef:poll_clients SERVER_NAME=$SERVER_NAME || \
{ rake tail_logs SERVER_NAME=$SERVER_NAME; fail "Chef client timeout: $SERVER_NAME"; }
rake ssh bash <<-EOF_BASH
if ! grep -c "$COMPUTE_NAME.vpc" /etc/hosts &> /dev/null; then
echo "172.19.0.10$COUNT $COMPUTE_NAME.vpc $COMPUTE_NAME" >> /etc/hosts
fi
EOF_BASH
copy_hosts
rake chef:install SERVER_NAME=$COMPUTE_NAME || \
fail "Failed to install Chef on $COMPUTE_NAME."
done
# Poll Compute nodes (dom0) to finish Chef'ing
COUNT=0
for SERVER_IP in $SERVER_IP_LIST; do
COUNT=$(($COUNT + 1))
# NOTE: we put .vpc on these because the agent doesn't seem to
# set the domain name correctly
local COMPUTE_NAME="compute$COUNT.vpc"
rake chef:poll_clients SERVER_NAME=$COMPUTE_NAME || \
{ rake tail_logs SERVER_NAME=$COMPUTE_NAME; fail "Chef client timeout: $COMPUTE_NAME"; }
done
# run Torpedo API tests (Uses the Ruby openstack-compute gem)
if [ -n "$RUN_TORPEDO" ]; then
rake torpedo SERVER_NAME=nova1 MODE=xen || \
{ rake tail_logs; fail "Hit by Torpedo."; }
fi
# run OS API v1.0 tests (Uses the Ruby openstack-compute gem)
if [ -n "$RUN_RUBY_OSAPI_V10" ]; then
rake nova:ruby_osapi_tests SERVER_NAME=nova1 MODE=xen || \
{ rake tail_logs; fail "OS API tests failed."; }
fi
# run OS API v1.1 tests (Uses the Ruby openstack-compute gem)
if [ -n "$RUN_RUBY_OSAPI_V11" ]; then
rake nova:ruby_osapi_v11_tests SERVER_NAME=nova1 MODE=xen || \
{ rake tail_logs; fail "OS API tests failed."; }
fi
# run stacktester
if [ -n "$RUN_STACK_TESTER" ]; then
rake nova:stacktester SERVER_NAME=nova1 || \
{ rake tail_logs; fail "Stacktester failed."; }
fi
else
rake tail_logs
fail "Failed to create server group."
fi
}
setup
<% if job.type == 'JobChefVpcXen' %>
run_xen_hybrid_job
<% else %>
run_job
<% end %>