Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add a fixture for Qemu vhost-user-blk backend #4156

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pathlib import Path

import pytest
import requests

import host_tools.cargo_build as build_tools
from framework import defs, utils
Expand All @@ -58,6 +59,11 @@


METRICS = get_metrics_logger()
QEMU_PUB_KEY_URL = "https://keys.openpgp.org/vks/v1/by-fingerprint/CEACC9E15534EBABB82D3FA03353C9CEF108B584"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ubuntu packages don't have the vhost-user-blk binary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was my first guess too, but I wasn't able to find it.

QEMU_VERSION = "8.1.1"
QEMU_TARBALL = f"qemu-{QEMU_VERSION}.tar.xz"
QEMU_URL = f"https://download.qemu.org/{QEMU_TARBALL}"
QEMU_SIG_URL = f"https://download.qemu.org/{QEMU_TARBALL}.sig"


def pytest_addoption(parser):
Expand Down Expand Up @@ -196,6 +202,47 @@ def bin_vsock_path(test_fc_session_root_path):
yield vsock_helper_bin_path


@pytest.fixture(scope="session")
def bin_vhost_user_blk_backend(test_fc_session_root_path):
"""Build a Qemu vhost-user-blk backend."""
# Fetch and import the public key
resp = requests.get(QEMU_PUB_KEY_URL, timeout=5)
resp.raise_for_status()
pk = Path(test_fc_session_root_path) / "qemu_pub_key"
pk.write_bytes(resp.content)
utils.run_cmd(["gpg", "--import", pk])

# Fetch the Qemu tarball
resp = requests.get(QEMU_URL, timeout=30)
resp.raise_for_status()
tarball_path = Path(test_fc_session_root_path) / QEMU_TARBALL
tarball_path.write_bytes(resp.content)

# Fetch the Qemu tarball signature
resp = requests.get(QEMU_SIG_URL, timeout=5)
resp.raise_for_status()
sig_path = Path(test_fc_session_root_path) / f"{QEMU_TARBALL}.sig"
sig_path.write_bytes(resp.content)

# Verify the signature
utils.run_cmd(["gpg", "--verify", sig_path, tarball_path])

# Unpack the Qemu tarball
utils.run_cmd(["tar", "xf", tarball_path, "-C", test_fc_session_root_path])

# Configure Qemu and build only the vhost-user-blk backend target.
backend_build_relpath = "contrib/vhost-user-blk/vhost-user-blk"
compile_cmd = f"./configure && make -j {backend_build_relpath}"
qemu_dir = Path(test_fc_session_root_path) / f"qemu-{QEMU_VERSION}"
utils.run_cmd(compile_cmd, cwd=qemu_dir)

# Note that the make target does not include the `build` part of the path,
# but the actual binary path does.
bin_path = qemu_dir / f"build/{backend_build_relpath}"

yield bin_path


@pytest.fixture(scope="session")
def change_net_config_space_bin(test_fc_session_root_path):
"""Build a binary that changes the MMIO config space."""
Expand Down