#!/usr/bin/env python3 # # Copyright VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # File: check-qemu-install # Purpose: # This script installs a system on a emulated qemu host to verify # that the iso produced is installable and boots. # after the iso is booted from disk it also tries to execute the # vyos-smoketest script to verify checks there. # # For now it will not fail on failed smoketest but will fail on # install and boot errors. # Arguments: # iso iso image to install # [disk] disk filename to use, if none is provided it # is autogenerated # [--keep] Keep the disk image after completion # [--logfile] name of logfile to save, defaulting to stdout # [--silent] only print on errors # [--debug] print all communication with the device import sys import os import time import argparse import subprocess import random import traceback import logging import re import shutil import json import platform from io import BytesIO from datetime import datetime from glob import glob import tomli import pexpect EXCEPTION = 0 DISK_IMAGE_EXTENSION = '.raw' CI_CONFIG_ARGS = { 'hostname': 'vyos-CLOUD-INIT', 'eth0_ipv4': '192.0.2.1/25', 'eth0_ipv6': '2001:db8::1/64', 'default_nexthop' : '192.0.2.126', 'default_nexthop6' : '2001:db8::ffff', } tpm_folder = '/tmp/vyos_tpm_test' tpm_sock = f'{tpm_folder}/swtpm-sock' qemu_name = 'VyOS-QEMU' test_timeout = 5 *3600 # 5 hours (in seconds) to complete individual testcases op_mode_prompt = r'vyos@vyos:~\$' cfg_mode_prompt = r'vyos@vyos#' default_user = 'vyos' default_password = 'vyos' # getch.py KEY_F2 = chr(27) + chr(91) + chr(49) + chr(50) + chr(126) KEY_F10 = chr(27) + chr(91) + chr(50) + chr(49) + chr(126) KEY_UP = chr(27) + chr(91) + chr(65) KEY_DOWN = chr(27) + chr(91) + chr(66) KEY_SPACE = chr(32) KEY_RETURN = chr(13) KEY_ESC = chr(27) KEY_Y = chr(121) mok_password = '1234' # Map QEMU arch QEMU_CONFIG = { 'amd64': { 'bin' : 'qemu-system-x86_64', 'machine' : 'pc', 'bios' : '/usr/share/OVMF/OVMF_CODE.fd', }, "arm64": { 'bin': 'qemu-system-aarch64', 'machine': 'virt,highmem=on', 'bios': '/usr/share/qemu-efi-aarch64/QEMU_EFI.fd', }, } parser = argparse.ArgumentParser(description='Install and start a test VyOS vm.') parser.add_argument('--iso', help='ISO file to install') parser.add_argument('--disk', help='name of disk image file', nargs='?') parser.add_argument('--keep', help='Do not remove disk-image after installation', action='store_true', default=False) parser.add_argument('--silent', help='Do not show output on stdout unless an error has occurred', action='store_true', default=False) parser.add_argument('--debug', help='Send all debug output to stdout', action='store_true', default=False) parser.add_argument('--logfile', help='Log to file') parser.add_argument('--match', help='Smoketests to run') parser.add_argument('--uefi', help='Boot using UEFI', action='store_true', default=False) parser.add_argument('--vnc', help='Enable VNC', action='store_true', default=False) parser.add_argument('--raid', help='Perform a RAID-1 install', action='store_true', default=False) parser.add_argument('--configd', help='Execute testsuite with config daemon', action='store_true', default=False) parser.add_argument('--no-interfaces', help='Execute testsuite without interface tests to save time', action='store_true', default=False) parser.add_argument('--smoketest', help='Execute script based CLI smoketests', action='store_true', default=False) parser.add_argument('--configtest', help='Execute load/commit config tests', action='store_true', default=False) parser.add_argument('--tpmtest', help='Execute TPM encrypted config tests', action='store_true', default=False) parser.add_argument('--sbtest', help='Execute Secure Boot tests', action='store_true', default=False) parser.add_argument('--sbom', help='Generate SBOM file using syft', action='store_true', default=False) parser.add_argument('--sbom-output-dir', help='Host directory to mount and copy SBOM file into', type=str, default=None) parser.add_argument('--cloud-init', help='Execute cloud-init tests', action='store_true', default=False) parser.add_argument('--qemu-cmd', help='Only generate QEMU launch command', action='store_true', default=False) parser.add_argument('--cpu', help='Set QEMU CPU', type=int, default=2) parser.add_argument('--cpu-type', help='Set QEMU CPU type', type=str, default='host') parser.add_argument('--memory', help='Set QEMU memory', type=int, default=4) parser.add_argument('--vyconf', help='Execute testsuite with vyconfd', action='store_true', default=False) parser.add_argument('--no-vpp', help='Execute testsuite without VPP tests', action='store_true', default=False) parser.add_argument('--huge-page-size', help='Huge page size (e.g., 2M, 1G)', type=str) parser.add_argument('--huge-page-count', help='Number of huge pages to allocate', type=int) parser.add_argument('--isolate-cpus', help='CPU cores to isolate (e.g., 1,3-4', type=str) args = parser.parse_args() if os.geteuid() != 0: exit('You need to have root privileges to run this script.') if args.sbom and not args.sbom_output_dir: args.sbom_output_dir = os.getcwd() if args.sbom_output_dir: os.makedirs(args.sbom_output_dir, exist_ok=True) if args.cloud_init: hostname = CI_CONFIG_ARGS['hostname'] op_mode_prompt = rf'vyos@{hostname}:~\$' cfg_mode_prompt = rf'vyos@{hostname}#' # This is what we requested the build to contain with open('data/defaults.toml', 'rb') as f: vyos_defaults = tomli.load(f) # This is what we got from the build manifest_file = 'build/manifest.json' if os.path.isfile(manifest_file): with open('build/manifest.json', 'rb') as f: manifest = json.load(f) vyos_version = manifest['build_config']['version'] vyos_codename = manifest['build_config']['release_train'] class StreamToLogger(object): """ Fake file-like stream object that redirects writes to a logger instance. """ def __init__(self, logger, log_level=logging.INFO): self.logger = logger self.log_level = log_level self.linebuf = b'' self.ansi_escape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]') def write(self, buf): self.linebuf += buf while b'\n' in self.linebuf: f = self.linebuf.split(b'\n', 1) if len(f) == 2: self.logger.debug(self.ansi_escape.sub('', f[0].decode(errors="replace").rstrip())) self.linebuf = f[1] def flush(self): pass class EarlyExit(Exception): pass def _kvm_exists(): return os.path.exists("/dev/kvm") def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False, vnc_enabled=False, secure_boot=False, transfer_disk=None): uefi = "" uuid = "f48b60b2-e6ad-49ef-9d09-4245d0585e52" accel = ',accel=kvm' if _kvm_exists() else '' if platform.machine() in ['amd64', 'x86_64']: architecture = 'amd64' elif platform.machine() in ['arm64', 'aarch64']: architecture = 'arm64' else: raise ValueError('Unsupported architecture!') qemu_arch_config = QEMU_CONFIG[architecture] qemu_bin = qemu_arch_config['bin'] bios = qemu_arch_config['bios'] cpu_type = args.cpu_type enable_kvm = '-enable-kvm' if _kvm_exists() else '' machine = qemu_arch_config['machine'] vga = '-vga none' vnc = '' if vnc_enabled: vga = '-vga virtio' vnc = '-vnc :0' if enable_uefi: uefi = f'-bios {bios}' name = f'{name}-UEFI' if secure_boot: name = f'{name}-SECURE-BOOT' machine = 'q35,smm=on' uefi = f'-drive "if=pflash,unit=0,format=raw,readonly=on,file={OVMF_CODE}" ' \ f'-drive "if=pflash,unit=1,format=raw,file={OVMF_VARS_TMP}"' # Changing UEFI settings require a display vga = '-vga virtio' cdrom = "" if iso_img: cdrom = f' -drive file={iso_img},format=raw,if=none,media=cdrom,id=drive-cd1,readonly=on' if architecture == 'arm64': cdrom = f' {cdrom} -device scsi-cd,bus=scsi0.0,drive=drive-cd1,id=cd1,bootindex=10' else: cdrom = f' {cdrom} -device ahci,id=achi0 -device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10' # RFC7042 section 2.1.2 MAC addresses used for documentation macbase = '00:00:5E:00:53' # Set QEmu disk image format - this differs if VyOS was installed via smoketest # or we use an already ewxisting image disk_format = 'qcow2' if args.disk.endswith('.qcow2') else 'raw' cmd = f'{qemu_bin} \ -name "{name}" \ -smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \ -cpu {cpu_type} \ -machine {machine}{accel} \ {uefi} \ -m {args.memory}G \ -nographic \ {vga} {vnc}\ -uuid {uuid} \ {enable_kvm} \ -monitor unix:/tmp/qemu-monitor-socket-{disk_img},server,nowait \ -netdev user,id=n0,net=192.0.2.0/24,dhcpstart=192.0.2.101,dns=192.0.2.10 -device virtio-net-pci,netdev=n0,mac={macbase}:00,romfile="",host_mtu=1500 \ -netdev user,id=n1 -device virtio-net-pci,netdev=n1,mac={macbase}:01,romfile="",host_mtu=1500 \ -netdev user,id=n2 -device virtio-net-pci,netdev=n2,mac={macbase}:02,romfile="",host_mtu=1500 \ -netdev user,id=n3 -device virtio-net-pci,netdev=n3,mac={macbase}:03,romfile="",host_mtu=1500 \ -netdev user,id=n4 -device virtio-net-pci,netdev=n4,mac={macbase}:04,romfile="" \ -netdev user,id=n5 -device virtio-net-pci,netdev=n5,mac={macbase}:05,romfile="" \ -netdev user,id=n6 -device virtio-net-pci,netdev=n6,mac={macbase}:06,romfile="" \ -netdev user,id=n7 -device virtio-net-pci,netdev=n7,mac={macbase}:07,romfile="" \ -device virtio-scsi-pci,id=scsi0 \ {cdrom} \ -drive format={disk_format},file={disk_img},if=none,media=disk,id=drive-hd1,readonly=off \ -device scsi-hd,bus=scsi0.0,drive=drive-hd1,id=hd1,bootindex=1' if raid: cmd += f' -drive format={disk_format},file={raid},if=none,media=disk,id=drive-hd2,readonly=off' \ f' -device scsi-hd,bus=scsi0.0,drive=drive-hd2,id=hd2,bootindex=2' if tpm: cmd += f' -chardev socket,id=chrtpm,path={tpm_sock}' \ ' -tpmdev emulator,id=tpm0,chardev=chrtpm' \ ' -device tpm-tis,tpmdev=tpm0' if transfer_disk: cmd += f' -drive format=raw,file={transfer_disk},if=none,media=disk,id=drive-transfer,readonly=off' \ f' -device scsi-hd,bus=scsi0.0,drive=drive-transfer,id=transfer-disk' return cmd def shutdownVM(c, log, message=''): ################################################# # Powering off system ################################################# if message: log.info(message) c.sendline('poweroff now') log.info('Shutting down virtual machine') for i in range(30): log.info('Waiting for shutdown...') # Shutdown in qemu doesnt work first time # Use this workaround # https://vyos.dev/T5024 c.sendline('poweroff now') if not c.isalive(): log.info('VM is shut down!') break time.sleep(10) else: tmp = 'VM Did not shut down after 300sec' log.error(tmp) raise Exception(tmp) c.close() def waitForLogin(child, log, timeout=20) -> None: try: child.expect('The highlighted entry will be executed automatically in', timeout=timeout) child.sendline('') except pexpect.TIMEOUT: log.warning('Did not find GRUB countdown window, ignoring') def loginVM(c, log): log.info('Waiting for login prompt') c.expect('[Ll]ogin:', timeout=600) c.sendline(default_user) c.expect('[Pp]assword:') c.sendline(default_password) c.expect(op_mode_prompt) log.info('Logged in!') def clearTPM(): for f in glob(f'{tpm_folder}/*'): os.remove(f) # Setting up logger log = logging.getLogger() log.setLevel(logging.DEBUG) stl = StreamToLogger(log) formatter = logging.Formatter('%(levelname)5s - %(message)s') handler = logging.StreamHandler(sys.stdout) if args.silent: handler.setLevel(logging.ERROR) elif args.debug: handler.setLevel(logging.DEBUG) else: handler.setLevel(logging.INFO) handler.setFormatter(formatter) log.addHandler(handler) if args.logfile: filehandler = logging.FileHandler(args.logfile) filehandler.setLevel(logging.DEBUG) filehandler.setFormatter(formatter) log.addHandler(filehandler) if args.silent: output = BytesIO() else: output = sys.stdout.buffer if not os.path.exists('/dev/kvm'): log.error('KVM not enabled on host, proceeding with software emulation') if not args.iso and not args.disk: log.error('Neither ISO not QCOW2 disk image supplied - error!') sys.exit(1) if not args.disk: tmp_disk_time = datetime.now().strftime('%Y%m%d-%H%M%S') tmp_disk_random = "%04x" % random.randint(0,65535) args.disk = f'testinstall-{tmp_disk_time}-{tmp_disk_random}{DISK_IMAGE_EXTENSION}' if not args.iso or not os.path.isfile(args.iso): log.debug('Unable to find ISO image to install ...') OVMF_CODE = '/usr/share/OVMF/OVMF_CODE_4M.secboot.fd' OVMF_VARS_TMP = args.disk.replace(DISK_IMAGE_EXTENSION, '.efivars') if args.sbtest: shutil.copy('/usr/share/OVMF/OVMF_VARS_4M.ms.fd', OVMF_VARS_TMP) # Creating diskimage!! diskname_raid = None def gen_disk(name): if not os.path.isfile(name): log.info(f'Creating Disk image {name}') c = subprocess.check_output(['qemu-img', 'create', name, '2G']) log.debug(c.decode()) else: log.info(f'Re-using already existing disk image "{name}".') if args.raid: filename, ext = os.path.splitext(args.disk) diskname_raid = f'{filename}_disk1{ext}' # change primary diskname, too args.disk = f'{filename}_disk0{ext}' gen_disk(diskname_raid) # must be called after the raid disk as args.disk name is altered in the RAID path gen_disk(args.disk) # Create 512MB transfer disk for SBOM generation if requested, download the syft util to use inside the VM for SBOM generation process. # It will be used to copy generated SBOM files from the VM to the host via the mounted transfer disk. transfer_disk_path = None if args.sbom: _ts = datetime.now().strftime('%Y%m%d-%H%M%S') _rand = '%04x' % random.randint(0, 0xFFFF) transfer_disk_path = f'/tmp/vyos-sbom-transfer-{_ts}-{_rand}.img' subprocess.check_output(['dd', 'if=/dev/zero', f'of={transfer_disk_path}', 'bs=1M', 'count=512']) subprocess.check_output(['mkfs.vfat', '-F', '32', '-n', 'SBOMXFER', transfer_disk_path]) log.info(f'Created SBOM transfer disk: {transfer_disk_path}') setup_mount = f'{transfer_disk_path}.setup' os.makedirs(setup_mount, exist_ok=True) subprocess.check_output(['mount', '-o', 'loop', transfer_disk_path, setup_mount]) try: log.info('Downloading syft to transfer disk') if platform.machine() in ['amd64', 'x86_64']: syft_tar_url = 'https://cdn.vyos.io/tools/syft_1.44.0_linux_amd64.tar.gz' elif platform.machine() in ['arm64', 'aarch64']: syft_tar_url = 'https://cdn.vyos.io/tools/syft_1.44.0_linux_arm64.tar.gz' else: raise ValueError(f'Unsupported architecture for syft download: {platform.machine()}') import tarfile, tempfile with tempfile.TemporaryDirectory() as tar_tmp: tar_path = os.path.join(tar_tmp, 'syft.tar.gz') subprocess.check_call(['curl', '-sSfL', '-o', tar_path, syft_tar_url]) with tarfile.open(tar_path) as tf: with tf.extractfile(tf.getmember('syft')) as src: dest_path = os.path.join(setup_mount, 'syft') with open(dest_path, 'wb') as dst: dst.write(src.read()) os.chmod(os.path.join(setup_mount, 'syft'), 0o755) log.info('Syft downloaded to transfer disk') finally: subprocess.check_output(['umount', setup_mount]) os.rmdir(setup_mount) # Create software emulated TPM - clear existing TPM data first - might be a # leftover from a previous run clearTPM() def start_swtpm(): if not os.path.exists(tpm_folder): os.mkdir(tpm_folder) def swtpm_thread(): subprocess.check_output([ 'swtpm', 'socket', '--tpmstate', f'dir={tpm_folder}', '--ctrl', f'type=unixio,path={tpm_sock}', '--tpm2', '--log', 'level=1' ]) from multiprocessing import Process tpm_process = Process(target=swtpm_thread) tpm_process.start() return tpm_process def toggleUEFISecureBoot(c): def UEFIKeyPress(c, key): UEFI_SLEEP = 1 c.send(key) time.sleep(UEFI_SLEEP) # Enter UEFI for ii in range(1, 10): c.send(KEY_F2) time.sleep(0.250) time.sleep(10) # Device Manager UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_RETURN) # Secure Boot Configuration UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_RETURN) # Attempt Secure Boot Toggle UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_RETURN) UEFIKeyPress(c, KEY_RETURN) # Save Secure Boot UEFIKeyPress(c, KEY_F10) UEFIKeyPress(c, KEY_Y) # Go Back to Menu UEFIKeyPress(c, KEY_ESC) UEFIKeyPress(c, KEY_ESC) # Go Down for reset UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_DOWN) UEFIKeyPress(c, KEY_RETURN) def BOOTLOADERchooseSerialConsole(child, live: bool) -> None: """ Select GRUB boot entry that uses the serial console. This differs between a LIVE ISO image and an already installed system. """ BOOTLOADER_TMO = 40 BOOTLOADER_SLEEP = 1.5 BOOTLOADER_LOAD_TMO = 5 # let GRUB screen load UEFI_STRING = r'BdsDxe.*' GRUB_STRING = r'GNU GRUB.*' ISOLINUX_STRING = r'ISOLINUX.*' # XXX: UEFI systems directly load GRUB, BIOS systems fallback to ISOLINUX if live and args.uefi: # Let UEFI start before GRUB child.expect(UEFI_STRING, timeout=BOOTLOADER_TMO) # Wait for GRUB child.expect(GRUB_STRING, timeout=BOOTLOADER_TMO) time.sleep(BOOTLOADER_LOAD_TMO) # Select GRUB serial console # Key DOWN -> fail-safe mode child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) # Key DOWN -> Serial Console boot child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) # Boot child.send(KEY_RETURN) elif live and not args.uefi: # Wait for ISOLINUX child.expect(ISOLINUX_STRING, timeout=BOOTLOADER_TMO) time.sleep(BOOTLOADER_LOAD_TMO) # Boot Menu starts at Live system (vyos) - KVM console child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) # Live system (vyos fail-safe mode) child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) # Live system (vyos) - Serial console - boot it up child.send(KEY_RETURN) else: # Let UEFI start before GRUB if args.uefi: child.expect(UEFI_STRING, timeout=BOOTLOADER_TMO) # Wait for GRUB child.expect(GRUB_STRING, timeout=BOOTLOADER_TMO) time.sleep(BOOTLOADER_LOAD_TMO) # Select GRUB serial console # Boot options child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) child.send(KEY_RETURN) time.sleep(BOOTLOADER_SLEEP) # Select console type child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) child.send(KEY_RETURN) time.sleep(BOOTLOADER_SLEEP) # *ttyS (serial) child.send(KEY_DOWN) time.sleep(BOOTLOADER_SLEEP) child.send(KEY_RETURN) time.sleep(BOOTLOADER_SLEEP) # Boot child.send(KEY_RETURN) return None def basic_cli_tests(c): # Repeating / shared basic CLI test between installed images and the # cloud-init test-case c.sendline('configure') c.expect(cfg_mode_prompt) c.sendline('exit') c.expect(op_mode_prompt) c.sendline('show version') c.expect(op_mode_prompt) c.sendline('show version kernel') c.expect(f'{vyos_defaults["kernel_version"]}-{vyos_defaults["kernel_flavor"]}') c.expect(op_mode_prompt) c.sendline('show version frr') c.expect(op_mode_prompt) c.sendline('show interfaces') c.expect(op_mode_prompt) # c.sendline('systemd-detect-virt') # c.expect('kvm') # c.expect(op_mode_prompt) c.sendline('show system cpu') c.expect(op_mode_prompt) c.sendline('show system memory') c.expect(op_mode_prompt) c.sendline('show system memory detail | no-more') c.expect(op_mode_prompt) c.sendline('show configuration commands | match "option kernel"') c.expect(op_mode_prompt) c.sendline('cat /proc/cmdline') c.expect(op_mode_prompt) c.sendline('show version all | grep -e "vpp" -e "vyos-1x"') c.expect(op_mode_prompt) # Get serial console interface name from flavor definition c.sendline('cat /usr/share/vyos/flavor.json | jq -r ".console_type"') c.expect(op_mode_prompt) lines = [l.strip() for l in c.before.splitlines() if l.strip()] console_type = lines[-1].decode('utf-8').strip() # e.g. ttyS # We do only care for ttyS or ttyAMA console types, exit early # for VGA consoles if console_type == 'tty': return c.sendline('cat /usr/share/vyos/flavor.json | jq -r ".console_num"') c.expect(op_mode_prompt) lines = [l.strip() for l in c.before.splitlines() if l.strip()] console_num = lines[-1].decode('utf-8').strip() # e.g. 0 # Get serial console speed from flavor definition c.sendline('cat /usr/share/vyos/flavor.json | jq -r ".console_speed"') c.expect(op_mode_prompt) lines = [l.strip() for l in c.before.splitlines() if l.strip()] console_speed = lines[-1].decode('utf-8').strip() # e.g. 115200 # Ensure serial console with kernel option is set in CLI, done automatically by image installer c.sendline('show configuration commands | match "system console"') c.expect(rf'set system console device {console_type}{console_num} kernel\r\r\nset system console device {console_type}{console_num} speed \'{console_speed}\'') c.expect(op_mode_prompt) # Validate GRUB has the right console_type defined c.sendline('cat /boot/grub/grub.cfg.d/20-vyos-defaults-autoload.cfg | grep "set console_type"') c.expect(f'set console_type="{console_type}"') c.expect(op_mode_prompt) if args.qemu_cmd: tmp = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, iso_img=args.iso, vnc_enabled=args.vnc, secure_boot=args.sbtest) os.system(tmp) exit(0) if args.cloud_init: # Build cloud-init seed iso CI_ISO = 'ci_seed.iso' CI_DATA_DIR = 'ci_data' # Insert cloud-init ISO into CD-ROM args.iso = CI_ISO if not os.path.exists(CI_DATA_DIR): os.makedirs(CI_DATA_DIR) # create "empty" meta-data file open(f'{CI_DATA_DIR}/meta-data', mode='w').close() network_config = """version: 2 ethernets: eth0: dhcp4: false dhcp6: false """ user_data = """#cloud-config vyos_config_commands: - set system host-name '{hostname}' - set service ntp server 1.pool.ntp.org - set service ntp server 2.pool.ntp.org - delete interfaces ethernet eth0 address 'dhcp' - set interfaces ethernet eth0 address '{eth0_ipv4}' - set interfaces ethernet eth0 address '{eth0_ipv6}' - set protocols static route 0.0.0.0/0 next-hop '{default_nexthop}' - set protocols static route6 ::/0 next-hop '{default_nexthop6}' """.format(**CI_CONFIG_ARGS) with open(f'{CI_DATA_DIR}/network-config', mode='w') as f: f.writelines(network_config) with open(f'{CI_DATA_DIR}/user-data', mode='w') as f: f.writelines(user_data) # Assemble cloud-init ISO file if os.path.exists(CI_ISO): os.unlink(CI_ISO) os.system(f'mkisofs -joliet -rock -volid "cidata" -output {CI_ISO} {CI_DATA_DIR}') tpm_process = None try: # Start TPM emulator if args.tpmtest: tpm_process = start_swtpm() ################################################# # Installing image to disk ################################################# log.info('Installing system') cmd = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, tpm=args.tpmtest, iso_img=args.iso, vnc_enabled=args.vnc, secure_boot=args.sbtest, transfer_disk=transfer_disk_path) log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl, timeout=60) ################################################# # Logging into VyOS system ################################################# if args.sbtest: log.info('Disable UEFI Secure Boot for initial installation') toggleUEFISecureBoot(c) BOOTLOADERchooseSerialConsole(c, live=(not args.cloud_init)) loginVM(c, log) ################################################# # Cloud-Init comes with a pre-assembled ISO - just boot and test it ################################################# if args.cloud_init: log.info('Perform basic CLI configuration mode tests from cloud-init...') basic_cli_tests(c) # Valida assigned IPv4 and IPv6 addresses c.sendline('ip --json addr show dev eth0 | jq -r \'.[0].addr_info[] | select(.family=="inet") | "\(.local)/\(.prefixlen)"\'') c.expect(CI_CONFIG_ARGS['eth0_ipv4']) c.expect(op_mode_prompt) c.sendline('ip --json addr show dev eth0 | jq -r \'.[0].addr_info[] | select(.family=="inet6" and .scope=="global" and (.temporary|not)) | "\(.local)/\(.prefixlen)"\'') c.expect(CI_CONFIG_ARGS['eth0_ipv6']) c.expect(op_mode_prompt) # Valida default route nexthops c.sendline('ip -4 --json route show default | jq -r ".[0].gateway"') c.expect(CI_CONFIG_ARGS['default_nexthop']) c.expect(op_mode_prompt) c.sendline('ip -6 --json route show default | jq -r ".[0].gateway"') c.expect(CI_CONFIG_ARGS['default_nexthop6']) c.expect(op_mode_prompt) shutdownVM(c, log, 'Powering off system') c.close() raise EarlyExit ################################################# # Check for no private key contents within the image ################################################# msg = 'Found private key - bailing out' c.sendline(f'if sudo grep -rq "BEGIN PRIVATE KEY" /var/lib/shim-signed/mok; then echo {msg}; exit 1; fi') tmp = c.expect([f'\n{msg}', op_mode_prompt]) if tmp == 0: log.error(msg) exit(1) ################################################# # Configure boot options if required ################################################# if args.huge_page_size and args.huge_page_count: c.sendline('configure') c.expect(cfg_mode_prompt) c.sendline(f'set system option kernel memory hugepage-size {args.huge_page_size} hugepage-count {args.huge_page_count}') c.expect(cfg_mode_prompt) if args.isolate_cpus: c.sendline(f'set system option kernel cpu isolate-cpus {args.isolate_cpus}') c.expect(cfg_mode_prompt) c.sendline('set system option kernel disable-mitigations') c.expect(cfg_mode_prompt) c.sendline('commit') c.expect(cfg_mode_prompt) c.sendline('save') c.expect(cfg_mode_prompt) c.sendline('exit') c.expect(op_mode_prompt) ################################################# # Installing into VyOS system ################################################# log.info('Starting installer') c.sendline('install image') c.expect('\nWould you like to continue?.*') c.sendline('y') c.expect('\nWhat would you like to name this image?.*') c.sendline('') c.expect(f'\nPlease enter a password for the "{default_user}" user.*') c.sendline('vyos') c.expect(f'\nPlease confirm password for the "{default_user}" user.*') c.sendline('vyos') c.expect('\nWhat console should be used by default?.*') c.sendline('S') if args.raid: c.expect('\nWould you like to configure RAID-1 mirroring??.*') c.sendline('y') c.expect('\nWould you like to configure RAID-1 mirroring on them?.*') c.sendline('y') c.expect('\nInstallation will delete all data on both drives. Continue?.*') c.sendline('y') c.expect('\nWhich file would you like as boot config?.*') c.sendline('') else: c.expect('\nWhich one should be used for installation?.*') c.sendline('') c.expect('\nInstallation will delete all data on the drive. Continue?.*') c.sendline('y') c.expect('\nWould you like to use all the free space on the drive?.*') c.sendline('y') c.expect('\nWhich file would you like as boot config?.*') c.sendline('') c.expect(op_mode_prompt) if args.sbtest: c.sendline('install mok') c.expect('input password:.*') c.sendline(mok_password) c.expect('input password again:.*') c.sendline(mok_password) c.expect(op_mode_prompt) log.info('system installed, rebooting') c.sendline('reboot now') ################################################# # SHIM Mok Manager ################################################# if args.sbtest: log.info('Install Secure Boot Machine Owner Key') MOK_SLEEP = 0.5 c.expect('BdsDxe: starting Boot00.*') time.sleep(3) # press any key c.send(KEY_RETURN) time.sleep(MOK_SLEEP) # Enroll MOK c.send(KEY_DOWN) time.sleep(MOK_SLEEP) c.send(KEY_RETURN) time.sleep(MOK_SLEEP) # Continue c.send(KEY_DOWN) time.sleep(MOK_SLEEP) c.send(KEY_RETURN) time.sleep(MOK_SLEEP) # Enroll Keys c.send(KEY_DOWN) time.sleep(MOK_SLEEP) c.send(KEY_RETURN) time.sleep(MOK_SLEEP) c.sendline(mok_password) c.send(KEY_RETURN) time.sleep(MOK_SLEEP) # Reboot c.send(KEY_RETURN) time.sleep(MOK_SLEEP) ################################################# # Re-Enable Secure Boot ################################################# if args.sbtest: log.info('Enable UEFI Secure Boot for initial installation') toggleUEFISecureBoot(c) ################################################# # Removing CD installation media ################################################# time.sleep(2) log.info('eject installation media') os.system(f'echo "eject -f drive-cd1" | socat - unix-connect:/tmp/qemu-monitor-socket-{args.disk}') ################################################# # Booting installed system ################################################# log.info('Booting installed system') BOOTLOADERchooseSerialConsole(c, live=False) ################################################# # Logging into VyOS system ################################################# waitForLogin(c, log) loginVM(c, log) ################################################# # Boot options require a reboot ################################################# if args.huge_page_size and args.huge_page_count: log.info('Rebooting to apply kernel boot options') c.sendline('reboot now') loginVM(c, log) ################################################ # Always load the WiFi simulation module ################################################ c.sendline('sudo modprobe mac80211_hwsim') c.expect(op_mode_prompt) # Inform smoketest about this environment c.sendline('touch /tmp/vyos.smoketests.hint') c.expect(op_mode_prompt) ################################################# # Start/stop config daemon ################################################# if args.configd: c.sendline('sudo systemctl restart vyos-configd.service &> /dev/null') else: c.sendline('sudo systemctl stop vyos-configd.service &> /dev/null') c.expect(op_mode_prompt) ################################################# # Basic Configmode/Opmode switch ################################################# log.info('Basic CLI configuration mode test') basic_cli_tests(c) ################################################# # Verify /etc/os-release via lsb_release ################################################# c.sendline('lsb_release --short --id 2>/dev/null') c.expect('VyOS') if os.path.isfile(manifest_file): c.sendline('lsb_release --short --release 2>/dev/null') c.expect(vyos_version) c.sendline('lsb_release --short --codename 2>/dev/null') c.expect(vyos_codename) # Ensure ephemeral key is loaded vyos_kernel_key = 'VyOS build time autogenerated kernel key' c.sendline(f'show log kernel | match "{vyos_kernel_key}"') c.expect(f'.*{vyos_kernel_key}.*') c.expect(op_mode_prompt) ################################################# # Executing test-suite ################################################# if args.tpmtest: def verify_mount(): # Verify encrypted and mounted c.sendline('mount | grep vyos_config') c.expect('/dev/mapper/vyos_config on /opt/vyatta/etc/config.*') c.expect(op_mode_prompt) def verify_config(): # Verify encrypted config is loaded c.sendline('show config commands | cat') c.expect('set system option performance \'network-latency\'') c.expect('set system option reboot-on-panic') c.expect(op_mode_prompt) log.info('Running TPM encrypted config tests') tpm_timeout = 600 # Give it 10 mins to encrypt # Verify TPM is loaded c.sendline('find /dev -name tpm0') c.expect('/dev/tpm0') c.expect(op_mode_prompt) # Create recovery key import string from random import choices test_recovery_key = ''.join(choices(string.ascii_uppercase + string.digits, k=32)) log.info('Encrypting config to TPM') c.sendline('encryption enable') c.expect('Automatically generate a recovery key\?.*') c.sendline('n') c.expect('Enter recovery key: ') c.sendline(test_recovery_key) c.expect('Enter size of encrypted config partition.*', timeout=30) c.sendline('32') c.expect('Encrypted config volume has been enabled', timeout=tpm_timeout) c.expect('Backup the recovery key in a safe place!') c.expect(f'Recovery key: {test_recovery_key}') c.expect(op_mode_prompt) verify_mount() # Add some non-default config nodes this encrypted config log.info('Adding nodes for encrypted config test') c.sendline('configure') c.expect(cfg_mode_prompt) c.sendline('set system option performance network-latency') c.expect(cfg_mode_prompt) c.sendline('set system option reboot-on-panic') c.expect(cfg_mode_prompt) c.sendline('commit') c.expect(cfg_mode_prompt) c.sendline('save') c.expect(cfg_mode_prompt) c.sendline('exit') c.expect(op_mode_prompt) log.info('system installed, rebooting') c.sendline('reboot now') waitForLogin(c, log) # Check for vyos-router message c.expect('.*Mounted encrypted config volume', timeout=120) loginVM(c, log) verify_mount() verify_config() # Shutdown VM shutdownVM(c, log, 'Shutdown VM for TPM fail test') # Clear swtpm clearTPM() # Shutdown kills swtpm tpm_process.join() tpm_process.close() # Start emulator again tpm_process = start_swtpm() # Booting back into VM log.info('Booting system with cleared TPM') cmd = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, tpm=args.tpmtest, vnc_enabled=args.vnc) log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) waitForLogin(c, log) c.expect('.*Encrypted config volume has not been mounted', timeout=120) loginVM(c, log) # Test loading config with recovery key c.sendline('encryption load') c.expect('Enter recovery key: ') c.sendline(test_recovery_key) c.expect('Encrypted config volume has been mounted', timeout=120) c.expect(op_mode_prompt) verify_mount() log.info('Loading encrypted config.boot') c.sendline('configure') c.expect(cfg_mode_prompt) c.sendline('load /opt/vyatta/etc/config/config.boot') c.expect(cfg_mode_prompt) c.sendline('commit') c.expect(cfg_mode_prompt) c.sendline('exit') c.expect(op_mode_prompt) verify_config() # Shutdown VM shutdownVM(c, log, 'Shutdown VM for non-TPM backed test') clearTPM() # Shutdown kills swtpm tpm_process.join() tpm_process.close() tpm_process = None # Booting back into VM log.info('Booting system without TPM') cmd = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, tpm=False, vnc_enabled=args.vnc) log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) waitForLogin(c, log) loginVM(c, log) # New recovery key test_recovery_key = ''.join(choices(string.ascii_uppercase + string.digits, k=32)) log.info('Encrypting config') c.sendline('encryption enable') c.expect('Are you sure you want to proceed\?.*') c.sendline('y') c.expect('Enter key: ') c.sendline(test_recovery_key) c.expect('Confirm key:') c.sendline(test_recovery_key) c.expect('Enter size of encrypted config partition.*', timeout=30) c.sendline('32') c.expect('Encrypted config volume has been enabled', timeout=tpm_timeout) c.expect('Backup the key in a safe place!') c.expect(f'Key: {test_recovery_key}') c.expect(op_mode_prompt) verify_mount() shutdownVM(c, log, 'Shutdown VM for non-TPM config load') # Booting back into VM log.info('Booting system without TPM') cmd = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, tpm=False, vnc_enabled=args.vnc) log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) waitForLogin(c, log) c.expect('.*encrypted config volume will not be automatically mounted', timeout=120) loginVM(c, log) # Test loading config with recovery key c.sendline('encryption load') c.expect('Enter key: ') c.sendline(test_recovery_key) c.expect('Encrypted config volume has been mounted', timeout=120) c.expect(op_mode_prompt) verify_mount() log.info('Loading encrypted config.boot') c.sendline('configure') c.expect(cfg_mode_prompt) c.sendline('load /opt/vyatta/etc/config/config.boot') c.expect(cfg_mode_prompt) c.sendline('commit') c.expect(cfg_mode_prompt) c.sendline('exit') c.expect(op_mode_prompt) elif args.raid: # Verify RAID subsystem - by deleting a disk and re-create the array # from scratch c.sendline('cat /proc/mdstat') c.expect(op_mode_prompt) shutdownVM(c, log, f'Shutdown VM and start with empty RAID member "{args.disk}"') if os.path.exists(args.disk): os.unlink(args.disk) gen_disk(args.disk) ################################################# # Booting RAID-1 system with one missing disk ################################################# log.info('Booting RAID-1 system') cmd = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, vnc_enabled=args.vnc) # We need to swap boot indexes to boot from second harddisk so we can # recreate the RAID on the first disk cmd = cmd.replace('bootindex=1', 'bootindex=X') cmd = cmd.replace('bootindex=2', 'bootindex=1') cmd = cmd.replace('bootindex=X', 'bootindex=2') log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) ################################################# # Logging into VyOS system ################################################# waitForLogin(c, log) loginVM(c, log) c.sendline('cat /proc/mdstat') c.expect(op_mode_prompt) log.info('Re-format new RAID member') c.sendline('format by-id disk drive-hd1 like drive-hd2') c.sendline('yes') c.expect(op_mode_prompt) log.info('Add member to RAID1 (md0)') c.sendline('add raid md0 by-id member drive-hd1-part3') c.expect(op_mode_prompt) log.info('Now we need to wait for re-sync to complete') start_time = time.time() timeout = 60 while True: if (start_time + timeout) < time.time(): break c.sendline('cat /proc/mdstat') c.expect(op_mode_prompt) time.sleep(20) # Reboot system with new primary RAID1 disk shutdownVM(c, log, f'Shutdown VM and start from recovered RAID member "{args.disk}"') log.info('Booting RAID-1 system') cmd = get_qemu_cmd(qemu_name, args.uefi, args.disk, raid=diskname_raid, vnc_enabled=args.vnc) log.debug(f'Executing command: {cmd}') c = pexpect.spawn(cmd, logfile=stl) loginVM(c, log) c.sendline('cat /proc/mdstat') c.expect(op_mode_prompt) elif args.smoketest: # run default smoketest suite smoketests_path = '/usr/libexec/vyos/tests/smoke' if args.match: # Remove tests that we don't want to run match_str = '-o '.join([f'-name "test_*{name}*.py" ' for name in args.match.split("|")]).strip() c.sendline(f'sudo find {smoketests_path} -maxdepth 2 -type f -name test_* ! \( {match_str} \) -delete') c.expect(op_mode_prompt) if args.no_interfaces: # remove interface tests as they consume a lot of time c.sendline(f'sudo rm -f {smoketests_path}/cli/test_interfaces_*') c.expect(op_mode_prompt) if args.no_vpp: # remove VPP tests c.sendline(f'sudo rm -f {smoketests_path}/cli/test_vpp*') c.expect(op_mode_prompt) if args.vyconf: c.sendline('sudo /usr/libexec/vyos/set_vyconf_backend.py --no-prompt &> /dev/null') c.expect(op_mode_prompt) log.info('Smoketests will be run using vyconfd/vyos-commitd') log.info('Executing VyOS smoketests') c.sendline('/usr/bin/vyos-smoketest') i = c.expect(['\n +Invalid command:', '\n +Set failed', 'No such file or directory', r'\n\S+@\S+[$#]'], timeout=test_timeout) if i == 0: raise Exception('Invalid command detected') if i == 1: raise Exception('Set syntax failed :/') if i == 2: tmp = '(W)hy (T)he (F)ace? VyOS smoketest not found!' log.error(tmp) raise Exception(tmp) c.sendline('echo EXITCODE:$\x16?') i = c.expect(['EXITCODE:0', 'EXITCODE:\d+']) if i == 0: log.info('Smoketest finished successfully!') pass elif i == 1: log.error('Smoketest failed :/') raise Exception("Smoketest-failed, please look into debug output") # else, run configtest suite elif args.configtest: # Remove config-tests that we don't want to run if args.match: configs_path = '/usr/libexec/vyos/tests/configs' if args.match.startswith("!"): # Exclude mode — delete only the matched names names = args.match[1:].split("|") match_str = '-o '.join([f'-name "{name}"' for name in names]) cleanup_config_dir_cmd = f'sudo find {configs_path} -mindepth 1 -maxdepth 1 -type f \\( {match_str} \\) -exec rm -rf {{}} +' cleanup_config_tests_dir_cmd = f'sudo find {configs_path}/assert -mindepth 1 -maxdepth 1 -type f \\( {match_str} \\) -exec rm -rf {{}} +' else: # Include mode — keep only the matched names, delete the rest names = args.match.split("|") match_str = '-o '.join([f'-name "{name}"' for name in names]) cleanup_config_dir_cmd = f'sudo find {configs_path} -mindepth 1 -maxdepth 1 -type f ! \\( {match_str} \\) -exec rm -rf {{}} +' cleanup_config_tests_dir_cmd = f'sudo find {configs_path}/assert -mindepth 1 -maxdepth 1 -type f ! \\( {match_str} \\) -exec rm -rf {{}} +' c.sendline(cleanup_config_dir_cmd) c.expect(op_mode_prompt) c.sendline(cleanup_config_tests_dir_cmd) c.expect(op_mode_prompt) log.info('Adding a legacy WireGuard default keypair for migrations') c.sendline('sudo mkdir -p /config/auth/wireguard/default') c.expect(op_mode_prompt) c.sendline('echo "aGx+fvW916Ej7QRnBbW3QMoldhNv1u95/WHz45zDmF0=" | sudo tee /config/auth/wireguard/default/private.key') c.expect(op_mode_prompt) c.sendline('echo "x39C77eavJNpvYbNzPSG3n1D68rHYei6q3AEBEyL1z8=" | sudo tee /config/auth/wireguard/default/public.key') c.expect(op_mode_prompt) log.info('Generating PKI objects') c.sendline('/usr/bin/vyos-configtest-pki') c.expect(op_mode_prompt, timeout=900) script_file = '/config/scripts/vyos-foo-update.script' c.sendline(f'echo "#!/bin/sh" > {script_file}; chmod 775 {script_file}') c.expect(op_mode_prompt) log.info('Executing load config tests') c.sendline('/usr/bin/vyos-configtest') i = c.expect(['\n +Invalid command:', 'No such file or directory', r'\n\S+@\S+[$#]'], timeout=test_timeout) if i==0: raise Exception('Invalid command detected') elif i==1: tmp = 'VyOS smoketest not found!' log.error(tmp) raise Exception(tmp) c.sendline('echo EXITCODE:$\x16?') i = c.expect(['EXITCODE:0', 'EXITCODE:\d+']) if i == 0: log.info('Configtest finished successfully!') pass elif i == 1: tmp = 'Configtest failed :/ - check debug output' log.error(tmp) raise Exception(tmp) elif args.sbom: # Determine SBOM output file names based on ISO name iso_real = os.path.realpath(args.iso) if args.iso else None iso_name = os.path.splitext(os.path.basename(iso_real))[0] if iso_real else 'vyos' sbom_file_cdx = f'{iso_name}.iso.cdx.json' sbom_file_spdx = f'{iso_name}.iso.spdx.json' # Create a mount point for the SBOM transfer disk log.info('Mounting transfer disk in VM') c.sendline('sudo mkdir -p /mnt/sbom_transfer') c.expect(op_mode_prompt) c.sendline('sudo mount $(sudo blkid -L SBOMXFER) /mnt/sbom_transfer') c.expect(op_mode_prompt) c.sendline('mountpoint -q /mnt/sbom_transfer && echo MOUNT_OK || echo MOUNT_FAIL') i = c.expect(['MOUNT_OK', 'MOUNT_FAIL']) if i != 0: raise Exception('Failed to mount SBOM transfer disk inside VM') c.expect(op_mode_prompt) # Copy the syft binary from the transfer disk and verify it is available before running the SBOM generation process c.sendline('test -x /mnt/sbom_transfer/syft && echo SYFT_SRC_OK || echo SYFT_SRC_FAIL') i = c.expect(['SYFT_SRC_OK', 'SYFT_SRC_FAIL']) if i != 0: raise Exception('Syft binary is missing or not executable on the SBOM transfer disk') c.expect(op_mode_prompt) c.sendline('sudo cp /mnt/sbom_transfer/syft /tmp/syft && sudo chmod +x /tmp/syft && test -x /tmp/syft && echo SYFT_COPY_OK || echo SYFT_COPY_FAIL') i = c.expect(['SYFT_COPY_OK', 'SYFT_COPY_FAIL']) if i != 0: raise Exception('Failed to copy Syft binary from SBOM transfer disk to /tmp/syft') c.expect(op_mode_prompt) c.sendline('TERM=dumb /tmp/syft --version') c.expect(op_mode_prompt) lines = c.before.decode(errors='replace').strip().splitlines() syft_version = next((l.strip() for l in reversed(lines) if l.strip()), 'unknown') log.info(f'syft version: {syft_version}') # Generate SBOMs using the syft util for the whole filesystem with all layers, output both CycloneDX and SPDX formats syft_cmd = ( f'sudo TERM=dumb /tmp/syft / -q' f' --exclude **/mnt/sbom_transfer/**' f' --source-name {iso_name}.iso --source-version {iso_name}' f' -o cyclonedx-json=/mnt/sbom_transfer/{sbom_file_cdx}' f' -o spdx-json=/mnt/sbom_transfer/{sbom_file_spdx}' ) log.info(f'Generating SBOMs: {sbom_file_cdx} and {sbom_file_spdx}') c.sendline(syft_cmd) c.expect(op_mode_prompt, timeout=1800) c.sendline('echo EXITCODE:$\x16?') i = c.expect(['EXITCODE:0', r'EXITCODE:\d+']) if i != 0: raise Exception('syft SBOM generation failed') # Unmount transfer disk c.sendline('sudo umount /mnt/sbom_transfer') c.expect(op_mode_prompt) log.info('SBOM files written to transfer disk. The transfer disk was unmounted.') elif args.sbtest: c.sendline('show secure-boot') c.expect('SecureBoot enabled') c.expect(op_mode_prompt) else: log.info('No testcase selected!') shutdownVM(c, log, 'Powering off system') c.close() # Extract SBOM files from transfer disk to host if args.sbom and transfer_disk_path and args.sbom_output_dir: log.info('Extracting SBOM files from transfer disk to host.') mount_point = f'{transfer_disk_path}.mnt' mounted = False os.makedirs(mount_point, exist_ok=True) try: subprocess.check_output(['mount', '-o', 'loop', transfer_disk_path, mount_point]) mounted = True for sbom_f in [sbom_file_cdx, sbom_file_spdx]: src = os.path.join(mount_point, sbom_f) if os.path.isfile(src): shutil.copy2(src, args.sbom_output_dir) log.info(f'SBOM file saved to: {args.sbom_output_dir}/{sbom_f}') finally: if mounted: subprocess.check_output(['umount', mount_point]) if os.path.isdir(mount_point): os.rmdir(mount_point) except EarlyExit: pass except pexpect.exceptions.TIMEOUT: log.error('Timeout waiting for VyOS system') log.error(traceback.format_exc()) EXCEPTION = 1 except pexpect.exceptions.ExceptionPexpect: log.error('Exception while executing QEMU') log.error('Is qemu working on this system?') log.error(traceback.format_exc()) EXCEPTION = 1 except Exception: log.error('Unknown error occurred!') traceback.print_exc() EXCEPTION = 1 ################################################# # Cleaning up ################################################# log.info("Cleaning up") if tpm_process: tpm_process.terminate() tpm_process.join() if not args.keep: log.info(f'Removing disk file: {args.disk}') try: os.remove(args.disk) if diskname_raid: os.remove(diskname_raid) if args.sbtest: os.remove(OVMF_VARS_TMP) if transfer_disk_path and os.path.isfile(transfer_disk_path): os.remove(transfer_disk_path) except Exception: log.error('Exception while removing diskimage!') log.error(traceback.format_exc()) EXCEPTION = 1 if EXCEPTION: log.error('Hmm... system got an exception while processing.') log.error('The ISO image is not considered usable!') sys.exit(1) sys.exit(0)