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 04/13] pytest: Add fixture that boot a machine
Date: Tue, 22 Sep 2026 12:08:51 +0200 [thread overview]
Message-ID: <20260922100900.29129-5-anthony@xenproject.org> (raw)
In-Reply-To: <20260922100900.29129-1-anthony@xenproject.org>
From: Anthony PERARD <anthony.perard@vates.tech>
.. and power it off once a test using the fixture is done.
This IPMI class is using the `ssh` console of an HP Moonshot 1500
Chassis.
Signed-off-by: Anthony PERARD <anthony.perard@vates.tech>
---
Maybe we could rename the class to Machine as a lib to control the
machine behavior, and access it's console.
---
automation/pytest/lib/ipmi.py | 69 ++++++++++++++++++++++++++++++++++
automation/pytest/test_boot.py | 17 +++++++++
2 files changed, 86 insertions(+)
create mode 100644 automation/pytest/lib/ipmi.py
diff --git a/automation/pytest/lib/ipmi.py b/automation/pytest/lib/ipmi.py
new file mode 100644
index 000000000000..0d3b085f704c
--- /dev/null
+++ b/automation/pytest/lib/ipmi.py
@@ -0,0 +1,69 @@
+import logging
+import paramiko
+import re
+
+
+class IPMI:
+ def __init__(self, *,
+ hostname: str,
+ username: str,
+ password: str,
+ blade_node: str,
+ ) -> None:
+ self.hostname = hostname
+ self.username = username
+ self.password = password
+ self.blade_node = blade_node
+
+ self.channel = None
+
+ def _new_client(self):
+ ssh = paramiko.client.SSHClient()
+ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ ssh.connect(self.hostname,
+ username=self.username,
+ password=self.password)
+ return ssh
+
+ def _run_cmd(self, command: str, debug_print: bool = True) -> str:
+ with self._new_client() as ssh:
+ stdin, stdout, stderr = ssh.exec_command(command)
+ output = stdout.read().decode()
+ if debug_print:
+ for line in output.splitlines():
+ if line in ['']:
+ continue
+ logging.debug(line.rstrip())
+ # the command's exit status (0 = success, 1 = failure)
+ # stdout.channel.recv_exit_status()
+ return output
+
+ def _power(self, state: str) -> None:
+ assert state in ["on", "off force"]
+ logging.info(f"Set power {state.split(' ')[0]} {self.blade_node}")
+ command = f"set node power {state} {self.blade_node}"
+ output = self._run_cmd(command, debug_print=False)
+ m = re.search(f"{self.blade_node}: #Node 1 (.*)\\r$",
+ output,
+ flags=re.M)
+ if m:
+ logging.info(f"-> {m[1]}")
+ else:
+ logging.warning(f"Failed to parse 'set power' command output: '{output}'")
+
+ def power_status(self):
+ command = f"show node power {self.blade_node}"
+ output = self._run_cmd(command, debug_print=False)
+ m = re.search(f"{self.blade_node}: #Node 1\\r\\n\\s+Power State: (\\S+)\\r$",
+ output,
+ flags=re.M)
+ if m:
+ logging.info(f"Machine is {m[1]}")
+ else:
+ logging.warning(f"Failed to match for \"Power State\" in '{output}'")
+
+ def power_on(self):
+ self._power('on')
+
+ def power_off(self):
+ self._power('off force')
diff --git a/automation/pytest/test_boot.py b/automation/pytest/test_boot.py
index 661c2a59e4fe..b7610736fa25 100644
--- a/automation/pytest/test_boot.py
+++ b/automation/pytest/test_boot.py
@@ -1,9 +1,11 @@
import os
from pathlib import Path
import pytest
+from typing import Generator
from lib.boot_binary import BootBinary
from lib.net_boot import NetBoot
+from lib.ipmi import IPMI
@pytest.fixture
@@ -41,3 +43,18 @@ def prepare_netboot(prepare_rootfs: BootBinary, xenroot_path: Path) -> None:
prepare_rootfs.dom0_tools(),
]
netboot.prepare_tftp(xenroot_path, rootfs_paths)
+
+
+@pytest.fixture
+def machine_on_ipmi(prepare_netboot: None) -> Generator[IPMI]:
+ ipmi = IPMI(
+ hostname=os.environ['IPMI_HOSTNAME'],
+ username=os.environ['MOON_CONSOLE_USER'],
+ password=os.environ['MOON_CONSOLE_PASS'],
+ blade_node=os.environ['IPMI_BLADE_NODE'],
+ )
+ ipmi.power_off()
+ ipmi.power_status()
+ ipmi.power_on()
+ yield ipmi
+ ipmi.power_off()
--
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 ` Anthony PERARD [this message]
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 ` [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-5-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.