All of lore.kernel.org
 help / color / mirror / Atom feed
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 09/13] pytest: Generate a rootfs for a guest
Date: Tue, 22 Sep 2026 12:08:56 +0200	[thread overview]
Message-ID: <20260922100900.29129-10-anthony@xenproject.org> (raw)
In-Reply-To: <20260922100900.29129-1-anthony@xenproject.org>

From: Anthony PERARD <anthony.perard@vates.tech>

Signed-off-by: Anthony PERARD <anthony.perard@vates.tech>
---
 automation/pytest/conftest.py        |  6 ++++
 automation/pytest/lib/boot_binary.py | 42 ++++++++++++++++++++++++++++
 automation/pytest/test_boot.py       |  8 ++++++
 3 files changed, 56 insertions(+)
 create mode 100644 automation/pytest/conftest.py

diff --git a/automation/pytest/conftest.py b/automation/pytest/conftest.py
new file mode 100644
index 000000000000..304241ae06ba
--- /dev/null
+++ b/automation/pytest/conftest.py
@@ -0,0 +1,6 @@
+import pytest
+
+
+def pytest_configure(config: pytest.Config) -> None:
+    config.addinivalue_line("markers",
+                            "guest_boot_script: script to run when the guest boot")
diff --git a/automation/pytest/lib/boot_binary.py b/automation/pytest/lib/boot_binary.py
index 1910d1f88fe6..9e79b1798908 100644
--- a/automation/pytest/lib/boot_binary.py
+++ b/automation/pytest/lib/boot_binary.py
@@ -30,6 +30,7 @@ class BootBinary:
                  static_dns: str | None = None,
                  static_ipv6: str | None = None,
                  boot_script: str | None = None,
+                 guest_boot_script: str | None = None,
                  ) -> None:
         self.vlan_id = vlan_id
         self.pxe_host = pxe_host
@@ -40,6 +41,7 @@ class BootBinary:
         self.static_ipv6 = static_ipv6
         self.ssh_pub_keys = ssh_pub_keys
         self.boot_script = boot_script
+        self.guest_boot_script = guest_boot_script
 
         # Minimal rootfs
         rootfs_path = tmp_path / "rootfs_minimal"
@@ -53,6 +55,12 @@ class BootBinary:
         self.prepare_dom0_rootfs(rootfs_path, xenroot)
         self.rootfs_dom0_dir = rootfs_path
 
+        # Guest kernel + rootfs
+        rootfs_path = tmp_path / "rootfs_domU"
+        rootfs_path.mkdir()
+        self.prepare_guest_rootfs(rootfs_path, xenroot)
+        self.rootfs_guest_dir = rootfs_path
+
 
     def prepare_minimal_rootfs(self, rootfs_path: Path, xenroot: Path) -> None:
         script_pre_xen = dedent(f"""\
@@ -212,8 +220,42 @@ class BootBinary:
 
         self.xen_tools_rootfs = cpio_rootfs
 
+    def prepare_guest_rootfs(self, rootfs_path: Path, xenroot: Path) -> None:
+        etc = rootfs_path / "etc"
+        etc.mkdir()
+
+        local_d_dir = etc / "local.d"
+        local_d_dir.mkdir()
+
+        xen_start_script = local_d_dir / "xen.start"
+        xen_start_script.write_text(dedent(f"""\
+            #!/bin/sh
+            echo 8 > /proc/sys/kernel/printk
+            {self.guest_boot_script}
+            """))
+        xen_start_script.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
+
+        (etc / "issue").write_text(dedent("""\
+            domU Welcome to Alpine Linux
+            Kernel \\r on an \\m (\\l)
+
+            """))
+
+        # rootfs archive
+        rootfs = []
+        # Uncompressed first! Then compressed cpio archives!
+        rootfs.append(xenroot / "binaries/rootfs.cpio.gz")
+        cpio_rootfs = xenroot / "binaries/guest-rootfs.cpio.gz"
+        concatenate_cpios(rootfs, cpio_rootfs)
+        cpio_archive_from_dir(rootfs_path, cpio_rootfs)
+
+        self.guest_rootfs = cpio_rootfs
+
     def minimal(self) -> Path:
         return self.minimal_rootfs
 
     def dom0_tools(self) -> Path:
         return self.xen_tools_rootfs
+
+    def guest(self) -> Path:
+        return self.guest_rootfs
diff --git a/automation/pytest/test_boot.py b/automation/pytest/test_boot.py
index 039cc36c1a04..5a7ec43fa52b 100644
--- a/automation/pytest/test_boot.py
+++ b/automation/pytest/test_boot.py
@@ -32,11 +32,17 @@ def prepare_rootfs(tmp_path: Path,
                    xenroot_path: Path,
                    sshkey_for_test: paramiko.pkey.PKey,
                    boot_string: str,
+                   request: pytest.FixtureRequest
                    ) -> BootBinary:
     static_gateway = os.environ['HOST_IP_GATEWAY']
     http_pxe_path = os.environ["PXE_HTTP_PATH"]
 
     boot_script = f"echo Dom0 ready {boot_string}\n"
+    marker = request.node.get_closest_marker("guest_boot_script")
+    if marker:
+        guest_boot_script = marker.args[0]
+    else:
+        guest_boot_script = None
 
     ssh_pub_keys = os.environ['SSH_PUB_KEYS']
     ssh_pub_keys += f"\n{sshkey_for_test.get_name()} {sshkey_for_test.get_base64()}\n"
@@ -52,6 +58,7 @@ def prepare_rootfs(tmp_path: Path,
                       static_ipv6=os.environ['HOST_IP6'],
                       ssh_pub_keys=ssh_pub_keys,
                       boot_script=boot_script,
+                      guest_boot_script=guest_boot_script,
                       )
 
 
@@ -61,6 +68,7 @@ def prepare_netboot(prepare_rootfs: BootBinary, xenroot_path: Path) -> None:
     rootfs_paths = [
         prepare_rootfs.minimal(),
         prepare_rootfs.dom0_tools(),
+        prepare_rootfs.guest(),
     ]
     netboot.prepare_tftp(xenroot_path, rootfs_paths)
 
-- 
Anthony PERARD



  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 ` [RFC XEN PATCH 08/13] pytest: Run run-tools-tests over ssh on the test machine Anthony PERARD
2026-09-22 10:08 ` Anthony PERARD [this message]
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-10-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.