Skip to content

Commit

Permalink
fixup! WIP: test: Run integration tests with mkosi-built image
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmaw-codethink committed Feb 22, 2024
1 parent 09088fc commit 03b6031
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mkosi.images/system/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Dependencies=
testsuite-13-container-template
testsuite-55-oomd
testsuite-58-repart
testsuite-69-shutdown

[Output]
@Format=directory
Expand Down Expand Up @@ -54,6 +55,7 @@ ExtraTrees=
%O/testsuite-13-container-template.raw:/usr/share/testsuite-13-container-template.raw
%O/testsuite-55-oomd.raw:/usr/share/testsuite-55-oomd.raw
%O/testsuite-58-repart.raw:/usr/share/testsuite-58-repart.raw
%O/testsuite-69-shutdown.raw:/usr/share/testsuite-69-shutdown.raw

Packages=
acl
Expand Down Expand Up @@ -83,6 +85,7 @@ Packages=
nvme-cli
openssl
qrencode
screen
scsi-target-utils
sed
socat
Expand Down
9 changes: 9 additions & 0 deletions mkosi.images/testsuite-69-shutdown/mkosi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Config]
Dependencies=base

[Output]
Format=sysext
Overlay=yes

[Content]
BaseTrees=%O/base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXTENSION_RELOAD_MANAGER=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Manager]
DefaultTimeoutStopSec=30s
DefaultTimeoutAbortSec=30s
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Service]
ExecStart=systemd-firstboot --prompt-locale --prompt-timezone --delete-root-password
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C /root/.bashrc
C /root/.profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
startup_message off
bell_msg ""
11 changes: 11 additions & 0 deletions mkosi.images/testsuite-69-shutdown/mkosi.finalize
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

mkdir -p "$BUILDROOT/usr/share/factory/root"
if [[ -e "$BUILDROOT/root/.bashrc" ]]; then
cp -a "$BUILDROOT/root/.bashrc" "$BUILDROOT/usr/share/factory/root/.bashrc"
fi
if [[ -e "$BUILDROOT/root/.profile" ]]; then
cp -a "$BUILDROOT/root/.profile" "$BUILDROOT/usr/share/factory/root/.profile"
fi
echo "PS1='screen\$WINDOW # '" >>"$BUILDROOT/usr/share/factory/root/.bashrc"
echo "PS1='\s-\v\\\$ '" >>"$BUILDROOT/usr/share/factory/root/.profile"
23 changes: 23 additions & 0 deletions test/TEST-69-SHUTDOWN/hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python3

from logging import getLogger as logging_get_logger
from pathlib import Path
from shlex import quote
from shutil import which
from subprocess import run


log = logging_get_logger(__name__)


def wrap_run(args, **kwargs):
args[0] = which(args[0])
clargs = [Path(__file__).parents[1] / 'test-shutdown.py', '-v', '--']
clargs += args
log.debug(f"Running {' '.join(quote(str(a)) for a in clargs)}")
run(clargs, **kwargs)


def check_result(mountpoint, console_log):
# This test determines success by whether the wrapper command failed
pass
15 changes: 15 additions & 0 deletions test/TEST-69-SHUTDOWN/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test_params += {
'mkosi_args' : [
'--kernel-command-line-extra',
' '.join([
'apparmor=0',
'selinux=0',
'enforcing=0',
f'SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/testsuite-@test_number@.units:/usr/lib/systemd/tests/testdata/units:',
'systemd.unit=testsuite.target',
f'systemd.wants=@test_unit_name@',
'systemd.mount-extra=/usr/share/testsuite-69-shutdown.raw:/run/extensions/testsuite-69-shutdown.raw::bind',
]),
],
'hook_module' : meson.current_source_dir() / 'hook.py',
}
7 changes: 5 additions & 2 deletions test/integration_test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def main():
f"{per_test_output_dir.absolute()}")
rename(td, per_test_output_dir)

def run_mkosi(mkosi_args, **kwargs):
def run_mkosi(mkosi_args, run=run, **kwargs):
clargs = [
'mkosi',
'--directory=..',
Expand Down Expand Up @@ -199,7 +199,10 @@ def run_mkosi(mkosi_args, **kwargs):
stack.enter_context(hook.setup(mkosi_args, qemu_opts))

run_mkosi(mkosi_args + ['qemu'] + qemu_opts,
check=True, stderr=STDOUT, stdout=console_log)
check=True, stderr=STDOUT, stdout=console_log,
**({'run': hook.wrap_run}
if hook is not None and hasattr(hook, 'wrap_run')
else {}))
console_log.seek(0)
copyfileobj(console_log, stdout.buffer)

Expand Down
2 changes: 1 addition & 1 deletion test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ if get_option('integration-tests') != false
'66': 'TEST-66-DEVICE-ISOLATION',
'67': 'TEST-67-INTEGRITY',
'68': 'TEST-68-PROPAGATE-EXIT-STATUS',
#'69': 'TEST-69-SHUTDOWN', # customises image and removes end.service from kernel cmdline
'69': 'TEST-69-SHUTDOWN',
#'70': 'TEST-70-TPM2', # tpm2 permission problems
'71': 'TEST-71-HOSTNAME',
'72': 'TEST-72-SYSUPDATE',
Expand Down

0 comments on commit 03b6031

Please sign in to comment.