Merge pull request #10128 from storytold/ci/rpm-release-smoke

Validate release RPM installation and GUI startup on target distributions
This commit is contained in:
FredApps authored and GitHub committed 2026-11-30 05:04:55 +01:00
commit 88e12f37e3
5 files changed
+310

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
"""Check a real installed release RPM and exercise the GUI control channel."""
import json
import os
from pathlib import Path
import secrets
import socket
import subprocess
import time
import tempfile
def run_smoke(results):
requirements = (results / "rpm-requires.txt").read_text()
for capability in (
"libc.so.6()(64bit)",
"libm.so.6(GLIBC_2.35)(64bit)",
"libgcc_s.so.1()(64bit)",
"libxkbcommon.so.0()(64bit)",
"(libvulkan.so.1()(64bit) or libEGL.so.1()(64bit))",
):
if capability not in requirements.splitlines():
raise RuntimeError(f"Missing RPM requirement: {capability}")
version = subprocess.check_output(["vectorcraft-cli", "--version"], text=True)
(results / "cli-version.txt").write_text(version)
# Original fixture authored for this package smoke test; no external artwork.
fixture = results / "original-smoke.svg"
fixture.write_text('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="140">'
'<rect x="20" y="20" width="160" height="100" rx="12" fill="#2463eb"/>'
'<circle cx="100" cy="70" r="30" fill="#ffcc33"/></svg>')
token = secrets.token_hex(32)
with tempfile.TemporaryDirectory(prefix="vectorcraft-runtime-") as runtime, (results / "gui.log").open("w") as log:
env = dict(os.environ, VECTORCRAFT_NO_PREFS="1", XDG_RUNTIME_DIR=runtime,
VECTORCRAFT_CONTROL_TOKEN=token)
app = subprocess.Popen([
"vectorcraft", "--control", "32180", "--automation-read-root", str(results),
"--automation-write-root", str(results), str(fixture),
], stdout=log, stderr=subprocess.STDOUT, env=env)
try:
deadline = time.monotonic() + 90
while True:
if app.poll() is not None:
raise RuntimeError(f"GUI exited during startup: {app.returncode}")
try:
channel = socket.create_connection(("127.0.0.1", 32180), timeout=5)
break
except OSError:
if time.monotonic() >= deadline:
raise RuntimeError("GUI control channel did not become ready") from None
time.sleep(1)
channel.settimeout(30)
with channel, channel.makefile("rwb") as stream:
for request_id, method, params in (
(0, "auth", {"token": token}),
(1, "ui.inspect", {}),
):
stream.write((json.dumps(dict(id=request_id, method=method, params=params)) + "\n").encode())
stream.flush()
response = json.loads(stream.readline())
(results / f"{method}.json").write_text(json.dumps(response, indent=2))
if response.get("id") != request_id or response.get("ok") is not True:
raise RuntimeError(f"GUI request failed: {method}")
finally:
app.terminate()
try:
app.wait(timeout=10)
except subprocess.TimeoutExpired:
app.kill()
app.wait()
if __name__ == "__main__":
run_smoke(Path("/results"))
@@ -0,0 +1,116 @@
"""Exercise failures that an installed-package happy-path check cannot reproduce."""
import importlib.util
import json
from pathlib import Path
import subprocess
import tempfile
import unittest
from unittest.mock import MagicMock, patch
spec = importlib.util.spec_from_file_location("rpm_smoke", Path(__file__).parents[1] / "release-rpm-smoke.py")
smoke = importlib.util.module_from_spec(spec)
spec.loader.exec_module(smoke)
class SmokeLifecycleTests(unittest.TestCase):
def setUp(self):
self.folder = tempfile.TemporaryDirectory()
self.addCleanup(self.folder.cleanup)
self.results = Path(self.folder.name)
(self.results / "rpm-requires.txt").write_text("\n".join([
"libc.so.6()(64bit)", "libm.so.6(GLIBC_2.35)(64bit)",
"libgcc_s.so.1()(64bit)", "libxkbcommon.so.0()(64bit)",
"(libvulkan.so.1()(64bit) or libEGL.so.1()(64bit))",
]))
self.app = MagicMock()
self.app.poll.return_value = None
self.channel = MagicMock()
self.stream = self.channel.makefile.return_value.__enter__.return_value
self.stream.readline.side_effect = [
b'{"id":0,"ok":true}\n', b'{"id":1,"ok":true,"result":{"window":"fixture"}}\n',
]
self.runtime = None
def launch(*args, **kwargs):
self.runtime = Path(kwargs["env"]["XDG_RUNTIME_DIR"])
self.assertTrue(self.runtime.is_dir())
return self.app
self.launch = self.start_patch(smoke.subprocess, "Popen", side_effect=launch)
self.start_patch(smoke.subprocess, "check_output", return_value="vectorcraft-cli 0.25.0\n")
self.connect = self.start_patch(smoke.socket, "create_connection", return_value=self.channel)
self.start_patch(smoke.time, "sleep")
def start_patch(self, owner, name, **kwargs):
patcher = patch.object(owner, name, **kwargs)
result = patcher.start()
self.addCleanup(patcher.stop)
return result
def assert_cleaned_up(self):
self.app.terminate.assert_called_once()
self.assertFalse(self.runtime.exists())
def test_success_records_inspection_and_removes_private_runtime(self):
smoke.run_smoke(self.results)
report = json.loads((self.results / "ui.inspect.json").read_text())
self.assertEqual(report["result"], {"window": "fixture"})
requests = [json.loads(call.args[0]) for call in self.stream.write.call_args_list]
self.assertEqual(requests[0]["method"], "auth")
self.assertEqual(requests[0]["params"]["token"], self.launch.call_args.kwargs["env"]["VECTORCRAFT_CONTROL_TOKEN"])
self.assert_cleaned_up()
def test_missing_runtime_dependency_prevents_launch(self):
(self.results / "rpm-requires.txt").write_text("")
with self.assertRaisesRegex(RuntimeError, "Missing RPM requirement"):
smoke.run_smoke(self.results)
self.launch.assert_not_called()
def test_child_exit_during_startup_is_a_failure(self):
self.app.poll.return_value = 1
self.app.returncode = 1
with self.assertRaisesRegex(RuntimeError, "exited during startup"):
smoke.run_smoke(self.results)
self.assert_cleaned_up()
def test_connection_is_retried_until_ready(self):
self.connect.side_effect = [OSError("not ready"), self.channel]
smoke.run_smoke(self.results)
self.assertEqual(self.connect.call_count, 2)
self.assert_cleaned_up()
def test_startup_timeout_stops_child(self):
self.connect.side_effect = OSError("not ready")
self.start_patch(smoke.time, "monotonic", side_effect=[0, 91])
with self.assertRaisesRegex(RuntimeError, "did not become ready"):
smoke.run_smoke(self.results)
self.assert_cleaned_up()
def test_auth_refusal_prevents_inspection(self):
self.stream.readline.side_effect = [b'{"id":0,"ok":false}\n']
with self.assertRaisesRegex(RuntimeError, "request failed: auth"):
smoke.run_smoke(self.results)
self.assertFalse((self.results / "ui.inspect.json").exists())
self.assert_cleaned_up()
def test_response_for_another_request_is_rejected(self):
self.stream.readline.side_effect = [b'{"id":0,"ok":true}\n', b'{"id":99,"ok":true}\n']
with self.assertRaisesRegex(RuntimeError, "request failed: ui.inspect"):
smoke.run_smoke(self.results)
self.assert_cleaned_up()
def test_malformed_response_still_stops_child(self):
self.stream.readline.side_effect = [b'not json\n']
with self.assertRaises(json.JSONDecodeError):
smoke.run_smoke(self.results)
self.assert_cleaned_up()
def test_unresponsive_child_is_killed_after_termination_timeout(self):
self.app.wait.side_effect = [subprocess.TimeoutExpired("vectorcraft", 10), 0]
smoke.run_smoke(self.results)
self.app.kill.assert_called_once()
self.assert_cleaned_up()
if __name__ == "__main__":
unittest.main()
+114
View File
@@ -0,0 +1,114 @@
name: Release RPM smoke
on:
workflow_dispatch:
inputs:
run-id:
description: Release run containing both RPM artifacts (empty selects the latest available pair)
type: string
default: ""
pull_request:
paths:
- .github/workflows/release-rpm-smoke.yml
- .github/scripts/release-rpm-smoke.py
- .github/scripts/tests/test_release_rpm_smoke.py
permissions: {}
jobs:
source:
permissions:
actions: read
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
run-id: ${{ steps.source.outputs.run-id }}
steps:
- id: source
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ inputs.run-id }}
run: |
candidates="$RUN_ID"
if [ -z "$candidates" ]; then
candidates=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow release.yml --branch release --limit 10 --json databaseId --jq '.[].databaseId')
fi
for candidate in $candidates; do
[[ "$candidate" =~ ^[0-9]+$ ]]
names=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$candidate/artifacts?per_page=100" --jq '.artifacts[] | select(.expired == false) | .name')
if grep -Fxq release-linux-x86_64 <<< "$names" && grep -Fxq release-linux-aarch64 <<< "$names"; then
printf 'run-id=%s\n' "$candidate" >> "$GITHUB_OUTPUT"
exit 0
fi
done
echo '::error::No release run has both Linux package artifacts available'
exit 1
smoke:
permissions:
contents: read
actions: read
needs: source
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
platform:
- {arch: x86_64, runner: ubuntu-24.04}
- {arch: aarch64, runner: ubuntu-24.04-arm}
distro: [fedora, rocky, opensuse]
runs-on: ${{ matrix.platform.runner }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Download the release packages
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ needs.source.outputs.run-id }}
ARCH: ${{ matrix.platform.arch }}
run: |
[[ "$RUN_ID" =~ ^[0-9]+$ ]]
mkdir -p packages results
gh run view "$RUN_ID" --json headSha,url > results/source.json
gh run download "$RUN_ID" --name "release-linux-$ARCH" --dir packages
sha256sum packages/*.rpm > results/rpm-sha256.txt
- name: Install and start the RPM on the target distribution
env:
DISTRO: ${{ matrix.distro }}
run: |
sudo apt-get update -qq
sudo apt-get install -y xvfb
Xvfb :99 -screen 0 1440x900x24 -ac -nolisten tcp > results/xvfb.log 2>&1 &
for _attempt in {1..20}; do
[ -S /tmp/.X11-unix/X99 ] && break
sleep 1
done
[ -S /tmp/.X11-unix/X99 ]
case "$DISTRO" in
fedora) image=fedora:latest ;;
rocky) image=rockylinux:10 ;;
opensuse) image=opensuse/tumbleweed:latest ;;
esac
docker pull "$image"
docker image inspect "$image" --format '{{json .RepoDigests}}' > results/container-digest.json
docker run --rm --ipc=host --name rpm-smoke -e DISTRO -e DISPLAY=:99 -e LIBGL_ALWAYS_SOFTWARE=1 \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro -v "$PWD/packages:/packages:ro" \
-v "$PWD/results:/results" -v "$PWD/.github/scripts:/checks:ro" "$image" bash -euc '
cat /etc/os-release > /results/os-release.txt
if [ "$DISTRO" = opensuse ]; then
zypper --non-interactive refresh
zypper --non-interactive install python3 Mesa-dri Mesa-libEGL1 libX11-6 libXcursor1 libXi6 libXrandr2 libxkbcommon0 libxkbcommon-x11-0
zypper --non-interactive --no-gpg-checks install /packages/*.rpm
else
dnf -y install python3 mesa-dri-drivers mesa-libEGL libX11 libXcursor libXi libXrandr libxkbcommon libxkbcommon-x11
dnf -y --nogpgcheck install /packages/*.rpm
fi
rpm -qp --requires /packages/*.rpm > /results/rpm-requires.txt
python3 /checks/release-rpm-smoke.py
'
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
if: always()
with:
name: rpm-smoke-${{ matrix.distro }}-${{ matrix.platform.arch }}
path: results/
if-no-files-found: error
+3
View File
@@ -21,4 +21,7 @@ jobs:
# The reusable workflow defaults build-jobs to 2 so a cold instrumented
# archive stays within hosted-runner memory (craft-common-actions#333).
uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main
with:
python-coverage-source: .github/scripts
python-coverage-script: .github/scripts/tests/test_release_rpm_smoke.py
secrets: inherit
+3
View File
@@ -18,3 +18,6 @@ sonar.issue.ignore.multicriteria=pdf_md5
sonar.issue.ignore.multicriteria.pdf_md5.ruleKey=rust:S4790
sonar.issue.ignore.multicriteria.pdf_md5.resourceKey=crates/pdf/src/encrypt.rs
sonar.coverage.exclusions=packaging/**
# Produced by the shared workflow Python coverage step.
sonar.python.coverage.reportPaths=python-coverage.xml