Merge lp:~elopio/snappy/resize_test into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Leo Arias
Status: Superseded
Proposed branch: lp:~elopio/snappy/resize_test
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 242 lines (+184/-6)
5 files modified
_integration-tests/data/tpl/control (+1/-1)
_integration-tests/scripts/get_unpartitioned_space (+1/-1)
_integration-tests/scripts/install-test-initramfs (+19/-0)
_integration-tests/scripts/resize-writable-test (+118/-0)
_integration-tests/tests/initramfs_test.go (+45/-4)
To merge this branch: bzr merge lp:~elopio/snappy/resize_test
Reviewer Review Type Date Requested Status
Snappy Developers Pending
Review via email: mp+270715@code.launchpad.net

This proposal has been superseded by a proposal from 2015-09-10.

To post a comment you must log in.
lp:~elopio/snappy/resize_test updated
669. By Leo Arias

Added the remove reboot mark.

670. By Leo Arias

Fixed the expected free size.

671. By Leo Arias

Fixed the expected free size.

672. By Leo Arias

Fixed format.

673. By Leo Arias

Fixed format.

674. By Leo Arias

Merged with prerequisite.

675. By Leo Arias

First remove the original initrd.img.

676. By Leo Arias

For mbr, resize the partition with sfdisk and using sectors.

677. By Leo Arias

Added comments.

678. By Leo Arias

Added setup and teardown.

679. By Leo Arias

Merged with trunk.

680. By Leo Arias

Fixed the name of the initrd.img

681. By Leo Arias

Fixed the call to ExecCommand.

682. By Leo Arias

