Merge lp:~darkmuggle-deactivatedaccount/ubuntu/precise/cloud-init/lp1336855 into lp:ubuntu/precise-proposed/cloud-init

Proposed by Ben Howard
Status: Work in progress
Proposed branch: lp:~darkmuggle-deactivatedaccount/ubuntu/precise/cloud-init/lp1336855
Merge into: lp:ubuntu/precise-proposed/cloud-init
Diff against target: 207 lines (+148/-1)
7 files modified
.pc/applied-patches (+1/-0)
.pc/lp-1336855-grub_xvda.patch/cloudinit/CloudConfig/cc_grub_dpkg.py (+64/-0)
cloudinit/CloudConfig/cc_grub_dpkg.py (+2/-1)
debian/changelog (+10/-0)
debian/cloud-init.postinst (+51/-0)
debian/patches/lp-1336855-grub_xvda.patch (+19/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~darkmuggle-deactivatedaccount/ubuntu/precise/cloud-init/lp1336855
Reviewer Review Type Date Requested Status
Scott Moser Pending
Ubuntu Development Team Pending
Review via email: mp+225549@code.launchpad.net
To post a comment you must log in.
209. By Ben Howard

* fixed issues where grub-pc does not consider xvda (LP: 1336855).
  - debian/patches/lp-1336855-grub_xvda.patch: added xvda as a
    considered device
  - debian/cloud-init.postinst: check to see if grub-pc is configured
    for the right device.

Revision history for this message
Robert C Jennings (rcj) wrote :

Comments below

210. By Ben Howard

Remove mtab reading and replace with chroot check

211. By Ben Howard

Fixed minor typo

Revision history for this message
Iain Lane (laney) wrote :

hi smoser, care to review?

thanks!

Revision history for this message
Scott Moser (smoser) wrote :

One comment in line (wrt chroot).
Also, would it make sense to just run:
  cloud-init --frequency=always --name=grub-dpkg
that might stop us from re-implementing logic already present in cloud-init in its postinst.

You'd ideally only do that (or all of this) in a case where the version that we're upgrading from is known-broken.

Revision history for this message
Sebastien Bacher (seb128) wrote :

what's the status of that, was the previous comment a blocker/something that needs to be addressed before upload?

Revision history for this message
Sebastien Bacher (seb128) wrote :

no reply, setting to "work in progress" to get out of the sponsoring queue until the issue is addressed, change back to "needs review" when that is done

Unmerged revisions

211. By Ben Howard

Fixed minor typo

210. By Ben Howard

Remove mtab reading and replace with chroot check

209. By Ben Howard

* fixed issues where grub-pc does not consider xvda (LP: 1336855).
  - debian/patches/lp-1336855-grub_xvda.patch: added xvda as a
    considered device
  - debian/cloud-init.postinst: check to see if grub-pc is configured
    for the right device.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.pc/applied-patches'
2--- .pc/applied-patches 2014-04-07 14:59:56 +0000
3+++ .pc/applied-patches 2014-07-03 20:47:31 +0000
4@@ -22,3 +22,4 @@
5 lp-1269626-azure_new_instance.patch
6 lp-1292648-azure-format-ephemeral-new.patch
7 lp-1302229-fix_futils_azure.patch
8+lp-1336855-grub_xvda.patch
9
10=== added directory '.pc/lp-1336855-grub_xvda.patch'
11=== added directory '.pc/lp-1336855-grub_xvda.patch/cloudinit'
12=== added directory '.pc/lp-1336855-grub_xvda.patch/cloudinit/CloudConfig'
13=== added file '.pc/lp-1336855-grub_xvda.patch/cloudinit/CloudConfig/cc_grub_dpkg.py'
14--- .pc/lp-1336855-grub_xvda.patch/cloudinit/CloudConfig/cc_grub_dpkg.py 1970-01-01 00:00:00 +0000
15+++ .pc/lp-1336855-grub_xvda.patch/cloudinit/CloudConfig/cc_grub_dpkg.py 2014-07-03 20:47:31 +0000
16@@ -0,0 +1,64 @@
17+# vi: ts=4 expandtab
18+#
19+# Copyright (C) 2009-2010 Canonical Ltd.
20+# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
21+#
22+# Author: Scott Moser <scott.moser@canonical.com>
23+# Author: Juerg Haefliger <juerg.haefliger@hp.com>
24+#
25+# This program is free software: you can redistribute it and/or modify
26+# it under the terms of the GNU General Public License version 3, as
27+# published by the Free Software Foundation.
28+#
29+# This program is distributed in the hope that it will be useful,
30+# but WITHOUT ANY WARRANTY; without even the implied warranty of
31+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+# GNU General Public License for more details.
33+#
34+# You should have received a copy of the GNU General Public License
35+# along with this program. If not, see <http://www.gnu.org/licenses/>.
36+
37+import cloudinit.util as util
38+import traceback
39+import os
40+
41+
42+def handle(_name, cfg, _cloud, log, _args):
43+ idevs = None
44+ idevs_empty = None
45+
46+ if "grub-dpkg" in cfg:
47+ idevs = util.get_cfg_option_str(cfg["grub-dpkg"],
48+ "grub-pc/install_devices", None)
49+ idevs_empty = util.get_cfg_option_str(cfg["grub-dpkg"],
50+ "grub-pc/install_devices_empty", None)
51+
52+ if ((os.path.exists("/dev/sda1") and not os.path.exists("/dev/sda")) or
53+ (os.path.exists("/dev/xvda1") and not os.path.exists("/dev/xvda"))):
54+ if idevs == None:
55+ idevs = ""
56+ if idevs_empty == None:
57+ idevs_empty = "true"
58+ else:
59+ if idevs_empty == None:
60+ idevs_empty = "false"
61+ if idevs == None:
62+ idevs = "/dev/sda"
63+ for dev in ("/dev/sda", "/dev/vda", "/dev/sda1", "/dev/vda1"):
64+ if os.path.exists(dev):
65+ idevs = dev
66+ break
67+
68+ # now idevs and idevs_empty are set to determined values
69+ # or, those set by user
70+
71+ dconf_sel = "grub-pc grub-pc/install_devices string %s\n" % idevs + \
72+ "grub-pc grub-pc/install_devices_empty boolean %s\n" % idevs_empty
73+ log.debug("setting grub debconf-set-selections with '%s','%s'" %
74+ (idevs, idevs_empty))
75+
76+ try:
77+ util.subp(('debconf-set-selections'), dconf_sel)
78+ except:
79+ log.error("Failed to run debconf-set-selections for grub-dpkg")
80+ log.debug(traceback.format_exc())
81
82=== modified file 'cloudinit/CloudConfig/cc_grub_dpkg.py'
83--- cloudinit/CloudConfig/cc_grub_dpkg.py 2012-02-16 17:27:05 +0000
84+++ cloudinit/CloudConfig/cc_grub_dpkg.py 2014-07-03 20:47:31 +0000
85@@ -44,7 +44,8 @@
86 idevs_empty = "false"
87 if idevs == None:
88 idevs = "/dev/sda"
89- for dev in ("/dev/sda", "/dev/vda", "/dev/sda1", "/dev/vda1"):
90+ for dev in ("/dev/sda", "/dev/vda", "/dev/xvda",
91+ "/dev/xvda1", "/dev/sda1", "/dev/vda1"):
92 if os.path.exists(dev):
93 idevs = dev
94 break
95
96=== modified file 'debian/changelog'
97--- debian/changelog 2014-04-07 15:18:55 +0000
98+++ debian/changelog 2014-07-03 20:47:31 +0000
99@@ -1,3 +1,13 @@
100+cloud-init (0.6.3-0ubuntu1.14) precise; urgency=medium
101+
102+ * fixed issues where grub-pc does not consider xvda (LP: 1336855).
103+ - debian/patches/lp-1336855-grub_xvda.patch: added xvda as a
104+ considered device
105+ - debian/cloud-init.postinst: check to see if grub-pc is configured
106+ for the right device.
107+
108+ -- Ben Howard <ben.howard@ubuntu.com> Wed, 02 Jul 2014 13:42:12 -0600
109+
110 cloud-init (0.6.3-0ubuntu1.13) precise-proposed; urgency=medium
111
112 * debian/patches/lp-1302229-fix_futils_azure.patch: fixed imports and
113
114=== modified file 'debian/cloud-init.postinst'
115--- debian/cloud-init.postinst 2013-10-16 13:17:35 +0000
116+++ debian/cloud-init.postinst 2014-07-03 20:47:31 +0000
117@@ -157,6 +157,57 @@
118
119 # if there is generic cloud-config preseed, apply them
120 handle_preseed_local_cloud_config
121+
122+ ### Begin fix for LP: 1336855
123+ # fix issue where cloud-init misidentifies the location of grub
124+ if [ -x /usr/sbin/grub-install ]; then
125+
126+ # First, identify the root device for the parent.
127+ for parm in $(cat /proc/cmdline); do
128+ dev=$(echo $parm | awk -F\= '{print$NF}')
129+ case $parm in
130+ root=UUID*) [ -d /dev/disk/by-uuid ] &&
131+ root_dev=$(readlink -f /dev/disk/by-uuid/$dev);;
132+ root=LABEL*) [ -d /dev/disk/by-label ] &&
133+ root_dev=$(readlink -f /dev/disk/by-label/$dev);;
134+ root=/dev*) [ -d /dev ] &&
135+ root_dev=$(readlink -f $dev);;
136+ esac
137+ [ -n "$root_dev" ] && break
138+ done
139+
140+ # Only deal with simple, cloud-based devices
141+ case $root_dev in
142+ /dev/vda*|/dev/xvda*|/dev/sda*) install_grub_safe=1;;
143+ *) install_grub_safe=0;;
144+ esac
145+
146+ # Make sure that we are not chrooted. We want to be safe.
147+ [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ] &&
148+ install_grub_safe=0;
149+
150+ if [ "$install_grub_safe" -eq 1 ]; then
151+ # Find out where grub thinks the root device is
152+ db_get grub-pc/install_devices && grub_cfg_dev=${RET} || :
153+ db_get grub-pc/install_devices_empty && grub_dev_empty=${RET} || :
154+
155+ # Find out the parent device for the root device
156+ block_path=$(udevadm info -q path -n $root_dev | awk '-Fblock/' '{print$NF}')
157+ pdev=$(echo $block_path | awk '-F/' '{print$1}')
158+ [ -n "$pdev" ] && parent_dev="/dev/$pdev"
159+
160+ # If everything checks out, set grub-pc/install_devices and re-install
161+ # grub.
162+ if [ "$grub_dev_empty" = "false" -a -n "$parent_dev" -a "$parent_dev" != "$grub_cfg_dev" ]; then
163+ echo "Reconfiguring grub install device due to mismatch"
164+ db_set grub-pc/install_devices "$parent_dev"
165+ grub-install $parent_dev ||
166+ echo "WARNING! Unable to fix grub device mismatch. You may be broken."
167+ fi
168+ fi
169+ fi
170+ ### END fix for LP: 1336855
171+
172 fi
173
174 #DEBHELPER#
175
176=== added file 'debian/patches/lp-1336855-grub_xvda.patch'
177--- debian/patches/lp-1336855-grub_xvda.patch 1970-01-01 00:00:00 +0000
178+++ debian/patches/lp-1336855-grub_xvda.patch 2014-07-03 20:47:31 +0000
179@@ -0,0 +1,19 @@
180+Description: consider xvda devices for grub-pc configuration
181+ Cloud-init previously did not consider /dev/xvda and /dev/xvda1 for
182+ setting as the grub device. Subsequently, unattended updates with
183+ grub may cause the instance to be unusable.
184+Author: Ben Howard <ben.howard@ubuntu.com>
185+Bug: https://bugs.launchpad.net/bugs/1336855
186+Forwarded: yes
187+--- a/cloudinit/CloudConfig/cc_grub_dpkg.py
188++++ b/cloudinit/CloudConfig/cc_grub_dpkg.py
189+@@ -44,7 +44,8 @@
190+ idevs_empty = "false"
191+ if idevs == None:
192+ idevs = "/dev/sda"
193+- for dev in ("/dev/sda", "/dev/vda", "/dev/sda1", "/dev/vda1"):
194++ for dev in ("/dev/sda", "/dev/vda", "/dev/xvda",
195++ "/dev/xvda1", "/dev/sda1", "/dev/vda1"):
196+ if os.path.exists(dev):
197+ idevs = dev
198+ break
199
200=== modified file 'debian/patches/series'
201--- debian/patches/series 2014-04-07 14:59:56 +0000
202+++ debian/patches/series 2014-07-03 20:47:31 +0000
203@@ -22,3 +22,4 @@
204 lp-1269626-azure_new_instance.patch
205 lp-1292648-azure-format-ephemeral-new.patch
206 lp-1302229-fix_futils_azure.patch
207+lp-1336855-grub_xvda.patch

Subscribers

People subscribed via source and target branches

to all changes: