From 1e2e196ee9d07c53a039f72994ab70dd562b0a91 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Sun, 17 Jul 2016 16:42:20 +0100 Subject: Handle conversion to qcow2 after umounting Add unit test support for checking the file format. --- bin/vmdebootstrap | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'bin') 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: -- cgit v1.2.1