tmt.checks package

Submodules

tmt.checks.avc module

tmt.checks.avc.AUSEARCH_TIMESTAMP_FILENAME = 'avc-timestamp.sh'

The filename of the file storing “since” timestamp for ausearch on the guest.

class tmt.checks.avc.AvcDenials(*args: Any, **kwargs: Any)

Bases: CheckPlugin[Check]

Check for SELinux AVC denials raised during the test.

The check collects SELinux AVC denials from the audit log, gathers details about them, and together with versions of the selinux-policy and related packages stores them in a report file after the test.

check:
  - name: avc

New in version 1.28.

classmethod after_test(*, check: Check, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list[tmt.result.CheckResult]
classmethod before_test(*, check: Check, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list[tmt.result.CheckResult]
classmethod essential_requires(guest: Guest, test: tmt.base.Test, logger: Logger) list['tmt.base.DependencySimple']

Collect all essential requirements of the test check.

Essential requirements of a check are necessary for the check to perform its basic functionality.

Returns:

a list of requirements.

tmt.checks.avc.INTERESTING_PACKAGES = ['audit', 'selinux-policy']

Packages related to selinux and AVC reporting. Their versions would be made part of the report.

tmt.checks.avc.TEST_POST_AVC_FILENAME = 'avc.txt'

The filename of the final check report file.

tmt.checks.avc.create_ausearch_timestamp(invocation: TestInvocation, logger: Logger) None

Save a timestamp for ausearch in a file on the guest

tmt.checks.avc.create_final_report(invocation: TestInvocation, logger: Logger) tuple[tmt.result.ResultOutcome, tmt.utils.Path]

Collect the data, evaluate and create the final report

tmt.checks.dmesg module

class tmt.checks.dmesg.DmesgCheck(*args: Any, **kwargs: Any)

Bases: CheckPlugin[Check]

Save the content of kernel ring buffer (aka “console”) into a file.

The check saves one file before the test, and then again when test finishes.

check:
  - name: dmesg

New in version 1.28.

classmethod after_test(*, check: Check, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list[tmt.result.CheckResult]
classmethod before_test(*, check: Check, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list[tmt.result.CheckResult]
classmethod essential_requires(guest: Guest, test: tmt.base.Test, logger: Logger) list['tmt.base.DependencySimple']

Collect all essential requirements of the test check.

Essential requirements of a check are necessary for the check to perform its basic functionality.

Returns:

a list of requirements.

tmt.checks.watchdog module

class tmt.checks.watchdog.GuestContext(ping_failures: int = 0, ssh_ping_failures: int = 0, thread: Thread | None = None, keep_running: bool = True)

Bases: object

Per-guest watchdog context

keep_running: bool = True

As long as this field is set to True, the watchdog will run its internal loop and run relevant checks. It is unset when terminating the watchdog check to notify the thread it’s time to quit.

ping_failures: int = 0

Current number of failed watchdog checks.

ssh_ping_failures: int = 0
thread: Thread | None = None

If set, contains a daemonized thread running the watchdog checks.

class tmt.checks.watchdog.Watchdog(*args: Any, **kwargs: Any)

Bases: CheckPlugin[WatchdogCheck]

Take various actions when guest becomes unresponsive.

Watchdog runs selected probes every now and then, and when a given number of probes fail, watchdog would run one or more of the predefined actions.

Check comes with two probes, “ping” and “SSH ping”, and single action, “reboot”.

  • “ping” uses the classic ICMP echo to check whether the guest is still up and running,

  • “SSH ping” tries to establish SSH connection,

  • “reboot” action issues a hard reboot of the guest.

Each probe has a “budget” of allowed failures, and when it runs out, the action is taken. A successfull probe replenishes its budget to the original level.

Multiple probes can be enabled at the same time, for the action to happen it’s enough if just one of them runs out of its budget.

check:
  - how: watchdog
    ping: true
    reboot: true
check:
  - how: watchdog

    # Use only SSH ping.
    ping: false
    ssh-ping: true

    # Try every 5 minutes, allow 7 failed attempts, and reboot
    # the guest when we run out of attempts.
    interval: 300
    reboot: true
    ssh-ping-threshold: 7

New in version 1.32.

classmethod after_test(*, check: WatchdogCheck, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list[tmt.result.CheckResult]
classmethod before_test(*, check: WatchdogCheck, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list[tmt.result.CheckResult]
class tmt.checks.watchdog.WatchdogCheck(how: str, enabled: bool = True, interval: int = 60, reboot: bool = False, ping: bool = False, ping_packets: int = 1, ping_threshold: int = 10, ssh_ping: bool = False, ssh_ping_threshold: int = 10)

Bases: Check

do_ping(invocation: TestInvocation, guest_context: GuestContext, logger: Logger) None

Perform a ping check

do_ssh_ping(invocation: TestInvocation, guest_context: GuestContext, logger: Logger) None

Perform a “SSH ping” check

interval: int = 60
notify(invocation: TestInvocation, logger: Logger) None

Notify invocation that hard reboot is required

ping: bool = False
ping_packets: int = 1
ping_threshold: int = 10
reboot: bool = False
ssh_ping: bool = False
ssh_ping_threshold: int = 10
tmt.checks.watchdog.render_report_path(invocation: TestInvocation) Path

Render path to a watchdog report file from necessary components

tmt.checks.watchdog.report_progress(log: Path, check_name: str, report: Iterable[str], command_output: str | None = None) None

Add new report into a report file.

Parameters:
  • log – path to the report file.

  • report – iterable of report lines to add. Each line is emitted on its own line in the file.

  • command_output – if set, the string is added to the report file once report lines are written into it.

Module contents

class tmt.checks.Check(how: str, enabled: bool = True)

Bases: SpecBasedContainer[_RawCheck, _RawCheck], SerializableContainer, NormalizeKeysMixin

Represents a single check from test’s check field.

Serves as a link between raw fmf/CLI specification and an actual check implementation/plugin.

enabled: bool = True
classmethod from_spec(raw_data: _RawCheck, logger: Logger) Check

Convert from a specification file or from a CLI option

See https://tmt.readthedocs.io/en/stable/classes.html#class-conversions for more details.

See to_spec() for its counterpart.

go(*, event: CheckEvent, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list['CheckResult']

Run the check.

Parameters:
  • event – when the check is running - before the test, after the test, etc.

  • invocation – test invocation to which the check belongs to.

  • environment – optional environment to set for the check.

  • logger – logger to use for logging.

Returns:

list of results produced by checks.

how: str
plugin
to_spec() _RawCheck

Convert to a form suitable for saving in a specification file

See https://tmt.readthedocs.io/en/stable/classes.html#class-conversions for more details.

See from_spec() for its counterpart.

class tmt.checks.CheckEvent(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Events in test runtime when a check can be executed

AFTER_TEST = 'after-test'
BEFORE_TEST = 'before-test'
classmethod from_spec(spec: str) CheckEvent
class tmt.checks.CheckPlugin(*args: Any, **kwargs: Any)

Bases: _CommonBase, Generic[CheckT]

Base class for plugins providing extra checks before, during and after tests

classmethod after_test(*, check: CheckT, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list['CheckResult']
classmethod before_test(*, check: CheckT, invocation: TestInvocation, environment: Environment | None = None, logger: Logger) list['CheckResult']
classmethod delegate(*, raw_data: _RawCheck, logger: Logger) Check

Create a check data instance for the plugin

classmethod essential_requires(guest: Guest, test: tmt.base.Test, logger: Logger) list['tmt.base.DependencySimple']

Collect all essential requirements of the test check.

Essential requirements of a check are necessary for the check to perform its basic functionality.

Returns:

a list of requirements.

class tmt.checks.CheckT

A type variable representing a Check instances.

alias of TypeVar(‘CheckT’, bound=Check)

tmt.checks.find_plugin(name: str) type[tmt.checks.CheckPlugin[Any]]

Find a plugin by its name.

Raises:

GeneralError – when the plugin does not exist.

tmt.checks.normalize_test_check(key_address: str, raw_test_check: Any, logger: Logger) Check

Normalize a single test check

tmt.checks.normalize_test_checks(key_address: str, raw_checks: Any, logger: Logger) list[tmt.checks.Check]

Normalize (prepare/finish/test) checks

tmt.checks.provides_check(check: str) Callable[[type[tmt.checks.CheckPlugin[Any]]], type[tmt.checks.CheckPlugin[Any]]]

A decorator for registering test checks.

Decorate a test check plugin class to register its checks.