Merge lp:~smoser/maas/vdenv-updates into lp:maas/trunk

Proposed by Scott Moser on 2012-07-19
Status: Merged
Approved by: Julian Edwards on 2012-07-19
Approved revision: 764
Merged at revision: 753
Proposed branch: lp:~smoser/maas/vdenv-updates
Merge into: lp:maas/trunk
Diff against target: 243 lines (+107/-57)
3 files modified
vdenv/bin/system-setup (+1/-1)
vdenv/zimmer-build/build (+7/-6)
vdenv/zimmer-build/ud-build.txt (+99/-50)
To merge this branch: bzr merge lp:~smoser/maas/vdenv-updates
Reviewer Review Type Date Requested Status
Julian Edwards (community) 2012-07-19 Approve on 2012-07-19
Review via email: mp+115645@code.launchpad.net

Commit Message

changes and updates to zimmer-build in vdenv.

 * default to importing isos only from the same release
   as the zimmer build is.
 * correctly set the DEFAULT_MAAS_URL value on each boot, to
   account for the zimmer image being booted on with different
   networking than originally. This makes use of 'maas-set-ip'
   script installed into /usr/local/bin.
 * set both http_proxy and https_proxy if desired during the
   zimmer build. Previously only http_proxy was set, meaning
   the proxy would not get used for maas-import-ephemerals.
 * when invoking kvm to build zimmer, pass 'boot=on' to kvm
   only on release older than precise.
 * change zimmer build to use quantal, support changing this
   by environment variable ZIMMER_GUEST_RELEASE
 * remove preseeding of cobbler password, and remove installation
   of cobbler-web, which would cause build to fail.
 * make zimmer build create a larger disk as data doesn't fit
   inside a < 2G image any more.

Description of the Change

This branch makes changes to zimmer-build in vdenv.

 * default to importing isos only from the same release
   as the zimmer build is.
 * correctly set the DEFAULT_MAAS_URL value on each boot, to
   account for the zimmer image being booted on with different
   networking than originally. This makes use of 'maas-set-ip'
   script installed into /usr/local/bin.
 * set both http_proxy and https_proxy if desired during the
   zimmer build. Previously only http_proxy was set, meaning
   the proxy would not get used for maas-import-ephemerals.
 * when invoking kvm to build zimmer, pass 'boot=on' to kvm
   only on release older than precise.
 * change zimmer build to use quantal, support changing this
   by environment variable ZIMMER_GUEST_RELEASE
 * remove preseeding of cobbler password, and remove installation
   of cobbler-web, which would cause build to fail.
 * make zimmer build create a larger disk as data doesn't fit
   inside a < 2G image any more.

To post a comment you must log in.
Julian Edwards (julian-edwards) wrote :

Rubber stamping.

review: Approve
lp:~smoser/maas/vdenv-updates updated on 2012-07-19
764. By Scott Moser on 2012-07-19

vdenv: system-setup relax the dpkg-query output parsing.

on 12.04:
 $ dpkg-query --show non-existant-package grep
 grep 2.10-1
 No packages found matching non-existant-package.

on 12.10:
 $ dpkg-query --show non-existant-package grep
 grep 2.12-2
 dpkg-query: no packages found matching non-existant-package

