From a7cbcdb72ea761f2e4108cf3d6178e8b67634818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Thu, 17 Oct 2024 08:46:58 +0200 Subject: [PATCH] Avoid using raw step data when injecting phases Actual step data containers come with type annotations and better checking. --- tmt/steps/execute/upgrade.py | 21 ++++++++----------- tmt/steps/prepare/distgit.py | 40 ++++++++++++++++++------------------ tmt/steps/prepare/feature.py | 4 ---- tmt/steps/prepare/install.py | 8 -------- tmt/trying.py | 35 ++++++++++++++++--------------- 5 files changed, 47 insertions(+), 61 deletions(-) diff --git a/tmt/steps/execute/upgrade.py b/tmt/steps/execute/upgrade.py index 801ad11957..3e421cc655 100644 --- a/tmt/steps/execute/upgrade.py +++ b/tmt/steps/execute/upgrade.py @@ -16,7 +16,7 @@ from tmt.steps.execute import ExecutePlugin from tmt.steps.execute.internal import ExecuteInternal, ExecuteInternalData from tmt.steps.prepare import PreparePlugin -from tmt.steps.prepare.install import _RawPrepareInstallStepData +from tmt.steps.prepare.install import PrepareInstallData from tmt.utils import Environment, EnvVarValue, Path, field STATUS_VARIABLE = 'IN_PLACE_UPGRADE' @@ -267,17 +267,14 @@ def _install_dependencies( recommends: bool = False) -> None: """ Install packages required/recommended for upgrade """ phase_name = 'recommended' if recommends else 'required' - data: _RawPrepareInstallStepData = { - 'how': 'install', - 'name': f'{phase_name}-packages-upgrade', - 'summary': f'Install packages {phase_name} by the upgrade', - 'package': [ - dependency.to_spec() - for dependency in tmt.utils.uniq(dependencies) - ], - 'missing': 'skip' if recommends else 'fail' - } - PreparePlugin.delegate(self.step, raw_data=data).go( # type:ignore[attr-defined] + data = PrepareInstallData( + how='install', + name=f'{phase_name}-packages-upgrade', + summary=f'Install packages {phase_name} by the upgrade', + package=tmt.utils.uniq(dependencies), + missing='skip' if recommends else 'fail') + + PreparePlugin.delegate(self.step, data=data).go( # type:ignore[attr-defined] guest=guest, logger=self._logger) def _prepare_remote_discover_data(self, plan: tmt.base.Plan) -> tmt.steps._RawStepData: diff --git a/tmt/steps/prepare/distgit.py b/tmt/steps/prepare/distgit.py index 4c9881b406..a4a5e76f24 100644 --- a/tmt/steps/prepare/distgit.py +++ b/tmt/steps/prepare/distgit.py @@ -10,7 +10,7 @@ from tmt.package_managers import Package from tmt.result import PhaseResult from tmt.steps.prepare import PreparePlugin -from tmt.steps.prepare.install import _RawPrepareInstallStepData +from tmt.steps.prepare.install import PrepareInstallData from tmt.steps.provision import Guest from tmt.utils import Command, Path, ShellScript, field, uniq @@ -55,30 +55,30 @@ def insert_to_prepare_step( prepare_step = discover_plugin.step.plan.prepare where = cast(tmt.steps.discover.DiscoverStepData, discover_plugin.data).where # Future install require - data_require: _RawPrepareInstallStepData = { - 'how': 'install', - 'name': 'requires (dist-git)', - 'summary': 'Install required packages of tests detected by dist-git', - 'order': tmt.utils.DEFAULT_PLUGIN_ORDER_REQUIRES, - 'where': where, - 'package': []} + data_require = PrepareInstallData( + how='install', + name='requires (dist-git)', + summary='Install required packages of tests detected by dist-git', + order=tmt.utils.DEFAULT_PLUGIN_ORDER_REQUIRES, + where=where, + package=[]) future_requires: PreparePlugin[Any] = cast( - PreparePlugin[Any], PreparePlugin.delegate( - prepare_step, raw_data=data_require)) + PreparePlugin[Any], + PreparePlugin.delegate(prepare_step, data=data_require)) prepare_step._phases.append(future_requires) # Future install recommend - data_recommend: _RawPrepareInstallStepData = { - 'how': 'install', - 'name': 'recommends (dist-git)', - 'summary': 'Install recommended packages of tests detected by dist-git', - 'order': tmt.utils.DEFAULT_PLUGIN_ORDER_RECOMMENDS, - 'where': where, - 'package': [], - 'missing': 'skip'} + data_recommend = PrepareInstallData( + how='install', + name='recommends (dist-git)', + summary='Install recommended packages of tests detected by dist-git', + order=tmt.utils.DEFAULT_PLUGIN_ORDER_RECOMMENDS, + where=where, + package=[], + missing='skip') future_recommends: PreparePlugin[Any] = cast( - PreparePlugin[Any], PreparePlugin.delegate( - prepare_step, raw_data=data_recommend)) + PreparePlugin[Any], + PreparePlugin.delegate(prepare_step, data=data_recommend)) prepare_step._phases.append(future_recommends) prepare_step._phases.append( diff --git a/tmt/steps/prepare/feature.py b/tmt/steps/prepare/feature.py index 63e7041a28..ee0310aabd 100644 --- a/tmt/steps/prepare/feature.py +++ b/tmt/steps/prepare/feature.py @@ -78,10 +78,6 @@ def disable(self) -> None: } -class _RawPrepareFeatureStepData(tmt.steps.prepare._RawPrepareStepData, total=False): - epel: str - - @dataclasses.dataclass class PrepareFeatureData(tmt.steps.prepare.PrepareStepData): epel: Optional[str] = field( diff --git a/tmt/steps/prepare/install.py b/tmt/steps/prepare/install.py index 062842442a..8b99bc9623 100644 --- a/tmt/steps/prepare/install.py +++ b/tmt/steps/prepare/install.py @@ -526,14 +526,6 @@ def install_debuginfo(self) -> None: 'installing debuginfo packages.') -class _RawPrepareInstallStepData(tmt.steps.prepare._RawPrepareStepData, total=False): - package: Union[str, list[str]] - directory: Union[str, list[str]] - copr: Union[str, list[str]] - exclude: Union[str, list[str]] - missing: str - - @dataclasses.dataclass class PrepareInstallData(tmt.steps.prepare.PrepareStepData): package: list[tmt.base.DependencySimple] = field( diff --git a/tmt/trying.py b/tmt/trying.py index 30ac6de250..e0f7f9b484 100644 --- a/tmt/trying.py +++ b/tmt/trying.py @@ -21,8 +21,6 @@ from tmt import Plan from tmt.base import RunData from tmt.steps.prepare import PreparePlugin -from tmt.steps.prepare.feature import _RawPrepareFeatureStepData -from tmt.steps.prepare.install import _RawPrepareInstallStepData from tmt.utils import MetadataError, Path USER_PLAN_NAME = "/user/plan" @@ -417,31 +415,34 @@ def handle_epel(self, plan: Plan) -> None: """ Enable EPEL repository """ # tmt run prepare --how feature --epel enabled - data: _RawPrepareFeatureStepData = { - "name": "tmt-try-epel", - 'how': 'feature', - 'epel': "enabled", - } + from tmt.steps.prepare.feature import PrepareFeatureData + + data = PrepareFeatureData( + name="tmt-try-epel", + how='feature', + epel="enabled") phase: PreparePlugin[Any] = cast( - PreparePlugin[Any], PreparePlugin.delegate( - plan.prepare, raw_data=data)) + PreparePlugin[Any], + PreparePlugin.delegate(plan.prepare, data=data)) + plan.prepare._phases.append(phase) def handle_install(self, plan: Plan) -> None: """ Install local rpm package on the guest. """ - packages = list(self.opt("install")) # tmt run prepare --how install --package PACKAGE - data: _RawPrepareInstallStepData = { - "name": "tmt-try-install", - 'how': 'install', - 'package': packages, - } + from tmt.steps.prepare.install import PrepareInstallData + + data = PrepareInstallData( + name="tmt-try-install", + how='install', + package=list(self.opt("install"))) phase: PreparePlugin[Any] = cast( - PreparePlugin[Any], PreparePlugin.delegate( - plan.prepare, raw_data=data)) + PreparePlugin[Any], + PreparePlugin.delegate(plan.prepare, data=data)) + plan.prepare._phases.append(phase) def go(self) -> None: