diff options
Diffstat (limited to 'scripts/check-qemu-install')
-rwxr-xr-x | scripts/check-qemu-install | 141 |
1 files changed, 122 insertions, 19 deletions
diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install index 7faea56f..53e1c74d 100755 --- a/scripts/check-qemu-install +++ b/scripts/check-qemu-install @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2019-2024, VyOS maintainers and contributors +# Copyright (C) 2019-2025, 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 @@ -44,6 +44,7 @@ import logging import re import tomli import shutil +import json from io import BytesIO from datetime import datetime @@ -94,12 +95,30 @@ parser.add_argument('--sbtest', help='Execute Secure Boot 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('--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) args = parser.parse_args() +# 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. @@ -121,13 +140,6 @@ class StreamToLogger(object): def flush(self): pass -def get_half_cpus(): - """ return 1/2 of the numbers of available CPUs """ - cpu = os.cpu_count() - if cpu > 1: - cpu /= 2 - return int(cpu) - OVMF_CODE = '/usr/share/OVMF/OVMF_CODE_4M.secboot.fd' OVMF_VARS_TMP = args.disk.replace('.img', '.efivars') if args.sbtest: @@ -162,17 +174,15 @@ def get_qemu_cmd(name, enable_uefi, disk_img, raid=None, iso_img=None, tpm=False f' -device ahci,id=achi0' \ f' -device ide-cd,bus=achi0.0,drive=drive-cd1,id=cd1,bootindex=10' - # test using half of the available CPUs on the system - cpucount = get_half_cpus() - - macbase = '52:54:00:00:00' + # RFC7042 section 2.1.2 MAC addresses used for documentation + macbase = '00:00:5E:00:53' cmd = f'qemu-system-x86_64 \ -name "{name}" \ - -smp {cpucount},sockets=1,cores={cpucount},threads=1 \ + -smp {args.cpu},sockets=1,cores={args.cpu},threads=1 \ -cpu host \ -machine {machine},accel=kvm \ {uefi} \ - -m 4G \ + -m {args.memory}G \ -vga none \ -nographic \ {vga} {vnc}\ @@ -357,7 +367,7 @@ if args.qemu_cmd: os.system(tmp) exit(0) -test_timeout = 3 *3600 # 3 hours (in seconds) +test_timeout = 5 *3600 # 3 hours (in seconds) tpm_process = None try: # Start TPM emulator @@ -385,14 +395,42 @@ try: toggleUEFISecureBoot(c) try: - c.expect('Automatic boot in', timeout=10) - c.sendline('') + c.expect('Welcome to GRUB', timeout=10) + c.send(KEY_DOWN) + c.send(KEY_DOWN) + c.send(KEY_RETURN) except pexpect.TIMEOUT: log.warning('Did not find GRUB countdown window, ignoring') loginVM(c, log) ################################################# + # 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) + 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') @@ -508,17 +546,29 @@ try: 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 start vyos-configd.service &> /dev/null') + 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) @@ -544,6 +594,30 @@ try: 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 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) + + ################################################# + # 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}"') @@ -766,6 +840,15 @@ try: # remove interface tests as they consume a lot of time c.sendline('sudo rm -f /usr/libexec/vyos/tests/smoke/cli/test_interfaces_*') c.expect(op_mode_prompt) + if args.no_vpp: + # remove VPP tests + c.sendline('sudo rm -f /usr/libexec/vyos/tests/smoke/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') @@ -792,6 +875,26 @@ try: # else, run configtest suite elif args.configtest: + # Remove config-tests that we don't want to run + if args.match: + 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 /usr/libexec/vyos/tests/config -mindepth 1 -maxdepth 1 \\( {match_str} \\) -exec rm -rf {{}} +' + cleanup_config_tests_dir_cmd = f'sudo find /usr/libexec/vyos/tests/config-tests -mindepth 1 -maxdepth 1 \\( {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 /usr/libexec/vyos/tests/config -mindepth 1 -maxdepth 1 ! \\( {match_str} \\) -exec rm -rf {{}} +' + cleanup_config_tests_dir_cmd = f'sudo find /usr/libexec/vyos/tests/config-tests -mindepth 1 -maxdepth 1 ! \\( {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) @@ -851,7 +954,7 @@ except pexpect.exceptions.ExceptionPexpect: EXCEPTION = 1 except Exception: - log.error('Unknown error occured while VyOS!') + log.error('Unknown error occured!') traceback.print_exc() EXCEPTION = 1 |