Skip to content

Commit

Permalink
Introduce "phase result" for prepare/finish plugins to return
Browse files Browse the repository at this point in the history
No plugin returns it yet, not any of the results is saved, the patch
changes return value types and adds the structure itself.
  • Loading branch information
happz committed Jun 2, 2024
1 parent 35b80aa commit 9ab154f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 18 deletions.
5 changes: 5 additions & 0 deletions tmt/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class CheckResult(BaseResult):
unserialize=CheckEvent.from_spec)


@dataclasses.dataclass
class PhaseResult(BaseResult):
""" Describes what tmt knows about a single phase result """


@dataclasses.dataclass
class Result(BaseResult):
""" Describes what tmt knows about a single test result """
Expand Down
7 changes: 5 additions & 2 deletions tmt/steps/finish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tmt.steps
from tmt.options import option
from tmt.plugins import PluginRegistry
from tmt.result import PhaseResult
from tmt.steps import (
Action,
ActionTask,
Expand All @@ -32,7 +33,7 @@ class FinishStepData(tmt.steps.WhereableStepData, tmt.steps.StepData):
FinishStepDataT = TypeVar('FinishStepDataT', bound=FinishStepData)


class FinishPlugin(tmt.steps.Plugin[FinishStepDataT, None]):
class FinishPlugin(tmt.steps.Plugin[FinishStepDataT, list[PhaseResult]]):
""" Common parent of finish plugins """

# ignore[assignment]: as a base class, FinishStepData is not included in
Expand Down Expand Up @@ -71,9 +72,11 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
self.go_prolog(logger)

return []


class Finish(tmt.steps.Step):
"""
Expand Down
7 changes: 5 additions & 2 deletions tmt/steps/finish/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tmt.steps
import tmt.steps.finish
import tmt.utils
from tmt.result import PhaseResult
from tmt.steps import safe_filename
from tmt.steps.provision import Guest
from tmt.utils import ShellScript, field
Expand Down Expand Up @@ -63,9 +64,9 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Perform finishing tasks on given guest """
super().go(guest=guest, environment=environment, logger=logger)
results = super().go(guest=guest, environment=environment, logger=logger)

# Give a short summary
overview = fmf.utils.listed(self.data.script, 'script')
Expand Down Expand Up @@ -96,3 +97,5 @@ def go(
else:
command = tmt.utils.ShellScript(f'{finish_wrapper_path}')
guest.execute(command, cwd=workdir)

return results
7 changes: 5 additions & 2 deletions tmt/steps/prepare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import tmt.utils
from tmt.options import option
from tmt.plugins import PluginRegistry
from tmt.result import PhaseResult
from tmt.steps import (
Action,
ActionTask,
Expand Down Expand Up @@ -51,7 +52,7 @@ class _RawPrepareStepData(tmt.steps._RawStepData, total=False):
summary: str


class PreparePlugin(tmt.steps.Plugin[PrepareStepDataT, None]):
class PreparePlugin(tmt.steps.Plugin[PrepareStepDataT, list[PhaseResult]]):
""" Common parent of prepare plugins """

# ignore[assignment]: as a base class, PrepareStepData is not included in
Expand Down Expand Up @@ -90,7 +91,7 @@ def go(
*,
guest: 'tmt.steps.provision.Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Prepare the guest (common actions) """

self.go_prolog(logger)
Expand All @@ -103,6 +104,8 @@ def go(
if self.data.where:
logger.info('where', fmf.utils.listed(self.data.where), 'green')

return []


class Prepare(tmt.steps.Step):
"""
Expand Down
7 changes: 5 additions & 2 deletions tmt/steps/prepare/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tmt.steps
import tmt.steps.prepare
import tmt.utils
from tmt.result import PhaseResult
from tmt.steps.provision import Guest
from tmt.utils import Path, PrepareError, field, retry_session

Expand Down Expand Up @@ -123,9 +124,9 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Prepare the guests """
super().go(guest=guest, environment=environment, logger=logger)
results = super().go(guest=guest, environment=environment, logger=logger)

# Apply each playbook on the guest
for playbook in self.data.playbook:
Expand Down Expand Up @@ -166,3 +167,5 @@ def go(
logger.info('playbook-path', playbook_path, 'green')

guest.ansible(playbook_path, extra_args=self.data.extra_args)

return results
7 changes: 5 additions & 2 deletions tmt/steps/prepare/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tmt.steps.prepare
import tmt.utils
from tmt.package_managers import Package
from tmt.result import PhaseResult
from tmt.steps.prepare import PreparePlugin, _RawPrepareStepData
from tmt.steps.provision import Guest
from tmt.utils import Command, Path, field, uniq
Expand Down Expand Up @@ -171,10 +172,10 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Prepare the guests for building rpm sources """

super().go(guest=guest, environment=environment, logger=logger)
results = super().go(guest=guest, environment=environment, logger=logger)

environment = environment or tmt.utils.Environment()

Expand Down Expand Up @@ -291,3 +292,5 @@ def go(
# Inject additional install plugins - recommend
if collected_recommends and self.future_recommends:
self.future_recommends.data.package = uniq(collected_recommends)

return results
9 changes: 6 additions & 3 deletions tmt/steps/prepare/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tmt.steps
import tmt.steps.prepare
import tmt.utils
from tmt.result import PhaseResult
from tmt.steps.provision import Guest
from tmt.utils import Path, field

Expand Down Expand Up @@ -127,13 +128,13 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Prepare the guests """
super().go(guest=guest, environment=environment, logger=logger)
results = super().go(guest=guest, environment=environment, logger=logger)

# Nothing to do in dry mode
if self.opt('dry'):
return
return []

# Enable or disable epel
for feature_key in _FEATURES:
Expand All @@ -152,3 +153,5 @@ def go(
raise tmt.utils.GeneralError(f"Unknown feature setting '{value}'.")
else:
raise tmt.utils.GeneralError(f"Unsupported feature '{feature_key}'.")

return results
9 changes: 6 additions & 3 deletions tmt/steps/prepare/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PackagePath,
PackageUrl,
)
from tmt.result import PhaseResult
from tmt.steps.provision import Guest
from tmt.utils import Command, Path, ShellScript, field

Expand Down Expand Up @@ -644,13 +645,13 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Perform preparation for the guests """
super().go(guest=guest, environment=environment, logger=logger)
results = super().go(guest=guest, environment=environment, logger=logger)

# Nothing to do in dry mode
if self.is_dry_run:
return
return results

# Pick the right implementation
# TODO: it'd be nice to use a "plugin registry" and make the
Expand Down Expand Up @@ -726,3 +727,5 @@ def go(

# ... and install packages.
installer.install()

return results
7 changes: 5 additions & 2 deletions tmt/steps/prepare/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tmt.steps
import tmt.steps.prepare
import tmt.utils
from tmt.result import PhaseResult
from tmt.steps import safe_filename
from tmt.steps.provision import Guest
from tmt.utils import ShellScript, field
Expand Down Expand Up @@ -62,9 +63,9 @@ def go(
*,
guest: 'Guest',
environment: Optional[tmt.utils.Environment] = None,
logger: tmt.log.Logger) -> None:
logger: tmt.log.Logger) -> list[PhaseResult]:
""" Prepare the guests """
super().go(guest=guest, environment=environment, logger=logger)
results = super().go(guest=guest, environment=environment, logger=logger)

environment = environment or tmt.utils.Environment()

Expand Down Expand Up @@ -112,3 +113,5 @@ def go(
command=command,
cwd=workdir,
env=environment)

return results

0 comments on commit 9ab154f

Please sign in to comment.