Merge lp:~larsks/cloud-utils/bug-1807171 into lp:cloud-utils

Proposed by Lars Kellogg-Stedman
Status: Merged
Merged at revision: 339
Proposed branch: lp:~larsks/cloud-utils/bug-1807171
Merge into: lp:cloud-utils
Diff against target: 112 lines (+96/-1)
2 files modified
bin/growpart (+1/-1)
test/test-growpart-start-matches-size (+95/-0)
To merge this branch: bzr merge lp:~larsks/cloud-utils/bug-1807171
Reviewer Review Type Date Requested Status
Scott Moser (community) Approve
Review via email: mp+360264@code.launchpad.net

Commit message

growpart: fix bug occurring if start sector and size were the same.

The existing sed expression would erroneously change the start sector
of a partition, rather than the size, if the start sector and size
were identical. This commit modifies the sed expression so that it
will only operate on the final match in the line.

To post a comment you must log in.
Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

Ugh, so, the first stab a test is invalid because it only checks the output of growpart, and growpart lies. I'll submit an update in a moment.

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

2 problems with the test case:
a.) it has some tab/spaces indentation issues. for better or worse (probably worse), current expectation in those files is tabs.
b.) running it with current growpart does not catch the failure.

heres some modifications that catch the failure.
http://paste.ubuntu.com/p/BX5BkX7XFB/

integrate those , commit and i'll be happy.

thanks!

lp:~larsks/cloud-utils/bug-1807171 updated
340. By Lars Kellogg-Stedman

Fix test for bug #1807171

The test in the previous commit did not actually verify that the
final partition table matched the desired configuration.

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

I fixed the test, but in a completely different fashion. I've tested the test case against both the fix and the previous commit to verify that it breaks when expected.

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

larsks,
this looks good. thank you.

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

Lars,

Looking at it a bit more I'mk going to ake a small change in how we read back
the content from the sfdisk dump. My initial suggestion was trying to be
more forgiving in sfdisk output. sfdisk --dump probably doesn't guarantee
that its output is identical across different versions. For the simplist
case imagine that they add a new field to the header. That would cause
the test to fail.

So what I've done here is add a 'read_pt_info' that tries to read
a specific key for a specific partition in --dump output in a relatively
forgiving way.

Basically... I just don't want to babysit test failures that are not
test failures in the event of sfdisk changing its output.

Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

It seems that we need to trust the output of sfdisk --dump because we rely on it in growpart. The simplest fix would be to just discard the headers and only look at the partition lines. In any case, I'm happy as long as you're happy :).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/growpart'
--- bin/growpart 2018-10-19 16:46:40 +0000
+++ bin/growpart 2018-12-06 22:40:58 +0000
@@ -323,7 +323,7 @@
323 # now, change the size for this partition in ${dump_out} to be the323 # now, change the size for this partition in ${dump_out} to be the
324 # new size324 # new size
325 new_size=$((${max_end}-${pt_start}))325 new_size=$((${max_end}-${pt_start}))
326 sed "\|^\s*${dpart} |s/${pt_size},/${new_size},/" "${dump_out}" \326 sed "\|^\s*${dpart} |s/\(.*\)${pt_size},/\1${new_size},/" "${dump_out}" \
327 >"${new_out}" ||327 >"${new_out}" ||
328 fail "failed to change size in output"328 fail "failed to change size in output"
329329
330330
=== added file 'test/test-growpart-start-matches-size'
--- test/test-growpart-start-matches-size 1970-01-01 00:00:00 +0000
+++ test/test-growpart-start-matches-size 2018-12-06 22:40:58 +0000
@@ -0,0 +1,95 @@
1#!/bin/bash
2#
3# Create a disk image where there exists a partition whose sizes matches the
4# start sector.
5# brought up under bug 1807171, which describes an error in the sed expression
6# used to generate the replacement partition map
7
8set -e
9
10TEMP_D=""
11
12rq() {
13 local out="${TEMP_D}/out"
14 "$@" > "$out" 2>&1 || { echo "FAILED:" "$@"; cat "$out"; return 1; }
15}
16fail() { echo "FAILED:" "$@" 1>&2; exit 1; }
17
18setup_image() {
19 sfdisk disk.img <<EOF
20label: gpt
21label-id: db24000c-6ef3-4a17-b71c-1064baa29514
22device: disk.img
23unit: sectors
24first-lba: 2048
25last-lba: 4194270
26
27disk.img1 : start= 2048, size= 1024000, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=5bc16165-bfc0-4e13-94eb-b898dc0bca41
28disk.img2 : start= 1026048, size= 1026048, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=a0e1636e-b759-4e7a-bd14-6f3d6c04745d
29EOF
30}
31
32cleanup() {
33 rm -rf "${TEMP_D}"
34}
35
36TEMP_D=$(mktemp -d ${TMPDIR:-/tmp}/${0##*/}.XXXXXX)
37trap cleanup EXIT
38
39# the sfdisk and sgdisk resizers result in slightly different output, because
40# of course they do.
41
42expected_sfdisk='label: gpt
43label-id: DB24000C-6EF3-4A17-B71C-1064BAA29514
44device: disk.img
45unit: sectors
46first-lba: 2048
47last-lba: 4194270
48
49disk.img1 : start= 2048, size= 1024000, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=5BC16165-BFC0-4E13-94EB-B898DC0BCA41
50disk.img2 : start= 1026048, size= 3168223, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=A0E1636E-B759-4E7A-BD14-6F3D6C04745D'
51
52expected_sgdisk='label: gpt
53label-id: DB24000C-6EF3-4A17-B71C-1064BAA29514
54device: disk.img
55unit: sectors
56first-lba: 2048
57last-lba: 4192256
58
59disk.img1 : start= 2048, size= 1024000, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=5BC16165-BFC0-4E13-94EB-B898DC0BCA41
60disk.img2 : start= 1026048, size= 3166208, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=A0E1636E-B759-4E7A-BD14-6F3D6C04745D'
61
62
63CR='
64'
65
66test_resize () {
67 local resizer=$1
68 local expected=$2
69 echo "====== Testing with resizer=$resizer ====="
70
71 (
72 cd ${TEMP_D}
73 echo "$expected" > partitions.expected
74
75 rq truncate "--size=2G" disk.img
76 rq setup_image || fail "setup image $img"
77
78 sfdisk --dump disk.img > partitions.before
79
80 if ! GROWPART_RESIZER=$resizer \
81 growpart -v -v disk.img 2 2>"stderr" > "stdout"; then
82 cat "stderr" "stdout"
83 fail "[resizer=$resizer] growpart failed"
84 fi
85
86 sfdisk --dump disk.img > partitions.after
87 if ! diff -U0 partitions.expected partitions.after; then
88 fail "[resizer=$resizer] partition table is incorrect"
89 fi
90 )
91}
92
93set -e
94test_resize sfdisk "$expected_sfdisk"
95test_resize sgdisk "$expected_sgdisk"

Subscribers

People subscribed via source and target branches