Compare commits

..

1 Commits

Author SHA1 Message Date
Mike Yuan ebcc62c2b9
Merge 18c36b1e24 into 4f3df8c1bb 2024-11-24 12:01:37 +01:00
16 changed files with 74 additions and 108 deletions

View File

@ -37,7 +37,7 @@ jobs:
VALIDATE_GITHUB_ACTIONS: true VALIDATE_GITHUB_ACTIONS: true
- name: Check that tabs are not used in Python code - name: Check that tabs are not used in Python code
run: sh -c '! git grep -P "\\t" -- src/ukify/ukify.py test/integration-test-wrapper.py' run: sh -c '! git grep -P "\\t" -- src/ukify/ukify.py'
- name: Install ruff and mypy - name: Install ruff and mypy
run: | run: |
@ -47,14 +47,14 @@ jobs:
- name: Run mypy - name: Run mypy
run: | run: |
python3 -m mypy --version python3 -m mypy --version
python3 -m mypy src/ukify/ukify.py test/integration-test-wrapper.py python3 -m mypy src/ukify/ukify.py
- name: Run ruff check - name: Run ruff check
run: | run: |
ruff --version ruff --version
ruff check src/ukify/ukify.py test/integration-test-wrapper.py ruff check src/ukify/ukify.py
- name: Run ruff format - name: Run ruff format
run: | run: |
ruff --version ruff --version
ruff format --check src/ukify/ukify.py test/integration-test-wrapper.py ruff format --check src/ukify/ukify.py

View File

@ -105,7 +105,7 @@ jobs:
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: systemd/mkosi@0825cca8084674ec8fa27502134b1bc601f79e0c - uses: systemd/mkosi@8976a0abb19221e65300222f2d33067970cca0f1
# Freeing up disk space with rm -rf can take multiple minutes. Since we don't need the extra free space # Freeing up disk space with rm -rf can take multiple minutes. Since we don't need the extra free space
# immediately, we remove the files in the background. However, we first move them to a different location # immediately, we remove the files in the background. However, we first move them to a different location

View File

@ -1,18 +1,12 @@
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
if command -v flatpak-spawn >/dev/null; then MKOSI_CONFIG="$(mkosi --json summary | jq -r .Images[-1])"
SPAWN=(flatpak-spawn --host)
else
SPAWN=()
fi
MKOSI_CONFIG="$("${SPAWN[@]}" --host mkosi --json summary | jq -r .Images[-1])"
DISTRIBUTION="$(jq -r .Distribution <<< "$MKOSI_CONFIG")" DISTRIBUTION="$(jq -r .Distribution <<< "$MKOSI_CONFIG")"
RELEASE="$(jq -r .Release <<< "$MKOSI_CONFIG")" RELEASE="$(jq -r .Release <<< "$MKOSI_CONFIG")"
ARCH="$(jq -r .Architecture <<< "$MKOSI_CONFIG")" ARCH="$(jq -r .Architecture <<< "$MKOSI_CONFIG")"
exec "${SPAWN[@]}" mkosi \ exec mkosi \
--incremental=strict \ --incremental=strict \
--build-sources-ephemeral=no \ --build-sources-ephemeral=no \
--format=none \ --format=none \

View File

@ -6,12 +6,10 @@ ToolsTreeDistribution=arch
[Build] [Build]
ToolsTreePackages= ToolsTreePackages=
cryptsetup cryptsetup
github-cli
libcap libcap
libmicrohttpd libmicrohttpd
python-jinja python-jinja
python-pytest python-pytest
ruff ruff
shellcheck
tpm2-tss tpm2-tss
util-linux-libs util-linux-libs

View File

@ -16,4 +16,3 @@ ToolsTreePackages=
tpm2-tss-devel tpm2-tss-devel
python3-jinja2 python3-jinja2
python3-pytest python3-pytest
shellcheck

View File

@ -6,7 +6,6 @@ ToolsTreeDistribution=|ubuntu
[Build] [Build]
ToolsTreePackages= ToolsTreePackages=
gh
libblkid-dev libblkid-dev
libcap-dev libcap-dev
libcryptsetup-dev libcryptsetup-dev
@ -17,4 +16,3 @@ ToolsTreePackages=
libtss2-dev libtss2-dev
python3-jinja2 python3-jinja2
python3-pytest python3-pytest
shellcheck

View File

@ -5,5 +5,4 @@ ToolsTreeDistribution=fedora
[Build] [Build]
ToolsTreePackages= ToolsTreePackages=
gh
ruff ruff

View File

@ -5,7 +5,6 @@ ToolsTreeDistribution=opensuse
[Build] [Build]
ToolsTreePackages= ToolsTreePackages=
gh
pkgconfig(blkid) pkgconfig(blkid)
pkgconfig(libcap) pkgconfig(libcap)
pkgconfig(libcryptsetup) pkgconfig(libcryptsetup)
@ -17,4 +16,3 @@ ToolsTreePackages=
tss2-devel tss2-devel
python3-jinja2 python3-jinja2
python3-pytest python3-pytest
ShellCheck

