iLO-manager first main commitgit status

This commit is contained in:
Jiří Stach committed 2026-02-03 15:56:53 +01:00
1 parent e6f4cc04ca
commit 599d8da562
3271 files changed
+550655

No files matched your search

Whitespace-only changes.
@@ -0,0 +1,139 @@
"""
conftest.py is used to set up shared fixtures, plugins, hooks, other config etc.
This is the conftest.py for integration tests
http://docs.pytest.org/en/latest/writing_plugins.html#conftest-py-local-per-directory-plugins
"""
from __future__ import absolute_import
import logging
import re
import sys
import pytest
from ..functional.conftest import RestClient, ilorest, test_server
from .ilocli import IloCli
from .ilodebug import IloDebugger
ilo_debug_logger = logging.getLogger('ilodebug')
vsp_logger = logging.getLogger('vsp')
def pytest_configure(config):
# configure logging
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
ilo_debug_file = config.getoption('--ilodebug')
if ilo_debug_file:
sys.stdout.write("logging iLO debugger output to: {}".format(ilo_debug_file))
ilo_debug_logger.setLevel(logging.DEBUG)
fh = logging.FileHandler(ilo_debug_file, mode='wb+')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
ilo_debug_logger.addHandler(fh)
vsp_file = config.getoption('--vsp')
if vsp_file:
sys.stdout.write("logging iLO Virtual Serial Port output to: {}".format(vsp_file))
vsp_logger.setLevel(logging.DEBUG)
fh = logging.FileHandler(vsp_file, mode='wb+')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
vsp_logger.addHandler(fh)
def pytest_runtest_makereport(item, call):
# incremental testing marker
if "incremental" in item.keywords:
if call.excinfo is not None:
parent = item.parent
parent._previousfailed = item
def pytest_runtest_setup(item):
# incremental testing marker
if "incremental" in item.keywords:
previousfailed = getattr(item.parent, "_previousfailed", None)
if previousfailed is not None:
pytest.xfail("previous test failed (%s)" % previousfailed.name)
@pytest.fixture(scope='session', autouse=True)
def clear_nand_counters(test_server, request):
"""Clear all iLO NAND write counters using the iLO debugger."""
if request.config.getoption('--clear-nand-counters'):
with IloDebugger(test_server.hostname) as ilo_debugger:
sys.stdout.write("Clearing all iLO NAND write counters (setting timers to max)")
output = ilo_debugger.run("otmax all")
assert "Set daily timer to MAX value" in output, \
"Failed to clear NAND write counters:\n {}".format(output)
@pytest.fixture
def ilodebug(test_server, request):
"""Start an iLO debugger session and log all output."""
if request.config.getoption('--ilodebug'):
test_path = request.node.nodeid.replace('::()::', '::')
ilo_debug_logger.info(test_path)
with IloDebugger(test_server.hostname) as ilo_debugger:
# get current system time
output = ilo_debugger.run('id')
ilo_debug_logger.debug(output)
yield ilo_debugger
output = ilo_debugger.read()
if output:
ilo_debug_logger.debug('\n' + output)
else:
yield
@pytest.fixture
def vsp(test_server, request, set_uefi_debug):
"""Start an iLO Virtual Serial Port session and log all output."""
if request.config.getoption('--vsp'):
test_path = request.node.nodeid.replace('::()::', '::')
vsp_logger.info(test_path)
hostname = test_server.hostname
username, password = test_server.username, test_server.password
with IloCli(hostname, username, password) as cli:
if cli is None:
yield
else:
# get current system time
cli.sendline("time")
with cli.vsp_session():
yield cli
output = cli.read()
if output:
vsp_logger.debug('\n' + output)
else:
yield
@pytest.fixture
def set_uefi_debug(test_server, request):
"""Temporarily set the UEFI serial debug level using the iLO debugger.
The debug levels are: 0 (Disabled), 1 (ErrorsOnly), 2 (Medium), 3 (Verbose).
"""
new_dbg = request.config.getoption('--uefi-debug-level')
if new_dbg is not None:
with IloDebugger(test_server.hostname) as debugger:
# save the current debug level
output = debugger.run("evs name cqhdbg")
match = re.search('EVS NAME "CQHDBG".+\n.+([0-9]{2})', output)
current_dbg = "0x{}".format(match.group(1)) if match else None
sys.stdout.write("setting UEFI serial debug level to {} (current {})".format(new_dbg, current_dbg))
debugger.run("evs xset cqhdbg {}".format(new_dbg))
yield
# restore previous debug level
if current_dbg:
with IloDebugger(test_server.hostname) as debugger:
debugger.run("evs xset cqhdbg {}".format(current_dbg))
else:
yield
@@ -0,0 +1,82 @@
from __future__ import absolute_import
import sys
import time
from contextlib import contextmanager
import paramiko
class IloCli(object):
"""Wrapper for the iLO CLI (SMASH CLP)."""
def __init__(self, hostname, username=None, password=None, port=22, timeout=10, window_size=None):
"""Initialize an iLO CLI instance.
:param hostname: iLO hostname
:param username: iLO username
:param password: iLO password
:param port: SSH port
:param window_size: window size for the SSH session (max is used if not specified)
:param timeout: connection timeout, in seconds
"""
self.hostname = hostname
self.username = username
self.password = password
self.port = port
self.timeout = timeout
self.window_size = window_size if window_size else paramiko.common.MAX_WINDOW_SIZE
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.channel = None
def open(self):
"""Start an interactive iLO CLI session."""
self.ssh.connect(self.hostname, username=self.username, password=self.password,
port=self.port, timeout=self.timeout, look_for_keys=False)
transport = self.ssh.get_transport()
self.channel = transport.open_session(window_size=self.window_size)
self.channel.get_pty()
self.channel.invoke_shell()
def close(self):
"""End the iLO CLI session."""
if self.channel:
self.channel.close()
self.ssh.close()
def __enter__(self):
for _ in range(5):
try:
self.open()
return self
except paramiko.SSHException:
sys.stdout.write("SSHException: retrying connection")
time.sleep(30)
sys.stdout.write("SSH: Max retries attempted. No vsp will be captured.")
return None
def __exit__(self, exc_type, exc_value, traceback):
self.close()
def read(self):
"""Read all available output without blocking I/O."""
buf = []
while self.channel.recv_ready():
data = self.channel.recv(1024)
buf.append(data)
return "".join(buf)
def send(self, data):
self.channel.send(data)
def sendline(self, data):
self.send(data + '\n')
@contextmanager
def vsp_session(self):
"""Start a Virtual Serial Port session, returning to the CLI afterward."""
self.sendline("vsp")
yield self
self.send("\x1B(") # press 'ESC ('
@@ -0,0 +1,61 @@
from __future__ import absolute_import
from telnetlib import Telnet
class IloDebugger(object):
DEBUG_PORT = 8
def __init__(self, hostname, timeout=10):
"""Initialize an iLO debugger instance.
:param hostname: hostname of the iLO server
:param timeout: connection timeout, in seconds
"""
self.hostname = hostname
self.timeout = timeout
self.tn = None
self.prompt = '\r\n>'
def open(self):
"""Connect to the iLO debugger."""
self.tn = Telnet(self.hostname, self.DEBUG_PORT, self.timeout)
# wait until the debugger is ready and clear initial output
self.read_until(self.prompt)
def close(self):
"""Close the connection."""
if self.tn:
self.tn.close()
self.tn = None
def __enter__(self):
self.open()
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
def read(self):
"""Read all available output without blocking I/O."""
output = self.tn.read_very_eager()
# debugger occasionally outputs CRLFs with double CRs - just convert all to LFs
output = output.replace('\r', '')
return output
def read_until(self, expected, timeout=10):
"""Read until an expected string is encountered or the timeout, in seconds, has been reached."""
output = self.tn.read_until(expected, timeout)
output = output.replace('\r', '')
return output
def writeline(self, line):
"""Write a line to the iLO debugger."""
self.tn.write(line + '\n')
def run(self, cmd_line):
"""Run an iLO debugger command and capture output."""
self.read() # clear any previous output
self.writeline(cmd_line)
output = self.read_until(self.prompt)
return output