|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC XEN PATCH 03/13] pytest: Add fixture to prepare the tftp server
From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Prepare the netboot config, and upload the necessary files.
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
automation/pytest/lib/net_boot.py | 60 +++++++++++++++++++++++++++++++
automation/pytest/pyproject.toml | 2 ++
automation/pytest/test_boot.py | 11 ++++++
3 files changed, 73 insertions(+)
create mode 100644 automation/pytest/lib/net_boot.py
diff --git a/automation/pytest/lib/net_boot.py
b/automation/pytest/lib/net_boot.py
new file mode 100644
index 000000000000..50d2cfaa5aaa
--- /dev/null
+++ b/automation/pytest/lib/net_boot.py
@@ -0,0 +1,60 @@
+import io
+import logging
+import os
+import paramiko
+from pathlib import Path
+import textwrap
+
+
+class NetBoot:
+ def grub_script(self) -> str:
+ http_pxe_path = os.environ['PXE_HTTP_PATH']
+ tftp_path = f"(http)/{http_pxe_path}"
+ console_opts = "console=vga,com1"
+
+ xen_cmdline_opts = [
+ console_opts,
+ "loglvl=all",
+ "guest_loglvl=all",
+ "dom0_mem=4G",
+ "console_timestamps=boot",
+ "watchdog",
+ "noreboot",
+ ]
+ xen_cmdline = " ".join(xen_cmdline_opts)
+ linux_cmdline = "console=hvc0 root=/dev/ram0 earlyprintk=xen"
+ script = textwrap.dedent(f"""\
+ echo \"Loading xen\"
+ multiboot2 {tftp_path}/xen {xen_cmdline}
+ echo \"Loading vmlinuz\"
+ module2 {tftp_path}/bzImage {linux_cmdline}
+ echo \"Loading initrd\"
+ module2 --nounzip {tftp_path}/pre-dom0-rootfs.cpio.gz
+ echo \"Booting\"
+ boot
+ """)
+
+ return script
+
+ def prepare_tftp(self, xenroot: Path, rootfss: list[Path]) -> None:
+ username = os.environ['PXE_SSH_USER']
+ hostname = os.environ['PXE_HOST']
+ remote_path = Path(os.environ['PXE_SSH_PATH'])
+
+ binaries_path = xenroot / "binaries"
+ binaries = []
+ for b1 in ["xen", "bzImage"]:
+ binaries.append(binaries_path / b1)
+ binaries += rootfss
+
+ ssh = paramiko.client.SSHClient()
+ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ ssh.connect(hostname, username=username)
+ with ssh.open_sftp() as sftp:
+ for b2 in binaries:
+ logging.debug(f" put {b2}, to {remote_path / b2.name}")
+ sftp.put(str(b2), str(remote_path / b2.name), confirm=True)
+ grub_script = io.BytesIO(self.grub_script().encode('utf-8'))
+ sftp.putfo(grub_script, str(remote_path / "grub.cfg"),
+ confirm=True)
+ ssh.close()
diff --git a/automation/pytest/pyproject.toml b/automation/pytest/pyproject.toml
index 3180b2555029..78f60c4f8e77 100644
--- a/automation/pytest/pyproject.toml
+++ b/automation/pytest/pyproject.toml
@@ -3,8 +3,10 @@ name = "xen-ci-intree"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = [
+ "paramiko>=4.0.0",
"pip>=26.0.1",
"pytest>=9.0.2",
+ "types-paramiko>=4.0.0.20260322",
]
[dependency-groups]
dev = [
diff --git a/automation/pytest/test_boot.py b/automation/pytest/test_boot.py
index 230cee96d0ba..661c2a59e4fe 100644
--- a/automation/pytest/test_boot.py
+++ b/automation/pytest/test_boot.py
@@ -3,6 +3,7 @@ from pathlib import Path
import pytest
from lib.boot_binary import BootBinary
+from lib.net_boot import NetBoot
@pytest.fixture
@@ -30,3 +31,13 @@ def prepare_rootfs(tmp_path: Path,
static_ipv6=os.environ['HOST_IP6'],
boot_script=boot_script,
)
+
+
+@pytest.fixture
+def prepare_netboot(prepare_rootfs: BootBinary, xenroot_path: Path) -> None:
+ netboot = NetBoot()
+ rootfs_paths = [
+ prepare_rootfs.minimal(),
+ prepare_rootfs.dom0_tools(),
+ ]
+ netboot.prepare_tftp(xenroot_path, rootfs_paths)
--
Anthony PERARD
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |