Skip to content

Commit

Permalink
Avoid using raw step data when injecting phases
Browse files Browse the repository at this point in the history
Actual step data containers come with type annotations and better
checking.
  • Loading branch information
happz committed Sep 30, 2024
1 parent 880c1b3 commit d4fae72
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 61 deletions.
21 changes: 9 additions & 12 deletions tmt/steps/execute/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 20 additions & 20 deletions tmt/steps/prepare/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 0 additions & 4 deletions tmt/steps/prepare/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 0 additions & 8 deletions tmt/steps/prepare/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
35 changes: 18 additions & 17 deletions tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d4fae72

Please sign in to comment.