Skip to content

Commit

Permalink
Move container stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Oct 9, 2024
1 parent 5d6b90d commit c0ac303
Show file tree
Hide file tree
Showing 37 changed files with 959 additions and 934 deletions.
24 changes: 13 additions & 11 deletions docs/scripts/generate-plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

import tmt.checks
import tmt.container
import tmt.log
import tmt.plugins
import tmt.steps
Expand All @@ -16,7 +17,8 @@
import tmt.steps.provision
import tmt.steps.report
import tmt.utils
from tmt.utils import ContainerClass, Path
from tmt.container import ContainerClass
from tmt.utils import Path
from tmt.utils.templates import render_template_file

REVIEWED_PLUGINS: tuple[str, ...] = (
Expand All @@ -36,7 +38,7 @@
def _is_ignored(
container: ContainerClass,
field: dataclasses.Field[Any],
metadata: tmt.utils.FieldMetadata) -> bool:
metadata: tmt.container.FieldMetadata) -> bool:
""" Check whether a given field is to be ignored in documentation """

if field.name in ('how', '_OPTIONLESS_FIELDS'):
Expand All @@ -51,7 +53,7 @@ def _is_ignored(
def _is_inherited(
container: ContainerClass,
field: dataclasses.Field[Any],
metadata: tmt.utils.FieldMetadata) -> bool:
metadata: tmt.container.FieldMetadata) -> bool:
""" Check whether a given field is inherited from step data base class """

# TODO: for now, it's a list, but inspecting the actual tree of classes
Expand All @@ -64,8 +66,8 @@ def container_ignored_fields(container: ContainerClass) -> list[str]:

field_names: list[str] = []

for field in tmt.utils.container_fields(container):
_, _, _, _, metadata = tmt.utils.container_field(container, field.name)
for field in tmt.container.container_fields(container):
_, _, _, _, metadata = tmt.container.container_field(container, field.name)

if _is_ignored(container, field, metadata):
field_names.append(field.name)
Expand All @@ -78,8 +80,8 @@ def container_inherited_fields(container: ContainerClass) -> list[str]:

field_names: list[str] = []

for field in tmt.utils.container_fields(container):
_, _, _, _, metadata = tmt.utils.container_field(container, field.name)
for field in tmt.container.container_fields(container):
_, _, _, _, metadata = tmt.container.container_field(container, field.name)

if _is_inherited(container, field, metadata):
field_names.append(field.name)
Expand All @@ -92,8 +94,8 @@ def container_intrinsic_fields(container: ContainerClass) -> list[str]:

field_names: list[str] = []

for field in tmt.utils.container_fields(container):
_, _, _, _, metadata = tmt.utils.container_field(container, field.name)
for field in tmt.container.container_fields(container):
_, _, _, _, metadata = tmt.container.container_field(container, field.name)

if _is_ignored(container, field, metadata):
continue
Expand Down Expand Up @@ -184,8 +186,8 @@ def main() -> None:
STEP=step_name,
PLUGINS=plugin_generator,
REVIEWED_PLUGINS=REVIEWED_PLUGINS,
container_fields=tmt.utils.container_fields,
container_field=tmt.utils.container_field,
container_fields=tmt.container.container_fields,
container_field=tmt.container.container_field,
container_ignored_fields=container_ignored_fields,
container_inherited_fields=container_inherited_fields,
container_intrinsic_fields=container_intrinsic_fields))
Expand Down
31 changes: 17 additions & 14 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
import tmt.utils.git
import tmt.utils.jira
from tmt.checks import Check
from tmt.container import (
SerializableContainer,
SpecBasedContainer,
container,
container_field,
container_fields,
field,
)
from tmt.lint import LinterOutcome, LinterReturn
from tmt.result import Result, ResultInterpret
from tmt.utils import (
Expand All @@ -64,14 +72,9 @@
EnvVarValue,
FmfContext,
Path,
SerializableContainer,
ShellScript,
SpecBasedContainer,
WorkdirArgumentType,
container_field,
container_fields,
dict_to_yaml,
field,
normalize_shell_script,
verdict,
)
Expand Down Expand Up @@ -137,7 +140,7 @@ class _RawFmfId(TypedDict, total=False):


