diff --git a/docs/releases.rst b/docs/releases.rst index 4b7a3d61cf..6de99ee0cd 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -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` plugin. + tmt-1.36.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/stories/cli/try.fmf b/stories/cli/try.fmf index b758932c4d..6668a92578 100644 --- a/stories/cli/try.fmf +++ b/stories/cli/try.fmf @@ -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 diff --git a/tests/try/basic/data/epel.exp b/tests/try/basic/data/epel.exp new file mode 100755 index 0000000000..8dc05be4c4 --- /dev/null +++ b/tests/try/basic/data/epel.exp @@ -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 diff --git a/tests/try/basic/test.sh b/tests/try/basic/test.sh index 71e8e2c8db..0897bd09d7 100755 --- a/tests/try/basic/test.sh +++ b/tests/try/basic/test.sh @@ -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 diff --git a/tmt/cli.py b/tmt/cli.py index fd6cde3ac8..7f72fd21bf 100644 --- a/tmt/cli.py +++ b/tmt/cli.py @@ -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.") diff --git a/tmt/steps/prepare/feature.py b/tmt/steps/prepare/feature.py index ee0310aabd..63e7041a28 100644 --- a/tmt/steps/prepare/feature.py +++ b/tmt/steps/prepare/feature.py @@ -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( diff --git a/tmt/trying.py b/tmt/trying.py index f7970d1660..030fb33801 100644 --- a/tmt/trying.py +++ b/tmt/trying.py @@ -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" @@ -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 @@ -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 """ @@ -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