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
=== modified file '_integration-tests/data/tpl/control'
--- _integration-tests/data/tpl/control 2015-07-22 16:36:14 +0000
+++ _integration-tests/data/tpl/control 2015-09-10 17:31:29 +0000
@@ -1,4 +1,4 @@
1{{ $filter := .Filter }}1{{ $filter := .Filter }}
2{{ $test := .Test }}2{{ $test := .Test }}
3Test-Command: ./_integration-tests/reboot-wrapper {{ $test }} {{ if $filter }}-gocheck.f {{ $filter }}{{ end }}3Test-Command: ./_integration-tests/scripts/reboot-wrapper {{ $test }} {{ if $filter }}-gocheck.f {{ $filter }}{{ end }}
4Restrictions: allow-stderr4Restrictions: allow-stderr
55
=== added directory '_integration-tests/scripts'
=== renamed file '_integration-tests/tests/get_unpartitioned_space' => '_integration-tests/scripts/get_unpartitioned_space'
--- _integration-tests/tests/get_unpartitioned_space 2015-09-04 06:05:56 +0000
+++ _integration-tests/scripts/get_unpartitioned_space 2015-09-10 17:31:29 +0000
@@ -5,4 +5,4 @@
5writable_part="$(findfs LABEL=writable)"5writable_part="$(findfs LABEL=writable)"
6syspath="$(dirname $(realpath /sys/class/block/$(basename $writable_part)))"6syspath="$(dirname $(realpath /sys/class/block/$(basename $writable_part)))"
7device="$(realpath /dev/block/$(cat $syspath/dev))"7device="$(realpath /dev/block/$(cat $syspath/dev))"
8sudo parted $device unit % print free | grep 'Free Space' | tail -n1 | awk '{print $3}'8sudo parted -s $device unit % print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
99
=== added file '_integration-tests/scripts/install-test-initramfs'
--- _integration-tests/scripts/install-test-initramfs 1970-01-01 00:00:00 +0000
+++ _integration-tests/scripts/install-test-initramfs 2015-09-10 17:31:29 +0000
@@ -0,0 +1,19 @@
1#! /bin/sh -e
2# Prepare the initramfs image for the tests.
3
4current_boot_dir=$1
5writable_percent=$2
6tree_dir=$(pwd)
7initrd_unpack_dir=$ADT_ARTIFACTS/initrd
8
9cp ${current_boot_dir}/initrd.img /tmp/initrd.xz
10cd /tmp/
11unxz /tmp/initrd.xz
12mkdir $initrd_unpack_dir || true
13cd $initrd_unpack_dir
14cpio -id < /tmp/initrd
15cp $tree_dir/_integration-tests/scripts/resize-writable-test scripts/local-premount/
16sed -i "s/writable_percent=.*/writable_percent=${writable_percent}/" scripts/local-premount/resize-writable-test
17sed -i '1i /scripts/local-premount/resize-writable-test "$@"\n[ -e /conf/param.conf ] && . /conf/param.conf' scripts/local-premount/ORDER
18find .|cpio -o -H newc|xz -c -7 --check=crc32 > initrd.img
19sudo mv initrd.img $current_boot_dir
020
=== renamed file '_integration-tests/reboot-wrapper' => '_integration-tests/scripts/reboot-wrapper'
=== added file '_integration-tests/scripts/resize-writable-test'
--- _integration-tests/scripts/resize-writable-test 1970-01-01 00:00:00 +0000
+++ _integration-tests/scripts/resize-writable-test 2015-09-10 17:31:29 +0000
@@ -0,0 +1,118 @@
1#! /bin/sh -e
2# initramfs local-premount script to resize writable for testing
3
4PREREQ=""
5
6# Output pre-requisites
7prereqs()
8{
9 echo "$PREREQ"
10}
11
12case "$1" in
13 prereqs)
14 prereqs
15 exit 0
16 ;;
17esac
18
19TMPFILE="/run/initramfs/old-table-test.txt"
20LOGFILE="/run/initramfs/resize-writable-test.log"
21
22writable_percent=100
23
24wait-for-root "LABEL=writable" "${ROOTDELAY:-180}" >/dev/null || true
25
26writable_part="$(findfs LABEL=writable)"
27
28syspath="$(dirname $(realpath /sys/class/block/$(basename $writable_part)))"
29device="$(realpath /dev/block/$(cat $syspath/dev))"
30partition=$(cat $syspath/$(basename $writable_part)/partition)
31
32device_size="$(($(cat $syspath/size)/2))"
33
34get_end()
35{
36 NUM=$1
37 lastpart="$(grep -cE ^'[0-9]{1,}': $TMPFILE)"
38 if [ "$lastpart" = "$NUM" ]; then
39 endsize="$(parted -ms $DEV unit B print| grep ^/ | cut -d: -f2|sed 's/B$//')"
40 else
41 # we are not at the end ! get the start of the next partition
42 # (minus 1 byte) instead of using the absolute end of the disk
43 endsize=$(($(parted -ms $DEV unit B print|grep ^$(($num+1)):|\
44 cut -d: -f2|sed 's/B$//')-1))
45 fi
46 echo "endsize: ${endsize}" >/dev/kmsg || true
47 endsize_percent=$(($endsize*$writable_percent/100))
48 echo "endsize percent: ${endsize_percent}" >/dev/kmsg || true
49 echo "$endsize_percent"B
50}
51
52do_gpt()
53{
54 DEV=$1
55 # create new empty GPT
56 parted -s $DEV mklabel gpt
57 oIFS=$IFS
58 IFS=:
59 # re-create all partitions from backup table
60 grep -E ^'[0-9]{1,}': $TMPFILE|while read -r num start end size type name flags; do
61 if [ "$name" = "writable" ]; then
62 endsize=$(get_end $num)
63 parted -s $DEV mkpart \"$name\" \"$type\" $start $endsize
64 else
65 flags="$(echo $flags|sed -e 's/[,;]//g' -e 's/ /:/')"
66 parted -s $DEV mkpart \"$name\" \"$type\" $start $end
67 if [ -n "$flags" ]; then
68 for flag in ${flags}; do
69 parted -s $DEV set $num $flag on
70 done
71 fi
72 fi
73 done
74 IFS=$oIFS
75 parted -ms $DEV unit B print >/run/initramfs/new-gpt-table.txt 2>/dev/null
76}
77
78do_mbr()
79{
80 DEV=$1
81 PART=$2
82 endsize=$(get_end $PART)
83 parted -s $DEV resizepart $PART $endsize
84}
85
86
87echo "initrd: resize ${writable_part} to ${writable_percent}% of the disk" >/dev/kmsg || true
88echo "initrd: see ${LOGFILE} for details" >/dev/kmsg || true
89
90# check the filesystem before attempting re-size
91e2fsck -fy $writable_part >>$LOGFILE 2>&1
92# shrink the filesystem to the minimum
93resize2fs -M $writable_part >>$LOGFILE 2>&1
94
95# back up the original partition table for later use or debugging
96parted -ms $device unit B print >$TMPFILE 2>/dev/null
97table="$(parted -ms $device print| grep ^/| cut -d: -f6)"
98case $table in
99 gpt)
100 # do_gpt needs the device name
101 do_gpt $device >>$LOGFILE 2>&1
102 ;;
103 mbr|msdos)
104 # do_mbr needs the device node and partition number
105 do_mbr $device $partition >>$LOGFILE 2>&1
106 resizeopts="-f"
107 ;;
108 *)
109 echo "unknown partition table type, not resizing" >>$LOGFILE
110 exit 0
111 ;;
112esac
113# make sure we re read the partition table in any case
114blockdev --rereadpt $device >>$LOGFILE 2>&1
115# check the filesystem before attempting re-size
116e2fsck -fy $writable_part >>$LOGFILE 2>&1
117# resize the filesystem to full size of the partition
118resize2fs $resizeopts $writable_part >>$LOGFILE 2>&1
0119
=== modified file '_integration-tests/tests/initramfs_test.go'
--- _integration-tests/tests/initramfs_test.go 2015-09-04 13:48:32 +0000
+++ _integration-tests/tests/initramfs_test.go 2015-09-10 17:31:29 +0000
@@ -21,10 +21,12 @@
2121
22import (22import (
23 "os/exec"23 "os/exec"
24 "path"
24 "strconv"25 "strconv"
25 "strings"26 "strings"
2627
27 "launchpad.net/snappy/_integration-tests/testutils/common"28 "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/partition"
2830
29 "gopkg.in/check.v1"31 "gopkg.in/check.v1"
30)32)
@@ -35,13 +37,52 @@
35 common.SnappySuite37 common.SnappySuite
36}38}
3739
38func (s *initRAMFSSuite) TestFreeSpace(c *check.C) {40func getFreeSpacePercent(c *check.C) float64 {
39 cmd := exec.Command("sh", "_integration-tests/tests/get_unpartitioned_space")41 cmd := exec.Command("sh", "_integration-tests/scripts/get_unpartitioned_space")
40 free, err := cmd.Output()42 free, err := cmd.Output()
43 c.Assert(err, check.IsNil, check.Commentf("Error running the script to get the free space: %s", err))
41 freePercent := strings.TrimRight(strings.TrimSpace(string(free)), "%")44 freePercent := strings.TrimRight(strings.TrimSpace(string(free)), "%")
42 freePercentFloat, err := strconv.ParseFloat(freePercent, 32)45 freePercentFloat, err := strconv.ParseFloat(freePercent, 32)
43 c.Assert(err, check.IsNil,46 c.Assert(err, check.IsNil,
44 check.Commentf("Error converting the free space percentage to float: %s", err))47 check.Commentf("Error converting the free space percentage to float: %s", err))
45 c.Assert(freePercentFloat < 10, check.Equals, true,48 return freePercentFloat
46 check.Commentf("The free space at the end of the disk is greater than 10%"))49}
50
51func getCurrentBootDir(c *check.C) string {
52 system, err := partition.BootSystem()
53 c.Assert(err, check.IsNil, check.Commentf("Error getting the boot system: %s", err))
54 bootDir := partition.BootDir(system)
55 current, err := partition.CurrentPartition()
56 c.Assert(err, check.IsNil, check.Commentf("Error getting the current partition: %s", err))
57 return path.Join(bootDir, current)
58}
59
60func (s *initRAMFSSuite) TestFreeSpaceWithoutResize(c *check.C) {
61 writablePercent := "95"
62 if common.BeforeReboot() {
63 bootDir := getCurrentBootDir(c)
64 common.ExecCommand(
65 c, "sh", "-x", "_integration-tests/scripts/install-test-initramfs", bootDir, writablePercent)
66 common.Reboot(c)
67 } else if common.AfterReboot(c) {
68 common.RemoveRebootMark(c)
69 freeSpace := getFreeSpacePercent(c)
70 c.Assert(freeSpace, check.Equals, writablePercent,
71 check.Commentf("The writable partition was resized"))
72 }
73}
74
75func (s *initRAMFSSuite) TestFreeSpaceWithResize(c *check.C) {
76 if common.BeforeReboot() {
77 bootDir := getCurrentBootDir(c)
78 writablePercent := "85"
79 common.ExecCommand(
80 c, "sh", "-x", "_integration-tests/scripts/install-test-initramfs", bootDir, writablePercent)
81 common.Reboot(c)
82 } else if common.AfterReboot(c) {
83 common.RemoveRebootMark(c)
84 freeSpace := getFreeSpacePercent(c)
85 c.Assert(freeSpace < 10, check.Equals, true,
86 check.Commentf("The writable partition was not resized"))
87 }
47}88}

Subscribers

People subscribed via source and target branches