diff options
author | Neil Williams <codehelp@debian.org> | 2016-07-17 16:42:20 +0100 |
---|---|---|
committer | Neil Williams <codehelp@debian.org> | 2016-07-17 16:42:20 +0100 |
commit | 1e2e196ee9d07c53a039f72994ab70dd562b0a91 (patch) | |
tree | d4a1e8da0340224aed3724e447a1266ce959cf16 /bin | |
parent | 88d8b498b9fa2fe99d86612454eea20533744dc6 (diff) | |
download | vmdebootstrap-1e2e196ee9d07c53a039f72994ab70dd562b0a91.tar.gz |
Handle conversion to qcow2 after umounting
Add unit test support for checking the file format.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/vmdebootstrap | 28 |
1 files changed, 18 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: |