Skip to content

Commit

Permalink
[export_appliance] fix bogus case: guestumount even if tar failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
npf committed Sep 22, 2016
1 parent 0d6ff57 commit ced7a1d
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions steps/data/helpers/export_appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ def tar_convert(disk, output, excludes, compression_level):
elif output.endswith(('tar.lzo', 'tzo')):
compr = "| %s %s -c -" % (which("lzop"), compression_level_opt)

tar_options_str = ' '.join(tar_options + ['--exclude="%s"' % s for s in excludes])
directory = dir_path = os.path.dirname(os.path.realpath(disk))
cmds = [
which("mkdir") + " %s/.mnt" % directory,
which("guestmount") + " --ro -i -a %s %s/.mnt" % (disk, directory),
which("tar") + " -c %s -C %s/.mnt . %s > %s" % (tar_options, directory, compr, output),
which("guestunmount") + " %s/.mnt" % directory,
which("rmdir") + " %s/.mnt" % directory
]
cmd = " && ".join(cmds)
# NB: guestfish version >= 1.32 supports the special tar options, but not available in Debian stable (jessie): do not use for now
#tar_options_list = ["selinux:true", "acls:true", "xattrs:true",
# "numericowner:true",
Expand All @@ -82,11 +72,37 @@ def tar_convert(disk, output, excludes, compression_level):
#cmd = which("guestfish") + \
# " --ro -i tar-out -a %s / - %s %s > %s"
#cmd = cmd % (disk, tar_options_str, compr, output)
#proc = subprocess.Popen(cmd_mount_tar, env=os.environ.copy(), shell=True)
#proc.communicate()
#if proc.returncode:
# raise subprocess.CalledProcessError(proc.returncode, cmd)

tar_options_str = ' '.join(tar_options + ['--exclude="%s"' % s for s in excludes])
directory = dir_path = os.path.dirname(os.path.realpath(disk))
cmds = [
which("mkdir") + " %s/.mnt" % directory,
which("guestmount") + " --ro -i -a %s %s/.mnt" % (disk, directory),
which("tar") + " -c %s -C %s/.mnt . %s > %s" % (tar_options_str, directory, compr, output)
]
cmd_mount_tar = " && ".join(cmds)
proc = subprocess.Popen(cmd_mount_tar, env=os.environ.copy(), shell=True)
proc.communicate()
returncode_mount_tar = proc.returncode

proc = subprocess.Popen(cmd, env=os.environ.copy(), shell=True)
# try to umount even if the previous command failed
cmds = [
which("guestunmount") + " %s/.mnt" % directory,
which("rmdir") + " %s/.mnt" % directory
]
cmd_umount = " && ".join(cmds)
proc = subprocess.Popen(cmd_umount, env=os.environ.copy(), shell=True)
proc.communicate()
if proc.returncode:
raise subprocess.CalledProcessError(proc.returncode, cmd)
returncode_umount = proc.returncode

if returncode_mount_tar:
raise subprocess.CalledProcessError(returncode_mount_tar, cmd_mount_tar)
elif returncode_umount:
raise subprocess.CalledProcessError(returncode_umount, cmd_umount)


def qemu_convert(disk, output_fmt, output_filename):
Expand Down

0 comments on commit ced7a1d

Please sign in to comment.