Skip to content

Commit

Permalink
test: add fixture for vhost-user-blk backend
Browse files Browse the repository at this point in the history
The fixture fetches a Qemu release,
verifies its signature, configures and builds
the vhost-user-blk backend.

The fixture is supposed to be used for testing
vhost-user-blk device.

Command line options:
  -s, --socket-path=PATH       Use UNIX socket path
  -b, --blk-file=PATH          block device or file path
  -r, --read-only              Enable read-only

Signed-off-by: Nikita Kalyazin <[email protected]>
  • Loading branch information
kalyazin committed Oct 9, 2023
1 parent d803d31 commit fda098f
Showing 1 changed file with 47 additions and 0 deletions.
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"
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

0 comments on commit fda098f

Please sign in to comment.