Just relax the parsing of the "no packages" to match both.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'vdenv/bin/system-setup'
2--- vdenv/bin/system-setup 2012-03-14 16:23:37 +0000
3+++ vdenv/bin/system-setup 2012-07-19 03:47:23 +0000
4@@ -23,7 +23,7 @@
5 # $ dpkg-query --show cloud-init
6 # No packages found matching cloud-init.
7 LC_ALL=C dpkg-query --show "$@" 2>&1 |
8- awk '$0 ~ /^No packages/ { sub("[.]$","",$NF); pkgs[n]=$NF; n=n+1; };
9+ awk '$0 ~ /[Nn]o packages/ { sub("[.]$","",$NF); pkgs[n]=$NF; n=n+1; };
10 END { for(p in pkgs) {printf("%s ",pkgs[p])}; printf("\n"); }' \
11 n=0
12 }
13
14=== modified file 'vdenv/zimmer-build/build'
15--- vdenv/zimmer-build/build 2012-04-10 23:13:52 +0000
16+++ vdenv/zimmer-build/build 2012-07-19 03:47:23 +0000
17@@ -15,12 +15,11 @@
18 x86_64) GUEST_ARCHITECTURE="amd64" ;;
19 esac
20
21-
22-DEF_ZIMG="http://cloud-images.ubuntu.com/server/precise/current/precise-server-cloudimg-${GUEST_ARCHITECTURE}-disk1.img"
23+GUEST_RELEASE=${ZIMMER_GUEST_RELEASE:-quantal}
24+DEF_ZIMG="http://cloud-images.ubuntu.com/server/${GUEST_RELEASE}/current/${GUEST_RELEASE}-server-cloudimg-${GUEST_ARCHITECTURE}-disk1.img"
25 DEF_SAVE_D="pristine"
26 DEF_UD_FILE="ud-build.txt"
27-ZIMMER_SSH_FORWARD=""
28-#ZIMMER_SSH_FORWARD=${ZIMMER_SSH_FORWARD:-"hostfwd=tcp::2222-:22"}
29+ZIMMER_SSH_FORWARD=${ZIMMER_SSH_FORWARD:-""} # hostfwd=tcp::2222-:22
30 ZIMMER_MEM="${ZIMMER_MEM:-1024}"
31 KVM_PID=""
32 TAIL_PID=""
33@@ -130,6 +129,7 @@
34 command -v genisoimage >/dev/null ||
35 fail "you do not have genisoimage installed. install genisoimage package"
36
37+: > "$LOG"
38
39 [ -f "$ud_file" ] ||
40 fail "user data file $ud_file" is not a file
41@@ -182,6 +182,7 @@
42 img=${zimg%.zimg}.img
43 debug 0 "creating uncompressed img $img from $zimg"
44 qemu-img convert -O qcow2 "$zimg" "$img"
45+ qemu-img resize "$img" 4G
46 fi
47
48 debug 0 "making nocloud data source in iso"
49@@ -215,8 +216,8 @@
50 qemu-img create -f qcow2 -b "$img_fp" "${build0}" ||
51 fail "failed to create qcow image backed by $img"
52
53-## on precise, you do do not need 'boot=on' in kvm commanad line
54-[ "$(lsb_release -sc)" = "precise" ] && bton="" || bton="boot=on"
55+## on release newer than oneiric, do not give 'boot=on' in kvm cmdline
56+[ "$(lsb_release -sc)" ">" "oneiric" ] && bton="" || bton="boot=on"
57
58 serial_out="$TEMP_D/serial.output"
59 monitor="${TEMP_D}/monitor.fifo" && mkfifo "$monitor" ||
60
61=== modified file 'vdenv/zimmer-build/ud-build.txt'
62--- vdenv/zimmer-build/ud-build.txt 2012-04-11 03:39:58 +0000
63+++ vdenv/zimmer-build/ud-build.txt 2012-07-19 03:47:23 +0000
64@@ -14,13 +14,15 @@
65 #ONE_TIME_PROXY=http://local-proxy:3128/
66 PROXY_COPY_SYS_TO_COBBLER=1
67
68+ [ -n "$ONE_TIME_PROXY" ] &&
69+ export http_proxy="$ONE_TIME_PROXY" &&
70+ export https_proxy="$http_proxy"
71+
72 echo === $(date) ====
73 debconf-set-selections <<EOF
74- cobbler cobbler/password password xcobbler
75 cloud-init cloud-init/datasources multiselect NoCloud
76 EOF
77
78- [ -n "$ONE_TIME_PROXY" ] && export http_proxy="$ONE_TIME_PROXY"
79 export DEBIAN_FRONTEND=noninteractive;
80 dpkg-reconfigure cloud-init
81
82@@ -39,7 +41,6 @@
83 pkgs=""
84 pkgs="$pkgs distro-info" # (LP: #960142)
85 pkgs="$pkgs libvirt-bin" # for power control via virsh
86- pkgs="$pkgs cobbler-web" # for debugging and ease of use of cobbler
87 pkgs="$pkgs maas" # main maas package
88 apt_get update
89 apt_get install ${pkgs}
90@@ -56,59 +57,107 @@
91 ln -sf ${fname##*/}.zimmer "$fname"
92 fi
93
94- # hack /etc/init/cobbler.conf to always update its IP address on start
95- cat >> /etc/init/cobbler.conf <<"ENDCOB"
96- #### added by zimmer-build ######
97- pre-start script
98- #set -x; exec >/tmp/cobbler-pre.out 2>/tmp/cobbler-pre.err
99- found=""
100- fn="/etc/cobbler/cobbler-server"
101-
102- # if user wants to manage this, then just remove that file
103- # it is expected to either have an IP address or 'auto'
104- [ -f "$fn" ] || exit 0
105- read found < "$fn" || :
106- [ -n "$found" -a "$found" != "auto" ] ||
107- found=$(ifconfig eth0 2>/dev/null |
108- awk '$0 ~ /inet addr:/ { sub(/.*:/,"",$2); print $2; }')
109-
110- [ -z "$found" ] && exit 0
111-
112- sed -i.start -e "s/^next_server: .*$/next_server: $found/" \
113- -e "s/^server: *..*..*..*$/server: $found/" \
114- /etc/cobbler/settings
115-
116- # if the above sed did something, then we leave the orig
117- # file around for post-start to cleanup.
118- cmp /etc/cobbler/settings.start /etc/cobbler/settings >/dev/null &&
119- rm -f /etc/cobbler/settings.start || :
120- end script
121-
122- post-start script
123- #set -x; exec >/tmp/cobbler-start.out 2>/tmp/cobbler-start.err
124- set +e # upstart uses 'set -e' by default
125- [ -f /etc/cobbler/settings.start ] || exit 0
126- rm -f /etc/cobbler/settings.start
127-
128- # now basically wait around until cobbler is available
129- while : ; do
130+ ## set up rc.local.d functionality (LP: #915215)
131+ mkdir -p /etc/rc.local.d
132+ if [ ! -e /etc/rc.local.d/00-rc-local ]; then
133+ mv /etc/rc.local /etc/rc.local.d/00-rc-local
134+ fi
135+ printf "#!/bin/sh\nrun-parts /etc/rc.local.d\n" >> /etc/rc.local
136+ chmod 755 /etc/rc.local
137+
138+ # add an rc.local.d job that sets MAAS_PROVISION_URL and cobbler
139+ # to have the right ip address.
140+ cat > /etc/rc.local.d/maas-ip-fixup <<"END_MAAS_IP_FIXUP"
141+ #!/bin/sh
142+ # reconfigure maas in case our IP address has changed
143+ # get the right value for maas/default-maas-url. it will take
144+ # care of restarting things that need to be
145+ /usr/local/bin/maas-set-ip set auto
146+
147+ # now basically wait around until cobbler is available
148+ # detach to not block the rest of boot
149+ sh -c '
150+ max=3; i=0;
151+ while [ $i -lt $max ]; do
152 # will exit 155 if "cobblerd does not appear to be running"
153 cobbler system list >/dev/null
154 [ $? -eq 155 ] || break
155- sleep 1
156+ sleep 4
157+ i=$(($i+1))
158 done
159
160- # we're allowing cobbler to start even if these fail
161- cobbler sync
162- maas-import-isos --update
163- exit 0
164- end script
165- ENDCOB
166-
167- echo "auto" >> /etc/cobbler/cobbler-server
168-
169+ if [ $i -ne $max ]; then
170+ # if we talked to cobbler above, then sync it and import-isos
171+ cobbler sync
172+ maas-import-isos --update
173+ fi' &
174+ END_MAAS_IP_FIXUP
175+ chmod 755 /etc/rc.local.d/maas-ip-fixup
176+
177+ cat > /usr/local/bin/maas-set-ip <<"END_MAAS_SET_IP"
178+ #!/bin/sh
179+
180+ FIELDS="maas/default-maas-url"
181+ Usage() {
182+ cat <<EOF
183+ Usage ${0##*/} [set|show]
184+ Set or show the IP addresses for maas.
185+ for set, provide IP address or "auto"
186+ EOF
187+ }
188+ [ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
189+ [ "$1" = "set" -o "$1" = "show" ] || { Usage 1>&2; exit 1; }
190+
191+ get() {
192+ _RET=$(debconf-show ${1%%/*} 2>/dev/null |
193+ awk '{gsub("*","");} $1 == key { print $2 }' "key=$1:")
194+ }
195+ show() {
196+ while [ $# -ne 0 ]; do
197+ get $1; echo "$1: $_RET"
198+ shift
199+ done
200+ }
201+ get_ip() {
202+ # stolen from /var/lib/dpkg/info/maas.postinst
203+ local Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window \
204+ local IRTT interface ipaddr
205+ while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU \
206+ Window IRTT; do
207+ [ "$Mask" = "00000000" ] && break
208+ done < /proc/net/route
209+ interface="$Iface"
210+ ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global)
211+ ipaddr=${ipaddr#* inet }
212+ ipaddr=${ipaddr%%/*}
213+ _RET=${ipaddr}
214+ }
215+ if [ "$1" = "show" ]; then
216+ show $FIELDS
217+ else
218+ [ "$(id -u)" = "0" ] || { echo "must be root to set" 1>&2; exit 1; }
219+ url_val=$2
220+ url_key="maas/default-maas-url"
221+ if [ "${url_val:-auto}" = "auto" ]; then
222+ get_ip
223+ url_val=$_RET
224+ fi
225+ printf "%s\t%s\t%s\t%s\n" \
226+ "${url_key%%/*}" "${url_key}" "string" "$url_val" |
227+ debconf-set-selections
228+ DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-noninteractive} \
229+ dpkg-reconfigure -plow ${url_key%%/*}
230+ sudo service apache2 restart
231+ show $FIELDS
232+ #grep MAAS_URL /etc/maas/maas_local_settings.py
233+ #egrep "^(server|next_server)" /etc/cobbler/settings
234+ fi
235+ END_MAAS_SET_IP
236+ chmod 755 /usr/local/bin/maas-set-ip
237+
238+ my_release=$(lsb_release -c)
239 cat >> /etc/maas/import_isos <<END
240- RELEASES="precise"
241+ RELEASES="${my_release}"
242 ARCHES="i386 amd64"
243 END
244