View File

@ -13,7 +13,6 @@ Environment=
[Content] [Content]
Packages= Packages=
clang-devel
compiler-rt compiler-rt
gdb gdb
git-core git-core

View File

@ -15,7 +15,6 @@ Environment=
[Content] [Content]
Packages= Packages=
apt apt
clangd
erofs-utils erofs-utils
git-core git-core
libclang-rt-dev libclang-rt-dev

View File

@ -12,7 +12,6 @@ Environment=
[Content] [Content]
Packages= Packages=
clang
diffutils diffutils
erofs-utils erofs-utils
gcc-c++ gcc-c++

View File

@ -57,8 +57,6 @@ wrap=(
delv delv
dhcpd dhcpd
dig dig
dnf
dnf5
dmsetup dmsetup
dnsmasq dnsmasq
findmnt findmnt
@ -95,7 +93,7 @@ wrap=(
) )
for bin in "${wrap[@]}"; do for bin in "${wrap[@]}"; do
if ! mkosi-chroot bash -c "command -v $bin" >/dev/null; then if ! mkosi-chroot command -v "$bin" >/dev/null; then
continue continue
fi fi
@ -105,7 +103,7 @@ for bin in "${wrap[@]}"; do
enable_lsan=0 enable_lsan=0
fi fi
target="$(mkosi-chroot bash -c "command -v $bin")" target="$(mkosi-chroot command -v "$bin")"
mv "$BUILDROOT/$target" "$BUILDROOT/$target.orig" mv "$BUILDROOT/$target" "$BUILDROOT/$target.orig"

View File

@ -467,7 +467,7 @@ class SignTool:
raise NotImplementedError() raise NotImplementedError()
@staticmethod @staticmethod
def from_string(name: str) -> type['SignTool']: def from_string(name) -> type['SignTool']:
if name == 'pesign': if name == 'pesign':
return PeSign return PeSign
elif name == 'sbsign': elif name == 'sbsign':

View File

