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 <olivier.gayot@canonical.com>
This commit is contained in:
parent
b312a24468
commit
f1119b02a6
|
@ -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'))
|
||||
|
|
Loading…
Reference in New Issue