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

Avoid using raw step data when injecting phases #3248

Draft
wants to merge 16 commits into
base: iquwarah-tmt-try-package
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ execution. Use ``tmt run discover -vvv`` to see the details.
``tmt try`` now supports :ref:`/stories/cli/try/option/epel` option
backed by :ref:`prepare/feature</plugins/prepare/feature>` plugin.

``tmt try`` now supports :ref:`/stories/cli/try/option/install` option
backed by :ref:`prepare/feature</plugins/prepare/install>` plugin.


tmt-1.36.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
15 changes: 15 additions & 0 deletions stories/cli/try.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,18 @@ link:
link:
- implemented-by: /tmt/trying.py
- implemented-by: /tmt/steps/prepare/feature.py

/install:
story:
As a user I want an easy way to install local rpm package on the guest.
description: |
Install local rpm package on the guest.

.. versionadded:: 1.37

example:
- tmt try fedora@virtual --install tree

link:
- implemented-by: /tmt/trying.py
- implemented-by: /tmt/steps/prepare/install.py
8 changes: 8 additions & 0 deletions tests/try/basic/data/install.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/expect -f
# Try install

set timeout 180
spawn tmt try fedora@container --install tree -p /plans/basic
expect "What do we do next?"
send -- "q\r"
expect eof
8 changes: 8 additions & 0 deletions tests/try/basic/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ rlJournalStart
rlAssertGrep "Run .* successfully finished. Bye for now!" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Install"
rlRun -s "./install.exp"
rlAssertGrep "Let's try.*/plans/basic" $rlRun_LOG
rlAssertGrep "cmd: rpm -q --whatprovides tree || dnf install -y tree" $rlRun_LOG
rlAssertGrep "out: Installed:" $rlRun_LOG
rlAssertGrep "Run .* successfully finished. Bye for now!" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Verbose Output"
rlRun -s "TMT_CONFIG_DIR=$config ./verbose.exp"
rlAssertGrep "custom-prepare" $rlRun_LOG
Expand Down
3 changes: 3 additions & 0 deletions tmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,9 @@ def init(
@option(
"--epel", is_flag=True, default=False,
help="Enable epel repository.")
@option(
"--install", default=[], metavar="PACKAGE", multiple=True,
help="Install local rpm package on the guest.")
@option(
"-a", "--ask", is_flag=True, default=False,
help="Just provision the guest and ask what to do next.")
Expand Down
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
36 changes: 27 additions & 9 deletions tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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.utils import MetadataError, Path

USER_PLAN_NAME = "/user/plan"
Expand Down Expand Up @@ -105,7 +104,7 @@ def __init__(
self.tests: list[tmt.Test] = []
self.plans: list[Plan] = []
self.image_and_how = self.opt("image_and_how")
self.cli_options = ["epel"]
self.cli_options = ["epel", "install"]

# Use the verbosity level 3 unless user explicitly requested
# a different level on the command line
Expand Down Expand Up @@ -416,15 +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. """

# tmt run prepare --how install --package PACKAGE
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, data=data))

plan.prepare._phases.append(phase)

def go(self) -> None:
Expand Down
Loading