From: Anthony PERARD <anthony@xenproject.org>
To: xen-devel@lists.xenproject.org
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Doug Goldstein" <cardoe@cardoe.com>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [RFC XEN PATCH 08/13] pytest: Run run-tools-tests over ssh on the test machine
Date: Tue, 22 Sep 2026 12:08:55 +0200 [thread overview]
Message-ID: <20260922100900.29129-9-anthony@xenproject.org> (raw)
In-Reply-To: <20260922100900.29129-1-anthony@xenproject.org>
From: Anthony PERARD <anthony.perard@vates.tech>
Add a new random ssh public key to the rootfs.
Signed-off-by: Anthony PERARD <anthony.perard@vates.tech>
---
automation/pytest/lib/boot_binary.py | 7 +++++
automation/pytest/test_boot.py | 39 ++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/automation/pytest/lib/boot_binary.py b/automation/pytest/lib/boot_binary.py
index d8f503ead9f2..1910d1f88fe6 100644
--- a/automation/pytest/lib/boot_binary.py
+++ b/automation/pytest/lib/boot_binary.py
@@ -23,6 +23,7 @@ class BootBinary:
def __init__(self, tmp_path: Path, xenroot: Path,
pxe_host: str,
http_pxe_path: str,
+ ssh_pub_keys: str | None = None,
vlan_id: int | None = None,
static_ip: str | None = None,
static_gateway: str | None = None,
@@ -37,6 +38,7 @@ class BootBinary:
self.static_gateway = static_gateway
self.static_dns = static_dns
self.static_ipv6 = static_ipv6
+ self.ssh_pub_keys = ssh_pub_keys
self.boot_script = boot_script
# Minimal rootfs
@@ -126,6 +128,11 @@ class BootBinary:
runlevel_boot_d.mkdir(parents=True)
(runlevel_boot_d / "networking").symlink_to("/etc/init.d/networking")
+ if self.ssh_pub_keys:
+ home_root_ssh = rootfs_path / "root/.ssh"
+ home_root_ssh.mkdir(parents=True)
+ (home_root_ssh / "authorized_keys").write_text(self.ssh_pub_keys)
+
local_d_dir = rootfs_path / "etc/local.d"
local_d_dir.mkdir(parents=True)
diff --git a/automation/pytest/test_boot.py b/automation/pytest/test_boot.py
index 90d8e00e90d9..039cc36c1a04 100644
--- a/automation/pytest/test_boot.py
+++ b/automation/pytest/test_boot.py
@@ -1,5 +1,6 @@
import logging
import os
+import paramiko
from pathlib import Path
import pytest
import random
@@ -16,6 +17,11 @@ def xenroot_path() -> Path:
return Path("../..").resolve()
+@pytest.fixture
+def sshkey_for_test() -> paramiko.pkey.PKey:
+ return paramiko.ecdsakey.ECDSAKey.generate()
+
+
@pytest.fixture
def boot_string() -> str:
return ''.join(random.choice(string.ascii_letters) for _ in range(16))
@@ -24,6 +30,7 @@ def boot_string() -> str:
@pytest.fixture
def prepare_rootfs(tmp_path: Path,
xenroot_path: Path,
+ sshkey_for_test: paramiko.pkey.PKey,
boot_string: str,
) -> BootBinary:
static_gateway = os.environ['HOST_IP_GATEWAY']
@@ -31,6 +38,9 @@ def prepare_rootfs(tmp_path: Path,
boot_script = f"echo Dom0 ready {boot_string}\n"
+ ssh_pub_keys = os.environ['SSH_PUB_KEYS']
+ ssh_pub_keys += f"\n{sshkey_for_test.get_name()} {sshkey_for_test.get_base64()}\n"
+
return BootBinary(tmp_path,
xenroot_path,
vlan_id=int(os.environ['HOST_IP_VLANID']),
@@ -40,6 +50,7 @@ def prepare_rootfs(tmp_path: Path,
static_gateway=static_gateway,
static_dns=static_gateway,
static_ipv6=os.environ['HOST_IP6'],
+ ssh_pub_keys=ssh_pub_keys,
boot_script=boot_script,
)
@@ -73,6 +84,7 @@ def machine_on_ipmi(prepare_netboot: None) -> Generator[IPMI]:
@pytest.mark.timeout(600)
def test_xen_tools_tests(machine_on_ipmi: IPMI,
+ sshkey_for_test: paramiko.pkey.PKey,
boot_string: str,
) -> None:
expect_string = boot_string
@@ -91,3 +103,30 @@ def test_xen_tools_tests(machine_on_ipmi: IPMI,
if "Manual reset required ('noreboot' specified)" in line:
# Test failed, could wait a bit before failing the test.
logging.error("Xen panic")
+ ssh = paramiko.client.SSHClient()
+ ssh.set_missing_host_key_policy(paramiko.client.WarningPolicy)
+ logging.debug(f"connecting to {os.environ['HOST_IP4'].split('/')[0]}")
+ ssh.connect(os.environ['HOST_IP4'].split('/')[0],
+ username='root',
+ pkey=sshkey_for_test,
+ timeout=10,
+ )
+
+ cmd = '/root/run-tools-tests /usr/lib/xen/tests /tmp/tests-junit.xml'
+ logging.info(f"Exec command: {cmd}")
+ stdin, stdout, stderr = ssh.exec_command(cmd)
+ for output in stdout:
+ logging.debug(output.strip())
+ errormsg = stderr.read()
+ if errormsg:
+ logging.info(f"cmd errro: {errormsg!r}")
+ exit_status = stderr.channel.recv_exit_status()
+ logging.debug(f"exit status: {exit_status}")
+
+ cmd = 'cat /tmp/tests-junit.xml'
+ stdin, stdout, stderr = ssh.exec_command(cmd)
+ junit = stdout.read()
+ logging.debug(f"got junit result: {junit!r}")
+ errormsg = stderr.read()
+ if errormsg:
+ logging.info(f"cmd errro: {errormsg!r}")
--
Anthony PERARD
next prev parent reply other threads:[~2026-09-22 10:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 10:08 [RFC XEN PATCH 00/13] Running bare-metal tests with "pytest" Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 01/13] pytest: Add fixture to prepare rootfs Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 02/13] Creating new python project Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 03/13] pytest: Add fixture to prepare the tftp server Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 04/13] pytest: Add fixture that boot a machine Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 05/13] pytest: Introduce reading the console, and add a test Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 06/13] We need an older version of paramiko Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 07/13] pytest: Add random string to look for in the logs Anthony PERARD
2026-09-22 10:08 ` Anthony PERARD [this message]
2026-09-22 10:08 ` [RFC XEN PATCH 09/13] pytest: Generate a rootfs for a guest Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 10/13] pytest: Add guest test Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 11/13] pytest: Add config to enable live log, and disable ssh/paramiko logging Anthony PERARD
2026-09-22 10:08 ` [RFC XEN PATCH 12/13] pytest: Add example .env for options for the tests Anthony PERARD
2026-09-22 10:09 ` [RFC XEN PATCH 13/13] gitlab-ci: Add job for moonshot with pytest Anthony PERARD
2026-09-22 11:01 ` [RFC XEN PATCH 00/13] Running bare-metal tests with "pytest" Marek Marczykowski-Górecki
2026-09-22 14:31 ` Baptiste Le Duc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260922100900.29129-9-anthony@xenproject.org \
--to=anthony@xenproject.org \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=cardoe@cardoe.com \
--cc=marmarek@invisiblethingslab.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.