88# | | | |
99# +- vrouter -+ | |
1010# | +------------- vrouter -+
11+ # | | | |
1112# | 1 2 | | |
1213# +--- vm1 ---+ | |
1314# | | 2 1 | vm8 ---+
@@ -153,11 +154,10 @@ nova keypair-add --pub-key sshkey.pub sshkey
153154# cloudinit script to verify that the metadata server is working
154155tee cloudinit.sh << EOF
155156#! /bin/sh
156- echo "Cloudinit worked!"
157- echo
158-
159- echo "Inet interfaces:"
160- ip -o -f inet addr list
157+ echo "--- cloudinit.sh ---"
158+ ip -o -f inet addr list | sed -e 's/^[0-9]*: //' -e 's/ *inet//' -e 's/\/.*//' -e '/^lo/d'
159+ #(cd /run/cirros/datasource/data && for i in *; do echo -n "$i : "; head -1 $i ; done)
160+ echo "--- cloudinit.sh ---"
161161EOF
162162chmod a+x cloudinit.sh
163163
@@ -166,34 +166,43 @@ flavor=m1.tiny
166166vm_params=" --image $image --flavor $flavor --key-name sshkey --user-data cloudinit.sh"
167167
168168# vms
169+ vms=" "
169170
170171# vm1: net1, net2
171172nova boot $vm_params --nic net-id=$net1_id --nic net-id=$net2_id vm1
173+ vms=" $vms vm1"
172174
173175# vm2: net2, net1, float on net2
174176nova boot $vm_params --nic net-id=$net2_id --nic net-id=$net1_id vm2
177+ vms=" $vms vm2"
175178
176179# floatingip1 for vm2,net2
177180floatingip1_id=$( floatingip_create $public_id )
178181floatingip_associate vm2 net2 $floatingip1_id
179182
180183# vm4: net1
181184nova boot $vm_params --nic net-id=$net1_id vm4
185+ vms=" $vms vm4"
182186
183187# vm5: net2
184188nova boot $vm_params --nic net-id=$net2_id vm5
189+ vms=" $vms vm5"
185190
186191# vm3: public, net2
187192nova boot $vm_params --nic net-id=$public_id --nic net-id=$net2_id vm3
193+ vms=" $vms vm3"
188194
189195# vm6: public, net2
190196nova boot $vm_params --nic net-id=$public_id --nic net-id=$net2_id vm6
197+ vms=" $vms vm6"
191198
192199# vm7: public, net1, net2
193200nova boot $vm_params --nic net-id=$public_id --nic net-id=$net1_id --nic net-id=$net2_id vm7
201+ vms=" $vms vm7"
194202
195203# vm9: public
196204nova boot $vm_params --nic net-id=$public_id vm9
205+ vms=" $vms vm9"
197206
198207# net4 (new)
199208net4_id=$( net_create net4)
@@ -205,9 +214,91 @@ net_policy_join.py $net2_id $net4_id
205214
206215# vm8: net4
207216nova boot $vm_params --nic net-id=$net4_id vm8
217+ vms=" $vms vm8"
208218
209219# show where the vms ended up
210220nova list --fields name,status,Networks,OS-EXT-SRV-ATTR:host
211221
212- # restore the shell flags, since this script is usually sourced
222+ # don't exit this whole shell if a test fails
213223set +ex
224+
225+ # ----------------------------------------------------------------------
226+ # tests
227+
228+ # wait for the console-log to get to a login prompt
229+ vms_to_test=" $vms "
230+ echo
231+ echo " Waiting for VMs to boot: $vms_to_test ..."
232+ t0=$SECONDS
233+ while [ " $vms_to_test " ]; do
234+ # timeout after a few minutes
235+ if [ $(( $SECONDS - $t0 )) -gt 300 ]; then
236+ die " VMs failed to boot: $vms_to_test "
237+ fi
238+ vms_to_test_next=" "
239+ for vm in $vms_to_test ; do
240+ if nova console-log $vm | grep -q ' login: $' ; then
241+ echo " $vm booted in $(( $SECONDS - $t0 )) s"
242+ nova console-log $vm | \
243+ sed -n -e ' /--- cloudinit.sh ---/,/--- cloudinit.sh ---/ s/^/ / p' | head -n-1 | tail -n+2
244+ else
245+ vms_to_test_next=" $vms_to_test_next $vm "
246+ fi
247+ done
248+ vms_to_test=" $vms_to_test_next "
249+ done
250+
251+ echo " All VMs booted in $(( $SECONDS - $t0 )) s"
252+
253+ vm1_net2_ip=10.2.0.253; vm1_net1_ip=10.1.0.253
254+ vm2_net2_ip=10.2.0.252; vm2_float_ip=10.99.99.253; vm2_net1_ip=10.1.0.252
255+ vm3_public_ip=10.99.99.252; vm3_net2_ip=10.2.0.250
256+ vm4_net1_ip=10.1.0.251
257+ vm5_net2_ip=10.2.0.251
258+ vm6_public_ip=10.99.99.251; vm6_net2_ip=10.2.0.249
259+ vm7_public_ip=10.99.99.250; vm7_net1_ip=10.1.0.250; vm7_net2_ip=10.2.0.248
260+ vm8_net4_ip=10.4.0.253
261+ vm9_public_ip=10.99.99.249
262+
263+ test_vm_ssh () {
264+ msg=" $1 "
265+ shift
266+ ssh_cmdline=" "
267+ for ip in " $@ " ; do
268+ ssh_cmdline=" $ssh_cmdline ssh -A -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no cirros@$ip "
269+ done
270+
271+ # debug
272+ ssh_cmdline=" timeout 10s $ssh_cmdline ip -o -f inet addr list"
273+
274+ echo -n " $msg ... "
275+ out=$( $ssh_cmdline < /dev/null 2>&1 )
276+ if [ $? = 0 ]; then
277+ echo " ok"
278+ else
279+ echo " fail"
280+ die " $ssh_cmdline " $out
281+ fi
282+ }
283+
284+ echo
285+ echo " Testing SSH connecivity..."
286+
287+ test_vm_ssh " vm2_float" $vm2_float_ip
288+ test_vm_ssh " vm3_public" $vm3_public_ip
289+ test_vm_ssh " vm6_public" $vm6_public_ip
290+ test_vm_ssh " vm7_public" $vm7_public_ip
291+ test_vm_ssh " vm9_public" $vm9_public_ip
292+
293+ test_vm_ssh " vm2_float -> vm1_net1" $vm2_float_ip $vm1_net1_ip
294+ test_vm_ssh " vm2_float -> vm4_net1" $vm2_float_ip $vm4_net1_ip
295+ test_vm_ssh " vm2_float -> vm5_net2" $vm2_float_ip $vm5_net2_ip
296+ test_vm_ssh " vm2_float -> vm1_net2 -> vm4_net1" $vm2_float_ip $vm1_net2_ip $vm4_net1_ip
297+ test_vm_ssh " vm2_float -> vm8_net4" $vm2_float_ip $vm8_net4_ip
298+ test_vm_ssh " vm2_float -> vm5_net2 -> vm8_net4" $vm2_float_ip $vm5_net2_ip $vm8_net4_ip
299+ test_vm_ssh " vm7_public -> vm4_net1" $vm7_public_ip $vm4_net1_ip
300+ test_vm_ssh " vm7_public -> vm5_net2" $vm7_public_ip $vm5_net2_ip
301+ test_vm_ssh " vm7_public -> vm9_public" $vm7_public_ip $vm9_public_ip
302+ test_vm_ssh " vm6_public -> vm2_net2" $vm6_public_ip $vm2_net2_ip
303+
304+
0 commit comments