Skip to content

Commit

Permalink
Add epel prepare plugin using feature into tmt try (#2985)
Browse files Browse the repository at this point in the history
Co-authored-by: Ismail Ibrahim Quwarah <[email protected]>
Co-authored-by: Petr Šplíchal <[email protected]>
  • Loading branch information
3 people committed Sep 24, 2024
1 parent 1238dca commit 6d08a7b
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ In verbose mode, the ``discover`` step now prints information
about the beakerlib libraries which were fetched for the test
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-1.36.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
19 changes: 19 additions & 0 deletions stories/cli/try.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,22 @@ link:
package: vim
execute:
how: tmt

/option:
story:
As a user I want an easy way to run common options in ``1minutetip`` and ``tmt run``

/epel:
story:
As a user I want an easy way to enable epel repository
description: |
Enable EPEL repository

.. versionadded:: 1.37

example:
- tmt try centos-stream-9@virtual --epel

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

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

rlPhaseStartTest "Epel"
rlRun -s "./epel.exp"
rlAssertGrep "Let's try.*/plans/basic" $rlRun_LOG
rlAssertGrep "PLAY \[Enable EPEL repositories\]" $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 @@ -1749,6 +1749,9 @@ def init(
@option(
"-l", "--login", is_flag=True, default=False,
help="Log into the guest only, do not run any tests.")
@option(
"--epel", is_flag=True, default=False,
help="Enable epel repository.")
@option(
"-a", "--ask", is_flag=True, default=False,
help="Just provision the guest and ask what to do next.")
Expand Down
4 changes: 4 additions & 0 deletions tmt/steps/prepare/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ 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
28 changes: 27 additions & 1 deletion tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import tmt.utils
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 @@ -103,6 +105,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"]

# Use the verbosity level 3 unless user explicitly requested
# a different level on the command line
Expand Down Expand Up @@ -402,6 +405,28 @@ def action_quit(self, plan: Plan) -> None:
run_id = click.style(plan.my_run.workdir, fg="magenta")
self.print(f"Run {run_id} successfully finished. Bye for now!")

def handle_options(self, plan: Plan) -> None:
""" Choose requested cli option """

for option in self.cli_options:
if self.opt(option):
getattr(self, f"handle_{option}")(plan)

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",
}

phase: PreparePlugin[Any] = cast(
PreparePlugin[Any], PreparePlugin.delegate(
plan.prepare, raw_data=data))
plan.prepare._phases.append(phase)

def go(self) -> None:
""" Run the interactive session """

Expand All @@ -418,8 +443,9 @@ def go(self) -> None:
self.welcome()
self.save()

# Set the default verbosity level
# Set the default verbosity level, handle options
for plan in self.plans:
self.handle_options(plan)
self.action_verbose(plan)

# Choose the initial action
Expand Down

0 comments on commit 6d08a7b

Please sign in to comment.