Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add essential requirements to checks #2684

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tmt/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tmt.base
from tmt.result import CheckResult
from tmt.steps.execute import TestInvocation
from tmt.steps.provision import Guest


#: A type variable representing a :py:class:`Check` instances.
Expand Down Expand Up @@ -180,6 +181,23 @@ def delegate(
return cast(CheckPlugin[CheckT], find_plugin(raw_data['how'])) \
._check_class.from_spec(raw_data, logger)

@classmethod
def essential_requires(
cls,
guest: 'Guest',
test: 'tmt.base.Test',
logger: tmt.log.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.
"""

return []

@classmethod
def before_test(
cls,
Expand Down
19 changes: 19 additions & 0 deletions tmt/checks/avc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from tmt.utils import CommandOutput, Path, ShellScript, render_run_exception_streams

if TYPE_CHECKING:
import tmt.base
from tmt.steps.execute import TestInvocation
from tmt.steps.provision import Guest

#: The filename of the final check report file.
TEST_POST_AVC_FILENAME = 'avc.txt'
Expand Down Expand Up @@ -285,6 +287,23 @@ class AvcDenials(CheckPlugin[Check]):

_check_class = Check

@classmethod
def essential_requires(
cls,
guest: 'Guest',
test: 'tmt.base.Test',
logger: tmt.log.Logger) -> list['tmt.base.DependencySimple']:
if not guest.facts.has_selinux:
return []

# Avoid circular imports
import tmt.base

return [
tmt.base.DependencySimple('/usr/bin/sestatus'),
tmt.base.DependencySimple('/usr/sbin/ausearch')
]

@classmethod
def before_test(
cls,
Expand Down
16 changes: 16 additions & 0 deletions tmt/checks/dmesg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from tmt.utils import Path, render_run_exception_streams

if TYPE_CHECKING:
import tmt.base
from tmt.steps.execute import TestInvocation
from tmt.steps.provision import Guest

TEST_POST_DMESG_FILENAME = 'dmesg-{event}.txt'
FAILURE_PATTERNS = [
Expand Down Expand Up @@ -42,6 +44,20 @@ class DmesgCheck(CheckPlugin[Check]):

_check_class = Check

@classmethod
def essential_requires(
cls,
guest: 'Guest',
test: 'tmt.base.Test',
logger: tmt.log.Logger) -> list['tmt.base.DependencySimple']:
if not guest.facts.has_capability(GuestCapability.SYSLOG_ACTION_READ_ALL):
return []

# Avoid circular imports
import tmt.base

return [tmt.base.DependencySimple('/usr/bin/dmesg')]

@classmethod
def _fetch_dmesg(
cls,
Expand Down
6 changes: 6 additions & 0 deletions tmt/steps/prepare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ def as_key(self) -> frozenset['tmt.base.DependencySimple']:
test,
self._logger)

for check in test.check:
collected_requires[guest].dependencies += check.plugin.essential_requires(
guest,
test,
self._logger)

# Now we have guests and all their requirements. There can be
# duplicities, multiple tests requesting the same package, but also
# some guests may share the set of packages to be installed on them.
Expand Down
Loading