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

Prepare and finish steps save results of their phases [Step results #4] #2979

Merged
merged 2 commits into from
Aug 15, 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
8 changes: 8 additions & 0 deletions tests/finish/basic/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ rlJournalStart
rlAssertNotExists "$tmp/cleanup-test"
rlPhaseEnd

rlPhaseStartTest "Verify prepare and finish step save results"
rlRun "tmt run -i $tmp --scratch provision prepare finish"
rlAssertExists "$tmp/prepare/results.yaml"
rlAssertEquals "Prepare results exists and it's empty" "$(cat $tmp/prepare/results.yaml)" "[]"
rlAssertExists "$tmp/finish/results.yaml"
rlAssertEquals "Finish results exists and it's empty" "$(cat $tmp/finish/results.yaml)" "[]"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Removing tmp directory"
Expand Down
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
14 changes: 12 additions & 2 deletions tmt/steps/finish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class Finish(tmt.steps.Step):

_plugin_base_class = FinishPlugin

_preserved_workdir_members = [
*tmt.steps.Step._preserved_workdir_members,
'results.yaml']

def wake(self) -> None:
""" Wake up the step (process workdir and command line) """
super().wake()
Expand Down Expand Up @@ -152,7 +156,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 +170,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 +183,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
14 changes: 12 additions & 2 deletions tmt/steps/prepare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class Prepare(tmt.steps.Step):

_plugin_base_class = PreparePlugin

_preserved_workdir_members = [
*tmt.steps.Step._preserved_workdir_members,
'results.yaml']

def __init__(
self,
*,
Expand Down Expand Up @@ -347,7 +351,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 +365,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 +378,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
Loading