# An internal fmf id representation.
@dataclasses.dataclass
@container
class FmfId(
SpecBasedContainer[_RawFmfId, _RawFmfId],
SerializableContainer,
Expand Down Expand Up @@ -411,7 +414,7 @@ class _RawDependencyFmfId(_RawFmfId):
type: Optional[str]


@dataclasses.dataclass
@container
class DependencyFmfId(
FmfId,
# Repeat the SpecBasedContainer, with more fitting in/out spec type.
Expand Down Expand Up @@ -500,7 +503,7 @@ class _RawDependencyFile(TypedDict):
pattern: Optional[list[str]]


@dataclasses.dataclass
@container
class DependencyFile(
SpecBasedContainer[_RawDependencyFile, _RawDependencyFile],
SerializableContainer,
Expand Down Expand Up @@ -649,7 +652,7 @@ def _normalize_link(key_address: str, value: _RawLinks, logger: tmt.log.Logger)
return Links(data=value)


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Core(
tmt.utils.ValidateFmfMixin,
tmt.utils.LoadFmfKeysMixin,
Expand Down Expand Up @@ -1030,7 +1033,7 @@ def has_link(self, needle: 'LinkNeedle') -> bool:
Node = Core


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Test(
Core,
tmt.export.Exportable['Test'],
Expand Down Expand Up @@ -1651,7 +1654,7 @@ def expand_node_data(data: T, fmf_context: FmfContext) -> T:
return data


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Plan(
Core,
tmt.export.Exportable['Plan'],
Expand Down Expand Up @@ -2594,7 +2597,7 @@ def __str__(self) -> str:
return self.value


@dataclasses.dataclass(repr=False)
@container(repr=False)
class Story(
Core,
tmt.export.Exportable['Story'],
Expand Down Expand Up @@ -3331,7 +3334,7 @@ def init(
logger=logger)


@dataclasses.dataclass
@container
class RunData(SerializableContainer):
root: Optional[str]
plans: Optional[list[str]]
Expand Down Expand Up @@ -4084,7 +4087,7 @@ def matches(self, link: 'Link') -> bool:
return False


@dataclasses.dataclass
@container
class Link(SpecBasedContainer[Any, _RawLinkRelation]):
"""
An internal "link" as defined by tmt specification.
Expand Down
13 changes: 7 additions & 6 deletions tmt/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import dataclasses
import enum
import functools
from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypedDict, TypeVar, cast

import tmt.log
import tmt.steps.provision
import tmt.utils
from tmt.plugins import PluginRegistry
from tmt.utils import (
NormalizeKeysMixin,
from tmt.container import (
SerializableContainer,
SpecBasedContainer,
container,
field,
key_to_option,
)
from tmt.plugins import PluginRegistry
from tmt.utils import NormalizeKeysMixin

if TYPE_CHECKING:
import tmt.base
Expand Down Expand Up @@ -83,7 +84,7 @@ def from_spec(cls, spec: str) -> 'CheckEvent':
raise tmt.utils.SpecificationError(f"Invalid test check event '{spec}'.")


@dataclasses.dataclass
@container
class Check(
SpecBasedContainer[_RawCheck, _RawCheck],
SerializableContainer,
Expand Down Expand Up @@ -118,7 +119,7 @@ def from_spec( # type: ignore[override]

def to_spec(self) -> _RawCheck:
return cast(_RawCheck, {
tmt.utils.key_to_option(key): value
key_to_option(key): value
for key, value in self.items()
})

Expand Down
6 changes: 3 additions & 3 deletions tmt/checks/dmesg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
import datetime
import re
from re import Pattern
Expand All @@ -9,9 +8,10 @@
import tmt.steps.provision
import tmt.utils
from tmt.checks import Check, CheckEvent, CheckPlugin, _RawCheck, provides_check
from tmt.container import container, field
from tmt.result import CheckResult, ResultOutcome
from tmt.steps.provision import GuestCapability
from tmt.utils import Path, field, format_timestamp, render_run_exception_streams
from tmt.utils import Path, format_timestamp, render_run_exception_streams

if TYPE_CHECKING:
import tmt.base
Expand All @@ -29,7 +29,7 @@
]


@dataclasses.dataclass
@container
class DmesgCheck(Check):
failure_pattern: list[Pattern[str]] = field(
default_factory=lambda: DEFAULT_FAILURE_PATTERNS[:],
Expand Down
5 changes: 3 additions & 2 deletions tmt/checks/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import tmt.steps.provision.testcloud
import tmt.utils
from tmt.checks import Check, CheckPlugin, provides_check
from tmt.container import container, field
from tmt.result import CheckResult, ResultOutcome
from tmt.utils import Path, field, format_timestamp, render_run_exception_streams
from tmt.utils import Path, format_timestamp, render_run_exception_streams

if TYPE_CHECKING:
from tmt.steps.execute import TestInvocation
Expand Down Expand Up @@ -101,7 +102,7 @@ class GuestContext:
keep_running: bool = True


@dataclasses.dataclass
@container
class WatchdogCheck(Check):
interval: int = field(
default=60,
Expand Down
Loading

0 comments on commit c0ac303

Please sign in to comment.