pytest_mh.utils.journald

Classes

JournaldUtils(*args, **kwargs)

Perform journald related tasks.

class pytest_mh.utils.journald.JournaldUtils(*args, **kwargs)

Bases: MultihostUtility[MultihostHost]

Perform journald related tasks.

Parameters:

host (MultihostHost) – Remote host instance.

property now: str
Returns:

Current date and time that can be used to filter the journal.

Return type:

str

setup() None

Called before execution of each test.

get_artifacts_list(host: MultihostHost, artifacts_type: Literal['pytest_setup', 'pytest_teardown', 'topology_setup', 'topology_teardown', 'test']) set[str]

Dump journald into file that can be collected.

Parameters:
  • host (MultihostHost) – Host where the artifacts are being collected.

  • artifacts_type (MultihostArtifactsType) – Type of artifacts that are being collected.

Returns:

List of artifacts to collect.

Return type:

set[str]

clear() None

Reset timestamp

journalctl(current: bool = True, *, unit: str | None = None, lines: int | None = None, since: str | None = None, reverse: bool = False, grep: str | None = None, output: str | None = None, identifier: str | None = None, system: bool = False, user: bool = False, args: list[Any] | None = None) ProcessResult

Execute journalctl with given arguments. Show messages only for current test run, by default. Note that raise_on_error is False and the command may return non-zero return code.

Parameters:
  • current (bool, optional) – Show messages only for current test run, defaults to True

  • unit (str | None, optional) – Show messages for the specified systemd unit, defaults to None

  • lines (int | None, optional) – Show the most recent journal events and limit the number of events shown, defaults to None

  • since (str | None, optional) – Start showing entries on or newer than the specified date, defaults to None

  • reverse (bool, optional) – Reverse output so that the newest entries are displayed first, defaults to False

  • grep (str | None, optional) – Filter output to entries where the MESSAGE= field matches specified regex, defaults to None

  • output (str | None, optional) – Controls the formatting of the journal entries, defaults to None

  • identifier (str | None, optional) – Show messages for the specified syslog identifier SYSLOG_IDENTIFIER, defaults to None

  • system (bool, optional) – Show messages from system services and the kernel, defaults to False

  • user (bool, optional) – Show messages from service of current user, defaults to False

  • args (list[Any] | None, optional) – Additional options, defaults to None

Returns:

SSH process result

Return type:

ProcessResult

is_match(pattern: str, unit: str | None = None) bool

Search the logs for a pattern.

Parameters:
  • pattern (str) – Pattern to be searched for

  • unit (str | None, optional) – Search only messages for given systemd unit, defaults to None

Returns:

True, if pattern found

Return type:

bool

count(pattern: str, unit: str | None = None) int

Search the logs for a pattern and return number of occurrences.

Parameters:
  • pattern (str) – Pattern to be searched for

  • unit (str | None, optional) – Search only messages for given systemd unit, defaults to None

Returns:

Number of occurrences of the pattern

Return type:

int