Merge lp:~sylvain-pineau/checkbox/bug1086048 into lp:checkbox

Proposed by Sylvain Pineau
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 1854
Merged at revision: 1873
Proposed branch: lp:~sylvain-pineau/checkbox/bug1086048
Merge into: lp:checkbox
Diff against target: 125 lines (+33/-5)
2 files modified
debian/changelog (+1/-0)
scripts/kvm_test (+32/-5)
To merge this branch: bzr merge lp:~sylvain-pineau/checkbox/bug1086048
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+139886@code.launchpad.net

Commit message

kvm_test: Add verbose output on errors

Description of the change

kvm_test: Add verbose output on errors

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Interesting approach

I don't oppose landing that but I have this feeling that we've crossed the boundary when still writing in shell makes sense. We should, at the closest opportunity, rewrite that into python.

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-12-13 13:11:40 +0000
3+++ debian/changelog 2012-12-14 13:05:29 +0000
4@@ -46,6 +46,7 @@
5 unity_support_test and piped to ansi_parser.
6 * scripts/network_device_info: Set the driver version to 'Unknown' if the
7 modinfo_parser returns nothing (LP: #1089911)
8+ * scripts/kvm_test: Add verbose output on errors (LP: #1086048)
9
10 -- Daniel Manrique <roadmr@ubuntu.com> Fri, 16 Nov 2012 12:14:21 -0500
11
12
13=== modified file 'scripts/kvm_test'
14--- scripts/kvm_test 2012-08-23 16:55:51 +0000
15+++ scripts/kvm_test 2012-12-14 13:05:29 +0000
16@@ -1,7 +1,9 @@
17 #!/bin/bash
18
19-# Exit on any error
20-set -o errexit
21+set -o pipefail # trace ERR through pipes
22+set -o errtrace # trace ERR through functions
23+
24+ERROR='Unknown Error'
25
26 # Cleanup on exit
27 function cleanup() {
28@@ -9,38 +11,55 @@
29 [ -n "$kvm_pid" ] && kill $kvm_pid
30 }
31
32-trap cleanup 0
33+function error_handler()
34+{
35+ echo "$0: ${ERROR}"
36+ exit 1
37+}
38+
39+trap cleanup EXIT
40+trap error_handler ERR
41
42 # Build cloud image URL
43+ERROR="Unable to create temporary files"
44 temp_dir=$(mktemp -d)
45 if [ $# -eq 0 ]; then
46+ ERROR="Unable to get the latest release name from cloud-images.ubuntu.com"
47 release=$(wget -q -O - http://cloud-images.ubuntu.com/query/released.latest.txt | tail -n 2 | head -1 | cut -f 1)
48 cloud_dir="http://cloud-images.ubuntu.com/$release/current/"
49+ ERROR="Unable to get the cloud image URL from cloud-images.ubuntu.com"
50 cloud_name=$(wget -q -O - $cloud_dir | sed -n 's/.*href="\(.*i386.*img\)".*/\1/p')
51 cloud_image="$cloud_dir$cloud_name"
52 else
53 cloud_image=$1
54 fi
55
56+ERROR="Unable to set the working directory"
57 cd $temp_dir
58
59 # Get cloud image URL
60 if [ ! -e "$cloud_image" ]; then
61 cloud_name="$(basename $cloud_image)"
62+ ERROR="Unable to get cloud image $cloud_image"
63 wget -q -O $cloud_name $cloud_image
64 cloud_image="$temp_dir/$cloud_name"
65 fi
66
67 # Create public/private ssh keys for passwordless auth.
68+ERROR="Unable to create the required ssh key"
69 if [ ! -e "ssh_key" ]; then
70 ssh-keygen -q -t "rsa" -f "ssh_key" -N "" -C ""
71+else
72+ exit 1
73 fi
74
75 # Create user-data and meta-data files that will be used to modify image on first boot
76+ERROR="Unable to create meta-data file"
77 cat <<EOF > "meta-data"
78 instance-id: iid-local01
79 local-hostname: cloudimg
80 EOF
81+ERROR="Unable to create user-data file"
82 cat <<EOF > "user-data"
83 #cloud-config
84 password: passw0rd
85@@ -52,17 +71,24 @@
86
87 # create a disk to attach with some user-data and meta-data
88 seed="seed.iso"
89+ERROR="Unable to create $seed"
90 if [ ! -e "$seed" ]; then
91 genisoimage -quiet -output $seed -volid cidata -joliet -rock "user-data" "meta-data"
92+else
93+ exit 1
94 fi
95
96 # create a new qcow image to boot, backed by the original image
97 boot_disk="boot-disk.img"
98+ERROR="Unable to create $boot_disk"
99 if [ ! -e "$boot_disk" ]; then
100 qemu-img create -f qcow2 -b $cloud_image $boot_disk > /dev/null
101+else
102+ exit 1
103 fi
104
105 # Boot the image
106+ERROR="Unable to boot the cloud image"
107 kvm -m 256 \
108 -net nic \
109 -net user,net=10.0.0.0/8,host=10.0.0.1,hostfwd=tcp::2222-:22 \
110@@ -72,7 +98,8 @@
111 kvm_pid=$!
112
113 # Verify that the VM is running
114-set +o errexit
115+ERROR="Unable to ssh into the kvm instance"
116+trap "" ERR
117 for i in $(seq 20); do
118 sleep 6
119 output=$(ssh -q \
120@@ -89,4 +116,4 @@
121 fi
122 done
123
124-exit 1
125+error_handler

Subscribers

People subscribed via source and target branches