Francesco Romani has uploaded a new change for review. Change subject: mkimage: extract mkfloppy helper ......................................................................
mkimage: extract mkfloppy helper A future patch wants to add a different way to create a floppy image, so we extract the common code into a shared helper. Change-Id: I6f07095e0ddfd0cea5bda59cee9875ff1b7515ba Signed-off-by: Francesco Romani <from...@redhat.com> --- M vdsm/mkimage.py 1 file changed, 21 insertions(+), 14 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/52/56852/1 diff --git a/vdsm/mkimage.py b/vdsm/mkimage.py index a737e1a..8f1ee26 100644 --- a/vdsm/mkimage.py +++ b/vdsm/mkimage.py @@ -94,25 +94,32 @@ return path +def _mkFloppyImage(floppy, volumeName=None): + command = [EXT_MKFS_MSDOS, '-C', floppy, '1440'] + if volumeName is not None: + command.extend(['-n', volumeName]) + rc, out, err = execCmd(command, raw=True) + if rc: + raise OSError(errno.EIO, "could not create floppy file: " + "code %s, out %s\nerr %s" % (rc, out, err)) + + dirname = tempfile.mkdtemp() + m = mount.Mount(floppy, dirname) + m.mount(mntOpts='loop') + try: + yield dirname + # TODO: kill floppy fs image if we get an exception? + finally: + m.umount(force=True, freeloop=True) + shutil.rmtree(dirname) + + def mkFloppyFs(vmId, files, volumeName=None): floppy = dirname = None try: floppy = _getFileName(vmId, files) - command = [EXT_MKFS_MSDOS, '-C', floppy, '1440'] - if volumeName is not None: - command.extend(['-n', volumeName]) - rc, out, err = execCmd(command, raw=True) - if rc: - raise OSError(errno.EIO, "could not create floppy file: " - "code %s, out %s\nerr %s" % (rc, out, err)) - - dirname = tempfile.mkdtemp() - m = mount.Mount(floppy, dirname) - m.mount(mntOpts='loop') - try: + with _mkFloppyImage(floppy, volumeName) as dirname: _decodeFilesIntoDir(files, dirname) - finally: - m.umount(force=True, freeloop=True) finally: _commonCleanFs(dirname, floppy) -- To view, visit https://gerrit.ovirt.org/56852 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6f07095e0ddfd0cea5bda59cee9875ff1b7515ba Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <from...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches