From f1119b02a62d837c606bf3fd18a8a7b20180d958 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 19 Jan 2022 09:54:59 +0100 Subject: [PATCH] Add --use-fuse switch to kvm-test --install so it can run as non-root Passing --use-fuse to scripts/kvm-test.py allows to run as non-root. It requires installation of the package fuseiso so the switch is disabled by default. Signed-off-by: Olivier Gayot --- scripts/kvm-test.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/kvm-test.py b/scripts/kvm-test.py index 0c3ee4a7..f82fec07 100755 --- a/scripts/kvm-test.py +++ b/scripts/kvm-test.py @@ -174,6 +174,8 @@ parser.add_argument('--install', default=False, action='store_true', iso, use a base iso, or reuse previous test iso''') parser.add_argument('--boot', default=False, action='store_true', help='boot test image') +parser.add_argument('--use-fuse', default=False, action='store_true', + help="use FUSE to mount ISO (doesn't require root)") def parse_args(): @@ -229,12 +231,23 @@ def noop(path): @contextlib.contextmanager -def mounter(src, dest): - run(f'sudo mount -r {src} {dest}') +def mounter(src, dest, use_fuse: bool = False): + commands_with_fuse = ( + ["fuseiso", src, dest], + ["fusermount", "-u", dest], + ) + commands_without_fuse = ( + f'sudo mount -r {src} {dest}', + f'sudo umount {dest}', + ) + + mount, unmount = commands_with_fuse if use_fuse else commands_without_fuse + + run(mount) try: yield finally: - run(f'sudo umount {dest}') + run(unmount) def livefs_edit(ctx, *args): @@ -426,7 +439,7 @@ def install(ctx): run(f'qemu-img create -f qcow2 {ctx.target} {ctx.args.disksize}') if len(appends) > 0: - with mounter(iso, mntdir): + with mounter(iso, mntdir, ctx.args.use_fuse): # if we're passing kernel args, we need to manually specify # kernel / initrd kvm.extend(('-kernel', f'{mntdir}/casper/vmlinuz'))