[RFC XEN PATCH 00/13] Running bare-metal tests with "pytest"

Anthony PERARD posted 13 patches 2 days, 8 hours ago
automation/gitlab-ci/test.yaml       |  21 +++
automation/pytest/.env               |  19 ++
automation/pytest/conftest.py        |   6 +
automation/pytest/lib/__init__.py    |   0
automation/pytest/lib/boot_binary.py | 261 +++++++++++++++++++++++++++
automation/pytest/lib/ipmi.py        | 155 ++++++++++++++++
automation/pytest/lib/net_boot.py    |  60 ++++++
automation/pytest/pyproject.toml     |  17 ++
automation/pytest/pytest.toml        |  13 ++
automation/pytest/test_boot.py       | 237 ++++++++++++++++++++++++
10 files changed, 789 insertions(+)
create mode 100644 automation/pytest/.env
create mode 100644 automation/pytest/conftest.py
create mode 100644 automation/pytest/lib/__init__.py
create mode 100644 automation/pytest/lib/boot_binary.py
create mode 100644 automation/pytest/lib/ipmi.py
create mode 100644 automation/pytest/lib/net_boot.py
create mode 100644 automation/pytest/pyproject.toml
create mode 100644 automation/pytest/pytest.toml
create mode 100644 automation/pytest/test_boot.py
[RFC XEN PATCH 00/13] Running bare-metal tests with "pytest"
Posted by Anthony PERARD 2 days, 8 hours ago
From: Anthony PERARD <anthony.perard@vates.tech>

Patch series available in this git branch:
https://xenbits.xenproject.org/git-http/people/aperard/xen-unstable.git br.ci.bare-metal-with-pytest-v1

Hi,

I wanted to add some new machine to our GitLab CI, but I didn't want to
duplicate yet another time the existing shell script. They are good to get the
ball rolling but are getting harder to maintain as more test are been added,
and don't share common code between machines.

So, I've start work on something based on `pytest` which I hope will be easier
to maintain and extend and use to add new machines.

It's still Work In Progress.

Here is the current result:
    https://gitlab.com/xen-project/people/anthonyper/xen/-/jobs/16529107619

In this pipeline, the artifact use are a bit different from master; linux is
built with network driver, and vlan; the rootfs is from Marek's patch series,
with networking and dropbear service enabled.

Next:

I'd like to at least have a new fixture that give a started Host that a test
can ssh into. Then maybe a new class "Host" which could have functions for ssh
and getting the serial console output.

Don't go to much into detail review, I'm more interested of a general overview,
and to present what I have so far.

Some runes:
    - uv run mypy .
      to check the code, at least the types used.
      other code check could be added, and run by the pipeline
    - uv run pytest
      to run the whole test suite
    - uv run pytest test_boot.py::test_xen_tools_tests
      to run just one test

I did create an Arch Linux docker image with pytest, but paramiko got too new
to be used, so I've started to use `uv` to deal with the dependencies. `mypy`
always needed to be run with `uv` due to missing types for paramiko (not
packaged in Arch Linux). So the image is useless, and I'll look for a different
image later, for now just Arch Linux with `uv` installed.

Thanks,

Anthony PERARD (13):
  pytest: Add fixture to prepare rootfs
  Creating new python project
  pytest: Add fixture to prepare the tftp server
  pytest: Add fixture that boot a machine
  pytest: Introduce reading the console, and add a test
  We need an older version of paramiko.
  pytest: Add random string to look for in the logs
  pytest: Run run-tools-tests over ssh on the test machine
  pytest: Generate a rootfs for a guest
  pytest: Add guest test
  pytest: Add config to enable live log, and disable ssh/paramiko
    logging
  pytest: Add example .env for options for the tests
  gitlab-ci: Add job for moonshot with pytest

 automation/gitlab-ci/test.yaml       |  21 +++
 automation/pytest/.env               |  19 ++
 automation/pytest/conftest.py        |   6 +
 automation/pytest/lib/__init__.py    |   0
 automation/pytest/lib/boot_binary.py | 261 +++++++++++++++++++++++++++
 automation/pytest/lib/ipmi.py        | 155 ++++++++++++++++
 automation/pytest/lib/net_boot.py    |  60 ++++++
 automation/pytest/pyproject.toml     |  17 ++
 automation/pytest/pytest.toml        |  13 ++
 automation/pytest/test_boot.py       | 237 ++++++++++++++++++++++++
 10 files changed, 789 insertions(+)
 create mode 100644 automation/pytest/.env
 create mode 100644 automation/pytest/conftest.py
 create mode 100644 automation/pytest/lib/__init__.py
 create mode 100644 automation/pytest/lib/boot_binary.py
 create mode 100644 automation/pytest/lib/ipmi.py
 create mode 100644 automation/pytest/lib/net_boot.py
 create mode 100644 automation/pytest/pyproject.toml
 create mode 100644 automation/pytest/pytest.toml
 create mode 100644 automation/pytest/test_boot.py