@ -1,7 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
"""Test wrapper command for driving integration tests.""" '''Test wrapper command for driving integration tests.
'''
import argparse import argparse
import json import json
@ -12,6 +13,7 @@ import sys
import textwrap import textwrap
from pathlib import Path from pathlib import Path
EMERGENCY_EXIT_DROPIN = """\ EMERGENCY_EXIT_DROPIN = """\
[Unit] [Unit]
Wants=emergency-exit.service Wants=emergency-exit.service
@ -32,7 +34,7 @@ ExecStart=false
""" """
def main() -> None: def main():
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--mkosi', required=True) parser.add_argument('--mkosi', required=True)
parser.add_argument('--meson-source-dir', required=True, type=Path) parser.add_argument('--meson-source-dir', required=True, type=Path)
@ -44,43 +46,34 @@ def main() -> None:
parser.add_argument('--slow', action=argparse.BooleanOptionalAction) parser.add_argument('--slow', action=argparse.BooleanOptionalAction)
parser.add_argument('--vm', action=argparse.BooleanOptionalAction) parser.add_argument('--vm', action=argparse.BooleanOptionalAction)
parser.add_argument('--exit-code', required=True, type=int) parser.add_argument('--exit-code', required=True, type=int)
parser.add_argument('mkosi_args', nargs='*') parser.add_argument('mkosi_args', nargs="*")
args = parser.parse_args() args = parser.parse_args()
if not bool(int(os.getenv('SYSTEMD_INTEGRATION_TESTS', '0'))): if not bool(int(os.getenv("SYSTEMD_INTEGRATION_TESTS", "0"))):
print( print(f"SYSTEMD_INTEGRATION_TESTS=1 not found in environment, skipping {args.name}", file=sys.stderr)
f'SYSTEMD_INTEGRATION_TESTS=1 not found in environment, skipping {args.name}',
file=sys.stderr,
)
exit(77) exit(77)
if args.slow and not bool(int(os.getenv('SYSTEMD_SLOW_TESTS', '0'))): if args.slow and not bool(int(os.getenv("SYSTEMD_SLOW_TESTS", "0"))):
print( print(f"SYSTEMD_SLOW_TESTS=1 not found in environment, skipping {args.name}", file=sys.stderr)
f'SYSTEMD_SLOW_TESTS=1 not found in environment, skipping {args.name}',
file=sys.stderr,
)
exit(77) exit(77)
if args.vm and bool(int(os.getenv('TEST_NO_QEMU', '0'))): if args.vm and bool(int(os.getenv("TEST_NO_QEMU", "0"))):
print(f'TEST_NO_QEMU=1, skipping {args.name}', file=sys.stderr) print(f"TEST_NO_QEMU=1, skipping {args.name}", file=sys.stderr)
exit(77) exit(77)
for s in os.getenv('TEST_SKIP', '').split(): for s in os.getenv("TEST_SKIP", "").split():
if s in args.name: if s in args.name:
print(f'Skipping {args.name} due to TEST_SKIP', file=sys.stderr) print(f"Skipping {args.name} due to TEST_SKIP", file=sys.stderr)
exit(77) exit(77)
keep_journal = os.getenv('TEST_SAVE_JOURNAL', 'fail') keep_journal = os.getenv("TEST_SAVE_JOURNAL", "fail")
shell = bool(int(os.getenv('TEST_SHELL', '0'))) shell = bool(int(os.getenv("TEST_SHELL", "0")))
if shell and not sys.stderr.isatty(): if shell and not sys.stderr.isatty():
print( print(f"--interactive must be passed to meson test to use TEST_SHELL=1", file=sys.stderr)
'--interactive must be passed to meson test to use TEST_SHELL=1',
file=sys.stderr,
)
exit(1) exit(1)
name = args.name + (f'-{i}' if (i := os.getenv('MESON_TEST_ITERATION')) else '') name = args.name + (f"-{i}" if (i := os.getenv("MESON_TEST_ITERATION")) else "")
dropin = textwrap.dedent( dropin = textwrap.dedent(
"""\ """\
@ -91,14 +84,14 @@ def main() -> None:
if not shell: if not shell:
dropin += textwrap.dedent( dropin += textwrap.dedent(
""" f"""
[Unit] [Unit]
SuccessAction=exit SuccessAction=exit
SuccessActionExitStatus=123 SuccessActionExitStatus=123
""" """
) )
if os.getenv('TEST_MATCH_SUBTEST'): if os.getenv("TEST_MATCH_SUBTEST"):
dropin += textwrap.dedent( dropin += textwrap.dedent(
f""" f"""
[Service] [Service]
@ -106,7 +99,7 @@ def main() -> None:
""" """
) )
if os.getenv('TEST_MATCH_TESTCASE'): if os.getenv("TEST_MATCH_TESTCASE"):
dropin += textwrap.dedent( dropin += textwrap.dedent(
f""" f"""
[Service] [Service]
@ -123,7 +116,7 @@ def main() -> None:
""" """
) )
journal_file = (args.meson_build_dir / (f'test/journal/{name}.journal')).absolute() journal_file = (args.meson_build_dir / (f"test/journal/{name}.journal")).absolute()
journal_file.unlink(missing_ok=True) journal_file.unlink(missing_ok=True)
elif not shell: elif not shell:
dropin += textwrap.dedent( dropin += textwrap.dedent(
@ -143,60 +136,54 @@ def main() -> None:
*(['--forward-journal', journal_file] if journal_file else []), *(['--forward-journal', journal_file] if journal_file else []),
*( *(
[ [
'--credential', f'systemd.extra-unit.emergency-exit.service={shlex.quote(EMERGENCY_EXIT_SERVICE)}', # noqa: E501 '--credential',
'--credential', f'systemd.unit-dropin.emergency.target={shlex.quote(EMERGENCY_EXIT_DROPIN)}', f"systemd.extra-unit.emergency-exit.service={shlex.quote(EMERGENCY_EXIT_SERVICE)}",
'--credential',
f"systemd.unit-dropin.emergency.target={shlex.quote(EMERGENCY_EXIT_DROPIN)}",
] ]
if not sys.stderr.isatty() if not sys.stderr.isatty()
else [] else []
), ),
'--credential', f'systemd.unit-dropin.{args.unit}={shlex.quote(dropin)}', '--credential',
f"systemd.unit-dropin.{args.unit}={shlex.quote(dropin)}",
'--runtime-network=none', '--runtime-network=none',
'--runtime-scratch=no', '--runtime-scratch=no',
*args.mkosi_args, *args.mkosi_args,
'--qemu-firmware', '--qemu-firmware', args.firmware,
args.firmware, *(['--qemu-kvm', 'no'] if int(os.getenv("TEST_NO_KVM", "0")) else []),
*(['--qemu-kvm', 'no'] if int(os.getenv('TEST_NO_KVM', '0')) else []),
'--kernel-command-line-extra', '--kernel-command-line-extra',
' '.join( ' '.join([
[
'systemd.hostname=H', 'systemd.hostname=H',
f'SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/{args.name}.units:/usr/lib/systemd/tests/testdata/units:', f"SYSTEMD_UNIT_PATH=/usr/lib/systemd/tests/testdata/{args.name}.units:/usr/lib/systemd/tests/testdata/units:",
*([f'systemd.unit={args.unit}'] if not shell else []), *([f"systemd.unit={args.unit}"] if not shell else []),
'systemd.mask=systemd-networkd-wait-online.service', 'systemd.mask=systemd-networkd-wait-online.service',
*( *(
[ [
'systemd.mask=serial-getty@.service', "systemd.mask=serial-getty@.service",
'systemd.show_status=error', "systemd.show_status=error",
'systemd.crash_shell=0', "systemd.crash_shell=0",
'systemd.crash_action=poweroff', "systemd.crash_action=poweroff",
] ]
if not sys.stderr.isatty() if not sys.stderr.isatty()
else [] else []
), ),
] ]),
),
'--credential', f"journal.storage={'persistent' if sys.stderr.isatty() else args.storage}", '--credential', f"journal.storage={'persistent' if sys.stderr.isatty() else args.storage}",
*(['--runtime-build-sources=no'] if not sys.stderr.isatty() else []), *(['--runtime-build-sources=no'] if not sys.stderr.isatty() else []),
'qemu' if args.vm or os.getuid() != 0 else 'boot', 'qemu' if args.vm or os.getuid() != 0 else 'boot',
] # fmt: skip ]
result = subprocess.run(cmd) result = subprocess.run(cmd)
# On Debian/Ubuntu we get a lot of random QEMU crashes. Retry once, and then skip if it fails again. # On Debian/Ubuntu we get a lot of random QEMU crashes. Retry once, and then skip if it fails again.
if args.vm and result.returncode == 247 and args.exit_code != 247: if args.vm and result.returncode == 247 and args.exit_code != 247:
if journal_file:
journal_file.unlink(missing_ok=True) journal_file.unlink(missing_ok=True)
result = subprocess.run(cmd) result = subprocess.run(cmd)
if args.vm and result.returncode == 247 and args.exit_code != 247: if args.vm and result.returncode == 247 and args.exit_code != 247:
print( print(f"Test {args.name} failed due to QEMU crash (error 247), ignoring", file=sys.stderr)
f'Test {args.name} failed due to QEMU crash (error 247), ignoring',
file=sys.stderr,
)
exit(77) exit(77)
if journal_file and ( if journal_file and (keep_journal == "0" or (result.returncode in (args.exit_code, 77) and keep_journal == "fail")):
keep_journal == '0' or (result.returncode in (args.exit_code, 77) and keep_journal == 'fail')
):
journal_file.unlink(missing_ok=True) journal_file.unlink(missing_ok=True)
if shell or result.returncode in (args.exit_code, 77): if shell or result.returncode in (args.exit_code, 77):
@ -205,33 +192,31 @@ def main() -> None:
if journal_file: if journal_file:
ops = [] ops = []
if os.getenv('GITHUB_ACTIONS'): if os.getenv("GITHUB_ACTIONS"):
id = os.environ['GITHUB_RUN_ID'] id = os.environ["GITHUB_RUN_ID"]
iteration = os.environ['GITHUB_RUN_ATTEMPT'] iteration = os.environ["GITHUB_RUN_ATTEMPT"]
j = json.loads( j = json.loads(
subprocess.run( subprocess.run(
[ [
args.mkosi, args.mkosi,
'--directory', os.fspath(args.meson_source_dir), "--directory", os.fspath(args.meson_source_dir),
'--json', "--json",
'summary', "summary",
], ],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
text=True, text=True,
).stdout ).stdout
) # fmt: skip
distribution = j['Images'][-1]['Distribution']
release = j['Images'][-1]['Release']
artifact = f'ci-mkosi-{id}-{iteration}-{distribution}-{release}-failed-test-journals'
ops += [f'gh run download {id} --name {artifact} -D ci/{artifact}']
journal_file = Path(f'ci/{artifact}/test/journal/{name}.journal')
ops += [f'journalctl --file {journal_file} --no-hostname -o short-monotonic -u {args.unit} -p info']
print(
"Test failed, relevant logs can be viewed with: \n\n" f"{(' && '.join(ops))}\n",
file=sys.stderr,
) )
distribution = j["Images"][-1]["Distribution"]
release = j["Images"][-1]["Release"]
artifact = f"ci-mkosi-{id}-{iteration}-{distribution}-{release}-failed-test-journals"
ops += [f"gh run download {id} --name {artifact} -D ci/{artifact}"]
journal_file = Path(f"ci/{artifact}/test/journal/{name}.journal")
ops += [f"journalctl --file {journal_file} --no-hostname -o short-monotonic -u {args.unit} -p info"]
print("Test failed, relevant logs can be viewed with: \n\n"
f"{(' && '.join(ops))}\n", file=sys.stderr)
# 0 also means we failed so translate that to a non-zero exit code to mark the test as failed. # 0 also means we failed so translate that to a non-zero exit code to mark the test as failed.
exit(result.returncode or 1) exit(result.returncode or 1)