Merge pull request #1159 from dbungert/kvm-test-ctd

kvm-test: proxy, livefs_edit, debug
This commit is contained in:
Dan Bungert 2022-01-13 12:29:58 -07:00 committed by GitHub
commit 79b0c41b65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 10 deletions

View File

@ -40,6 +40,7 @@ iso:
default: edge default: edge
''' '''
def salted_crypt(plaintext_password): def salted_crypt(plaintext_password):
# match subiquity documentation # match subiquity documentation
salt = '$6$exDY1mhS4KUYCE/2' salt = '$6$exDY1mhS4KUYCE/2'
@ -122,6 +123,9 @@ Sample usage:
kvm-test --install -bo -rfocal kvm-test --install -bo -rfocal
boot the focal base iso unmodified and run install manually boot the focal base iso unmodified and run install manually
If DEBOOTSTRAP_PROXY is set, that will be passed to snapcraft to pick up
packages from a cache.
See 'cfg' in script for expected layout of iso files, See 'cfg' in script for expected layout of iso files,
which can be managed with ~/.kvm-test.yaml''') which can be managed with ~/.kvm-test.yaml''')
parser.add_argument('-a', '--autoinstall', default=False, parser.add_argument('-a', '--autoinstall', default=False,
@ -178,6 +182,13 @@ def parse_args():
ctx.args.build = True ctx.args.build = True
if ctx.args.reuse: if ctx.args.reuse:
ctx.args.save = True ctx.args.save = True
ctx.livefs_editor = os.environ.get('LIVEFS_EDITOR')
if not ctx.livefs_editor:
raise Exception('Obtain a copy of livefs-editor and point ' +
'LIVEFS_EDITOR to it\n'
'https://github.com/mwhudson/livefs-editor')
return ctx return ctx
@ -226,7 +237,8 @@ def mounter(src, dest):
def livefs_edit(ctx, *args): def livefs_edit(ctx, *args):
run(['sudo', 'PYTHONPATH=$LIVEFS_EDITOR', 'python3', '-m', 'livefs_edit', livefs_editor = os.environ['LIVEFS_EDITOR']
run(['sudo', f'PYTHONPATH={livefs_editor}', 'python3', '-m', 'livefs_edit',
ctx.baseiso, ctx.iso, *args]) ctx.baseiso, ctx.iso, *args])
@ -234,6 +246,11 @@ def build(ctx):
remove_if_exists(ctx.iso) remove_if_exists(ctx.iso)
project = os.path.basename(os.getcwd()) project = os.path.basename(os.getcwd())
snapargs = '--debug'
http_proxy = os.environ.get('DEBOOTSTRAP_PROXY')
if http_proxy:
snapargs += f' --http-proxy={http_proxy}'
snap_manager = noop if ctx.args.save else delete_later snap_manager = noop if ctx.args.save else delete_later
if project == 'subiquity': if project == 'subiquity':
if ctx.args.quick: if ctx.args.quick:
@ -256,14 +273,14 @@ def build(ctx):
with snap_manager('subiquity_test.snap') as snap: with snap_manager('subiquity_test.snap') as snap:
if not ctx.args.reuse: if not ctx.args.reuse:
run('snapcraft clean --use-lxd') run('snapcraft clean --use-lxd')
run(f'snapcraft snap --use-lxd --output {snap}') run(f'snapcraft snap --use-lxd --output {snap} {snapargs}')
assert_exists(snap) assert_exists(snap)
livefs_edit(ctx, '--add-snap-from-store', 'core20', 'stable', livefs_edit(ctx, '--add-snap-from-store', 'core20', 'stable',
'--inject-snap', snap) '--inject-snap', snap)
elif project == 'ubuntu-desktop-installer': elif project == 'ubuntu-desktop-installer':
with snap_manager('udi_test.snap') as snap: with snap_manager('udi_test.snap') as snap:
run('snapcraft clean --use-lxd') run('snapcraft clean --use-lxd')
run(f'snapcraft snap --use-lxd --output {snap}') run(f'snapcraft snap --use-lxd --output {snap} {snapargs}')
assert_exists(snap) assert_exists(snap)
run(f'sudo ./scripts/inject-snap {ctx.baseiso} {ctx.iso} {snap}') run(f'sudo ./scripts/inject-snap {ctx.baseiso} {ctx.iso} {snap}')
else: else:
@ -301,7 +318,7 @@ def drive(path, format='qcow2'):
if serial: if serial:
kwargs.append(f'serial={serial}') kwargs.append(f'serial={serial}')
return '-drive ' + ','.join(kwargs) return ['-drive', ','.join(kwargs)]
class PortFinder: class PortFinder:
@ -370,7 +387,8 @@ def install(ctx):
if ctx.args.overwrite: if ctx.args.overwrite:
os.remove(ctx.target) os.remove(ctx.target)
else: else:
raise Exception('refusing to overwrite existing image') raise Exception('refusing to overwrite existing image, use the ' +
'-o option to allow overwriting')
with tempfile.TemporaryDirectory() as tempdir: with tempfile.TemporaryDirectory() as tempdir:
mntdir = f'{tempdir}/mnt' mntdir = f'{tempdir}/mnt'
@ -395,13 +413,13 @@ def install(ctx):
if ctx.args.autoinstall or ctx.args.autoinstall_file: if ctx.args.autoinstall or ctx.args.autoinstall_file:
if ctx.args.autoinstall_file: if ctx.args.autoinstall_file:
ctx.cloudconfig = ctx.args.autoinstall_file.read() ctx.cloudconfig = ctx.args.autoinstall_file.read()
kvm.append(drive(create_seed(ctx.cloudconfig, tempdir), 'raw')) kvm.extend(drive(create_seed(ctx.cloudconfig, tempdir), 'raw'))
appends.append('autoinstall') appends.append('autoinstall')
if ctx.args.update: if ctx.args.update:
appends.append('subiquity-channel=' + ctx.args.update) appends.append('subiquity-channel=' + ctx.args.update)
kvm.append(drive(ctx.target)) kvm.extend(drive(ctx.target))
if not os.path.exists(ctx.target) or ctx.args.overwrite: if not os.path.exists(ctx.target) or ctx.args.overwrite:
run(f'qemu-img create -f qcow2 {ctx.target} {ctx.args.disksize}') run(f'qemu-img create -f qcow2 {ctx.target} {ctx.args.disksize}')
@ -424,7 +442,7 @@ def boot(ctx):
target = ctx.args.img target = ctx.args.img
kvm = kvm_common(ctx) kvm = kvm_common(ctx)
kvm.append(target) kvm.extend(drive(target))
run(kvm) run(kvm)