-- 
Anthony PERARD
Re: [RFC XEN PATCH 00/13] Running bare-metal tests with "pytest"
Posted by Marek Marczykowski-Górecki 2 days, 7 hours ago
On Tue, Sep 22, 2026 at 12:08:47PM +0200, Anthony PERARD wrote:
> From: Anthony PERARD <anthony.perard@vates.tech>
> 
> Patch series available in this git branch:
> https://xenbits.xenproject.org/git-http/people/aperard/xen-unstable.git br.ci.bare-metal-with-pytest-v1
> 
> Hi,
> 
> I wanted to add some new machine to our GitLab CI, but I didn't want to
> duplicate yet another time the existing shell script. They are good to get the
> ball rolling but are getting harder to maintain as more test are been added,
> and don't share common code between machines.
>
> So, I've start work on something based on `pytest` which I hope will be easier
> to maintain and extend and use to add new machines.

Nice!

> It's still Work In Progress.
> 
> Here is the current result:
>     https://gitlab.com/xen-project/people/anthonyper/xen/-/jobs/16529107619

Minor readability improvement idea: force color output of pytest.

> In this pipeline, the artifact use are a bit different from master; linux is
> built with network driver, and vlan; the rootfs is from Marek's patch series,
> with networking and dropbear service enabled.
> 
> Next:
> 
> I'd like to at least have a new fixture that give a started Host that a test
> can ssh into. Then maybe a new class "Host" which could have functions for ssh
> and getting the serial console output.
> 
> Don't go to much into detail review, I'm more interested of a general overview,
> and to present what I have so far.

We had a design session on this topic, and we discussed a structural
change: have one job per Xen boot flavor (mostly dom0 PV vs PVH, but
could be also other settings needing host reboot) and then have pytest
run several tests via SSH. The idea is to not waste 2-4 minutes for
every ~10 sec test. Yes, it does mean one failed test will likely
prevent others in the same job from running (especially in case of Xen
panic), but since the intended state is "all green", a single failure is
bad already, and this approach should still get you enough information
to debug that first failure.

In practical terms, it would require most fixtures to be class or
session scope, instead of the default test scope. And using more SSH
instead of baking tests into startup scripts (already partially done,
but may need extending to domU commands too).

Other than that, this approach looks nice, and I really like using
pytest here, as it makes the structure significantly better. This will
likely require a bit of adjustments to handle also other hosts (for
example for qubes runners tftp dir is mounted into gitlab's container so
there is no need to sftp boot files). But that should be easy to do
later, it doesn't change the overall structure much.


> Some runes:
>     - uv run mypy .
>       to check the code, at least the types used.
>       other code check could be added, and run by the pipeline
>     - uv run pytest
>       to run the whole test suite
>     - uv run pytest test_boot.py::test_xen_tools_tests
>       to run just one test
> 
> I did create an Arch Linux docker image with pytest, but paramiko got too new
> to be used, so I've started to use `uv` to deal with the dependencies. `mypy`
> always needed to be run with `uv` due to missing types for paramiko (not
> packaged in Arch Linux). So the image is useless, and I'll look for a different
> image later, for now just Arch Linux with `uv` installed.

FWIW Qubes tests use Alpine container, seems to have all what we need. I
see it also has paramiko 4.0.0

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
Re: [RFC XEN PATCH 00/13] Running bare-metal tests with "pytest"
Posted by Baptiste Le Duc 2 days, 3 hours ago
> From: Anthony PERARD <anthony.perard@vates.tech>
> 
> Patch series available in this git branch:
> https://xenbits.xenproject.org/git-http/people/aperard/xen-unstable.git br.ci.bare-metal-with-pytest-v1
> 
> Hi,
> 
> I wanted to add some new machine to our GitLab CI, but I didn't want to
> duplicate yet another time the existing shell script. They are good to get the
> ball rolling but are getting harder to maintain as more test are been added,
> and don't share common code between machines.

Hi Anthony,

Nice to hear! I reviewed it quickly and it seems to be a more maintainable
solution to add machines in the CI.

FWIW the patch series I sent [1] also uses a python-driven framework (QTB)
which aims to replace the existing shell smoke test scripts. It's QEMU-only
though as it drives QEMU over QMP/qtest to manually trigger some IRQs. So,
it doesn't cover your usecase for the moment as-is and for the moment I
don't see a possible common abstraction between them but worth flagging.

Moreover, do you think we could replace the QEMU smoke-tests by using your
framework? With a very quick review, it seems we could just add a pytest
fixture machine_on_qemu(). If yes, then it would definitely be an overlap
with the usage of QTB I described above.

[1] https://lore.kernel.org/xen-devel/1787823334.8631fc262581453bbf619ec5b2062170.1a04293255c000c4f3@vates.tech/

-- 
Baptiste Le Duc <baptiste.le-duc@vates.tech>