Capture screenshot when QEMU timeouts in boot tests

Open
#2,104 0 comments 0 reactions 1 assignee View on GitHub

@lzap is already working on this.

Since Dec 20, 2025.

Assessment

This issue has not been assessed yet.

Description

area/ci

If we encounter a timeout, we currently just give up which is okay if an image is configured for serial console. But installers are not. Let's just add a bit of code that captures a small screenshot so it is not too big for base64 encoded block to be thrown in the CICD output:

import socket
import json
import base64
import subprocess
from pathlib import Path

def capture_qemu_screenshot(qmp_socket_path, ppm_path):
    """Connects to QMP and saves a raw PPM screenshot."""
    client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        client.connect(str(qmp_socket_path))
        
        # 1. Negotiate QMP capabilities
        client.recv(1024) # Consumes the greeting
        client.sendall(json.dumps({"execute": "qmp_capabilities"}).encode())
        client.recv(1024) # Consumes the return
        
        # 2. Execute Screendump
        dump_cmd = {
            "execute": "screendump",
            "arguments": {"filename": str(ppm_path)}
        }
        client.sendall(json.dumps(dump_cmd).encode())
        client.recv(1024) # Ensure command finished
        
    finally:
        client.close()

def process_and_print_base64(ppm_path):
    """Shrinks the image and prints base64 for CI/CD logs."""
    png_path = ppm_path.with_suffix(".png")
    
    # Use ImageMagick to crush the size: 8-bit grayscale, 400px wide
    # This makes the Base64 string small enough to not bloat CI logs.
    subprocess.run([
        "convert", str(ppm_path),
        "-resize", "400x",
        "-colorspace", "gray",
        "-colors", "16", # Further reduces file size
        str(png_path)
    ], check=True)

    with open(png_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
        print("\n--- BEGIN QEMU SCREENSHOT ---")
        print(encoded_string)
        print("--- END QEMU SCREENSHOT ---\n")
Dominant language
Go
Stars
77
Forks
103
Avg merge
3d 6h
Merged PRs (30d)
53

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from osbuild/image-builder

All issues in osbuild/image-builder

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.