Skip to content

Commit

Permalink
Prepare and finish steps save results of their phases
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Aug 6, 2024
1 parent d315345 commit d362ba0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion tmt/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,8 @@ def run(self, logger: tmt.log.Logger) -> None:


@dataclasses.dataclass
class PluginTask(tmt.queue.MultiGuestTask[None], Generic[StepDataT, PluginReturnValueT]):
class PluginTask(tmt.queue.MultiGuestTask[PluginReturnValueT],
Generic[StepDataT, PluginReturnValueT]):
""" A task to run a phase on a given set of guests """

phase: Plugin[StepDataT, PluginReturnValueT]
Expand Down
10 changes: 8 additions & 2 deletions tmt/steps/finish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def go(self, force: bool = False) -> None:

guest_copies.append(guest_copy)

queue: PhaseQueue[FinishStepData, None] = PhaseQueue(
queue: PhaseQueue[FinishStepData, list[PhaseResult]] = PhaseQueue(
'finish',
self._logger.descend(logger_name=f'{self}.queue'))

Expand All @@ -166,7 +166,8 @@ def go(self, force: bool = False) -> None:
guests=[guest for guest in guest_copies if phase.enabled_on_guest(guest)]
)

failed_tasks: list[Union[ActionTask, PluginTask[FinishStepData, None]]] = []
failed_tasks: list[Union[ActionTask, PluginTask[FinishStepData, list[PhaseResult]]]] = []
results: list[PhaseResult] = []

for outcome in queue.run():
if not isinstance(outcome.phase, FinishPlugin):
Expand All @@ -178,6 +179,11 @@ def go(self, force: bool = False) -> None:
failed_tasks.append(outcome)
continue

if outcome.result:
results += outcome.result

self._save_results(results)

if failed_tasks:
raise tmt.utils.GeneralError(
'finish step failed',
Expand Down
10 changes: 8 additions & 2 deletions tmt/steps/prepare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def as_key(self) -> frozenset['tmt.base.DependencySimple']:
# To separate "push" from "prepare" queue visually
self.info('')

queue: PhaseQueue[PrepareStepData, None] = PhaseQueue(
queue: PhaseQueue[PrepareStepData, list[PhaseResult]] = PhaseQueue(
'prepare',
self._logger.descend(logger_name=f'{self}.queue'))

Expand All @@ -361,7 +361,8 @@ def as_key(self) -> frozenset['tmt.base.DependencySimple']:
guests=[
guest for guest in guest_copies if prepare_phase.enabled_on_guest(guest)])

failed_tasks: list[Union[ActionTask, PluginTask[PrepareStepData, None]]] = []
failed_tasks: list[Union[ActionTask, PluginTask[PrepareStepData, list[PhaseResult]]]] = []
results: list[PhaseResult] = []

for outcome in queue.run():
if not isinstance(outcome.phase, PreparePlugin):
Expand All @@ -373,8 +374,13 @@ def as_key(self) -> frozenset['tmt.base.DependencySimple']:
failed_tasks.append(outcome)
continue

if outcome.result:
results += outcome.result

self.preparations_applied += 1

self._save_results(results)

if failed_tasks:
# TODO: needs a better message...
raise tmt.utils.GeneralError(
Expand Down

0 comments on commit d362ba0

Please sign in to comment.