Fixed set up and tear down.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_integration-tests/data/tpl/control'
2--- _integration-tests/data/tpl/control 2015-07-22 16:36:14 +0000
3+++ _integration-tests/data/tpl/control 2015-09-10 17:31:29 +0000
4@@ -1,4 +1,4 @@
5 {{ $filter := .Filter }}
6 {{ $test := .Test }}
7-Test-Command: ./_integration-tests/reboot-wrapper {{ $test }} {{ if $filter }}-gocheck.f {{ $filter }}{{ end }}
8+Test-Command: ./_integration-tests/scripts/reboot-wrapper {{ $test }} {{ if $filter }}-gocheck.f {{ $filter }}{{ end }}
9 Restrictions: allow-stderr
10
11=== added directory '_integration-tests/scripts'
12=== renamed file '_integration-tests/tests/get_unpartitioned_space' => '_integration-tests/scripts/get_unpartitioned_space'
13--- _integration-tests/tests/get_unpartitioned_space 2015-09-04 06:05:56 +0000
14+++ _integration-tests/scripts/get_unpartitioned_space 2015-09-10 17:31:29 +0000
15@@ -5,4 +5,4 @@
16 writable_part="$(findfs LABEL=writable)"
17 syspath="$(dirname $(realpath /sys/class/block/$(basename $writable_part)))"
18 device="$(realpath /dev/block/$(cat $syspath/dev))"
19-sudo parted $device unit % print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
20+sudo parted -s $device unit % print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
21
22=== added file '_integration-tests/scripts/install-test-initramfs'
23--- _integration-tests/scripts/install-test-initramfs 1970-01-01 00:00:00 +0000
24+++ _integration-tests/scripts/install-test-initramfs 2015-09-10 17:31:29 +0000
25@@ -0,0 +1,19 @@
26+#! /bin/sh -e
27+# Prepare the initramfs image for the tests.
28+
29+current_boot_dir=$1
30+writable_percent=$2
31+tree_dir=$(pwd)
32+initrd_unpack_dir=$ADT_ARTIFACTS/initrd
33+
34+cp ${current_boot_dir}/initrd.img /tmp/initrd.xz
35+cd /tmp/
36+unxz /tmp/initrd.xz
37+mkdir $initrd_unpack_dir || true
38+cd $initrd_unpack_dir
39+cpio -id < /tmp/initrd
40+cp $tree_dir/_integration-tests/scripts/resize-writable-test scripts/local-premount/
41+sed -i "s/writable_percent=.*/writable_percent=${writable_percent}/" scripts/local-premount/resize-writable-test
42+sed -i '1i /scripts/local-premount/resize-writable-test "$@"\n[ -e /conf/param.conf ] && . /conf/param.conf' scripts/local-premount/ORDER
43+find .|cpio -o -H newc|xz -c -7 --check=crc32 > initrd.img
44+sudo mv initrd.img $current_boot_dir
45
46=== renamed file '_integration-tests/reboot-wrapper' => '_integration-tests/scripts/reboot-wrapper'
47=== added file '_integration-tests/scripts/resize-writable-test'
48--- _integration-tests/scripts/resize-writable-test 1970-01-01 00:00:00 +0000
49+++ _integration-tests/scripts/resize-writable-test 2015-09-10 17:31:29 +0000
50@@ -0,0 +1,118 @@
51+#! /bin/sh -e
52+# initramfs local-premount script to resize writable for testing
53+
54+PREREQ=""
55+
56+# Output pre-requisites
57+prereqs()
58+{
59+ echo "$PREREQ"
60+}
61+
62+case "$1" in
63+ prereqs)
64+ prereqs
65+ exit 0
66+ ;;
67+esac
68+
69+TMPFILE="/run/initramfs/old-table-test.txt"
70+LOGFILE="/run/initramfs/resize-writable-test.log"
71+
72+writable_percent=100
73+
74+wait-for-root "LABEL=writable" "${ROOTDELAY:-180}" >/dev/null || true
75+
76+writable_part="$(findfs LABEL=writable)"
77+
78+syspath="$(dirname $(realpath /sys/class/block/$(basename $writable_part)))"
79+device="$(realpath /dev/block/$(cat $syspath/dev))"
80+partition=$(cat $syspath/$(basename $writable_part)/partition)
81+
82+device_size="$(($(cat $syspath/size)/2))"
83+
84+get_end()
85+{
86+ NUM=$1
87+ lastpart="$(grep -cE ^'[0-9]{1,}': $TMPFILE)"
88+ if [ "$lastpart" = "$NUM" ]; then
89+ endsize="$(parted -ms $DEV unit B print| grep ^/ | cut -d: -f2|sed 's/B$//')"
90+ else
91+ # we are not at the end ! get the start of the next partition
92+ # (minus 1 byte) instead of using the absolute end of the disk
93+ endsize=$(($(parted -ms $DEV unit B print|grep ^$(($num+1)):|\
94+ cut -d: -f2|sed 's/B$//')-1))
95+ fi
96+ echo "endsize: ${endsize}" >/dev/kmsg || true
97+ endsize_percent=$(($endsize*$writable_percent/100))
98+ echo "endsize percent: ${endsize_percent}" >/dev/kmsg || true
99+ echo "$endsize_percent"B
100+}
101+
102+do_gpt()
103+{
104+ DEV=$1
105+ # create new empty GPT
106+ parted -s $DEV mklabel gpt
107+ oIFS=$IFS
108+ IFS=:
109+ # re-create all partitions from backup table
110+ grep -E ^'[0-9]{1,}': $TMPFILE|while read -r num start end size type name flags; do
111+ if [ "$name" = "writable" ]; then
112+ endsize=$(get_end $num)
113+ parted -s $DEV mkpart \"$name\" \"$type\" $start $endsize
114+ else
115+ flags="$(echo $flags|sed -e 's/[,;]//g' -e 's/ /:/')"
116+ parted -s $DEV mkpart \"$name\" \"$type\" $start $end
117+ if [ -n "$flags" ]; then
118+ for flag in ${flags}; do
119+ parted -s $DEV set $num $flag on
120+ done
121+ fi
122+ fi
123+ done
124+ IFS=$oIFS
125+ parted -ms $DEV unit B print >/run/initramfs/new-gpt-table.txt 2>/dev/null
126+}
127+
128+do_mbr()
129+{
130+ DEV=$1
131+ PART=$2
132+ endsize=$(get_end $PART)
133+ parted -s $DEV resizepart $PART $endsize
134+}
135+
136+
137+echo "initrd: resize ${writable_part} to ${writable_percent}% of the disk" >/dev/kmsg || true
138+echo "initrd: see ${LOGFILE} for details" >/dev/kmsg || true
139+
140+# check the filesystem before attempting re-size
141+e2fsck -fy $writable_part >>$LOGFILE 2>&1
142+# shrink the filesystem to the minimum
143+resize2fs -M $writable_part >>$LOGFILE 2>&1
144+
145+# back up the original partition table for later use or debugging
146+parted -ms $device unit B print >$TMPFILE 2>/dev/null
147+table="$(parted -ms $device print| grep ^/| cut -d: -f6)"
148+case $table in
149+ gpt)
150+ # do_gpt needs the device name
151+ do_gpt $device >>$LOGFILE 2>&1
152+ ;;
153+ mbr|msdos)
154+ # do_mbr needs the device node and partition number
155+ do_mbr $device $partition >>$LOGFILE 2>&1
156+ resizeopts="-f"
157+ ;;
158+ *)
159+ echo "unknown partition table type, not resizing" >>$LOGFILE
160+ exit 0
161+ ;;
162+esac
163+# make sure we re read the partition table in any case
164+blockdev --rereadpt $device >>$LOGFILE 2>&1
165+# check the filesystem before attempting re-size
166+e2fsck -fy $writable_part >>$LOGFILE 2>&1
167+# resize the filesystem to full size of the partition
168+resize2fs $resizeopts $writable_part >>$LOGFILE 2>&1
169
170=== modified file '_integration-tests/tests/initramfs_test.go'
171--- _integration-tests/tests/initramfs_test.go 2015-09-04 13:48:32 +0000
172+++ _integration-tests/tests/initramfs_test.go 2015-09-10 17:31:29 +0000
173@@ -21,10 +21,12 @@
174
175 import (
176 "os/exec"
177+ "path"
178 "strconv"
179 "strings"
180
181 "launchpad.net/snappy/_integration-tests/testutils/common"
182+ "launchpad.net/snappy/_integration-tests/testutils/partition"
183
184 "gopkg.in/check.v1"
185 )
186@@ -35,13 +37,52 @@
187 common.SnappySuite
188 }
189
190-func (s *initRAMFSSuite) TestFreeSpace(c *check.C) {
191- cmd := exec.Command("sh", "_integration-tests/tests/get_unpartitioned_space")
192+func getFreeSpacePercent(c *check.C) float64 {
193+ cmd := exec.Command("sh", "_integration-tests/scripts/get_unpartitioned_space")
194 free, err := cmd.Output()
195+ c.Assert(err, check.IsNil, check.Commentf("Error running the script to get the free space: %s", err))
196 freePercent := strings.TrimRight(strings.TrimSpace(string(free)), "%")
197 freePercentFloat, err := strconv.ParseFloat(freePercent, 32)
198 c.Assert(err, check.IsNil,
199 check.Commentf("Error converting the free space percentage to float: %s", err))
200- c.Assert(freePercentFloat < 10, check.Equals, true,
201- check.Commentf("The free space at the end of the disk is greater than 10%"))
202+ return freePercentFloat
203+}
204+
205+func getCurrentBootDir(c *check.C) string {
206+ system, err := partition.BootSystem()
207+ c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
208+ bootDir := partition.BootDir(system)
209+ current, err := partition.CurrentPartition()
210+ c.Assert(err, check.IsNil, check.Commentf("Error getting the current partition: %s", err))
211+ return path.Join(bootDir, current)
212+}
213+
214+func (s *initRAMFSSuite) TestFreeSpaceWithoutResize(c *check.C) {
215+ writablePercent := "95"
216+ if common.BeforeReboot() {
217+ bootDir := getCurrentBootDir(c)
218+ common.ExecCommand(
219+ c, "sh", "-x", "_integration-tests/scripts/install-test-initramfs", bootDir, writablePercent)
220+ common.Reboot(c)
221+ } else if common.AfterReboot(c) {
222+ common.RemoveRebootMark(c)
223+ freeSpace := getFreeSpacePercent(c)
224+ c.Assert(freeSpace, check.Equals, writablePercent,
225+ check.Commentf("The writable partition was resized"))
226+ }
227+}
228+
229+func (s *initRAMFSSuite) TestFreeSpaceWithResize(c *check.C) {
230+ if common.BeforeReboot() {
231+ bootDir := getCurrentBootDir(c)
232+ writablePercent := "85"
233+ common.ExecCommand(
234+ c, "sh", "-x", "_integration-tests/scripts/install-test-initramfs", bootDir, writablePercent)
235+ common.Reboot(c)
236+ } else if common.AfterReboot(c) {
237+ common.RemoveRebootMark(c)
238+ freeSpace := getFreeSpacePercent(c)
239+ c.Assert(freeSpace < 10, check.Equals, true,
240+ check.Commentf("The writable partition was not resized"))
241+ }
242 }

Subscribers

People subscribed via source and target branches