diff --git a/tmt/base/core.py b/tmt/base/core.py index b08da78511..a59342a475 100644 --- a/tmt/base/core.py +++ b/tmt/base/core.py @@ -2923,8 +2923,8 @@ def __init__( self.policies = policies or [] self.recipe_manager = RecipeManager(logger) self.recipe = None - if recipe_path is not None and self._tree is not None: - self.recipe = self.recipe_manager.load(self, recipe_path, self._tree.tree) + if recipe_path is not None: + self.recipe = self.recipe_manager.load(self, recipe_path) @property def run_workdir(self) -> Path: diff --git a/tmt/recipe.py b/tmt/recipe.py index 783101bc9f..5ff2adae54 100644 --- a/tmt/recipe.py +++ b/tmt/recipe.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Callable, Optional, TypedDict, cast -from fmf import Tree +import fmf import tmt.utils from tmt.checks import Check, _RawCheck, normalize_test_checks @@ -562,11 +562,12 @@ class RecipeManager(Common): def __init__(self, logger: Logger): super().__init__(logger=logger) - def load(self, run: 'Run', recipe_path: Path, fmf_tree: Tree) -> Recipe: + def load(self, run: 'Run', recipe_path: Path) -> Recipe: recipe = Recipe.from_spec( - cast(_RawRecipe, tmt.utils.yaml_to_dict(self.read(recipe_path))), self._logger + cast(_RawRecipe, tmt.utils.yaml_to_dict(self.read(recipe_path))), + self._logger, ) - self._update_tree(recipe, fmf_tree) + self._update_tree(run, recipe) # TODO: We should have a way to set which steps are enabled # without modifying the CLI context directly. self._update_cli_context(recipe) @@ -603,12 +604,18 @@ def tests(self, recipe: Recipe, plan_name: str) -> list[TestOrigin]: raise tmt.utils.GeneralError(f"Plan '{plan_name}' not found in the recipe.") @staticmethod - def _update_tree(recipe: Recipe, tree: Tree) -> None: + def _update_tree(run: 'Run', recipe: Recipe) -> None: """ - Load the plans from the recipe and update the given fmf tree with their specifications. + Create a new fmf tree from the recipe's run and plan specifications. """ - tree.children.clear() - tree.update({plan.name: plan.to_fmf_spec() for plan in recipe.plans}) + from tmt.base.core import Tree + + fmf_tree = fmf.Tree({plan.name: plan.to_fmf_spec() for plan in recipe.plans}) + fmf_tree.root = recipe.run.root + for node in fmf_tree.climb(): # pyright: ignore[reportUnknownVariableType] + if isinstance(node, fmf.Tree): + node.root = recipe.run.root + run._tree = Tree(logger=run._logger, tree=fmf_tree) def _update_cli_context(self, recipe: Recipe) -> None: """