summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Williams <codehelp@debian.org>2016-07-17 16:42:20 +0100
committerNeil Williams <codehelp@debian.org>2016-07-17 16:42:20 +0100
commit1e2e196ee9d07c53a039f72994ab70dd562b0a91 (patch)
treed4a1e8da0340224aed3724e447a1266ce959cf16
parent88d8b498b9fa2fe99d86612454eea20533744dc6 (diff)
downloadvmdebootstrap-1e2e196ee9d07c53a039f72994ab70dd562b0a91.tar.gz
Handle conversion to qcow2 after umounting
Add unit test support for checking the file format.
-rwxr-xr-xbin/vmdebootstrap28
-rw-r--r--yarns/300-slow-build-tests.yarn7
-rw-r--r--yarns/900-implements.yarn7
3 files changed, 32 insertions, 10 deletions
diff --git a/bin/vmdebootstrap b/bin/vmdebootstrap
index b958b9d..38d647c 100755
--- a/bin/vmdebootstrap
+++ b/bin/vmdebootstrap
@@ -313,8 +313,9 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
base.create_tarball(rootdir)
elif self.settings['squash']:
filesystem.squash_rootfs()
- filesystem.chown()
+ self.umount()
filesystem.convert_image_to_qcow2()
+ filesystem.chown()
except BaseException as e:
base.message('EEEK! Something bad happened...')
@@ -350,6 +351,21 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
logging.debug('mounted %s on %s', device, mount_point)
return mount_point
+ def umount(self):
+ if not self.settings['image']:
+ return
+ # Umount in the reverse mount order
+ for i in range(len(self.mount_points) - 1, -1, -1):
+ mount_point = self.mount_points[i]
+ try:
+ runcmd(['umount', mount_point], ignore_fail=False)
+ except cliapp.AppException:
+ logging.debug("umount failed, sleeping and trying again")
+ time.sleep(5)
+ runcmd(['umount', mount_point], ignore_fail=False)
+ else:
+ self.mount_points.remove(i)
+
def partition_image(self):
"""
Uses fat16 (msdos) partitioning by default, use part-type to change.
@@ -516,15 +532,7 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
# Umount in the reverse mount order
if self.settings['image']:
- for i in range(len(self.mount_points) - 1, -1, -1):
- mount_point = self.mount_points[i]
- try:
- runcmd(['umount', mount_point], ignore_fail=False)
- except cliapp.AppException:
- logging.debug("umount failed, sleeping and trying again")
- time.sleep(5)
- runcmd(['umount', mount_point], ignore_fail=False)
-
+ self.umount()
runcmd(['kpartx', '-d', self.settings['image']], ignore_fail=True)
for dirname in self.remove_dirs:
diff --git a/yarns/300-slow-build-tests.yarn b/yarns/300-slow-build-tests.yarn
index b4b0dd3..e42e8d2 100644
--- a/yarns/300-slow-build-tests.yarn
+++ b/yarns/300-slow-build-tests.yarn
@@ -39,6 +39,13 @@ These tests are slow, since building images is slow.
AND partition 1 has an vfat filesystem
AND partition 2 has file /boot/grub/grub.cfg matching ^### BEGIN /etc/grub.d/00_header ###$
+ SCENARIO build a basic Debian 8 qcow image
+ ASSUMING build tests are requested
+ GIVEN user wants to build an image FOO.img that is 2GiB in size
+ WHEN the user runs vmdebootstrap --sparse --extlinux --convert-qcow2
+ THEN the image has the correct size
+ AND image has file format matching qcow2
+
SCENARIO build a Debian 8 image with btrfs and grub
ASSUMING build tests are requested
GIVEN user wants to build an image FOO.img that is 2GiB in size
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index a629dc9..860d649 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -135,3 +135,10 @@ regular expression.
mount -r "$device" "$mp"
trap "umount \"$mp\"; unkpartx_image \"$IMAGE\"" EXIT
grep -P -e "$MATCH_3" "$mp/$MATCH_2"
+
+Check the image output format
+
+ IMPLEMENTS THEN image has file format matching (.+)
+ qemu-img info $IMAGE |
+ grep "file format" |
+ grep $MATCH_1