Iker Pedrosa 128650dfd4 Tests: implement system test framework
As discussed at length, this is the implementation of the new system
tests framework for shadow. This is a proof of concept that contains the
key elements to be able to run basic user (i.e. useradd, usermod) and
group (i.e. usermod) tests. If you like the framework the rest of the
functionality will be added in the future.

Some useful facts:
* It is implemented in python
* It is based on pytest and pytest-mh
* It works on all the distributions that are part of our CI
* It can be run in the cloud (VM or container) as well as on-premises
* After the execution of each test the environment is cleaned up
* Logs and other artifacts for failed tests are collected
* It has a rich API that can be extended and extended to cover new
  functionalities

Closes: https://github.com/shadow-maint/shadow/issues/835

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00

43 lines
1.2 KiB
Python

from __future__ import annotations
class ExpectScriptError(Exception):
"""
Expect script error.
Seeing this exception means that there is an unhandled path or other error
in the expect script that was executed. The script needs to be fixed.
"""
def __init__(self, code: int, msg: str | None = None) -> None:
"""
:param code: Expect script error code.
:type code: int
:param msg: Error message, defaults to None (translate error code to message)
:type msg: str | None, optional
"""
self.code: int = code
if msg is None:
msg = self.code_to_message(code)
super().__init__(msg)
def code_to_message(self, code: int) -> str:
"""
Translate expect script error codes used in this framework to message.
:param code: Expect script error code.
:type code: int
:return: Error message.
:rtype: str
"""
match code:
case 201:
return "Timeout, unexpected output"
case 202:
return "Unexpected end of file"
case 203:
return "Unexpected code path"
return "Unknown error code"