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

Add install prepare plugin using install into tmt try #3071

Merged
merged 16 commits into from
Oct 1, 2024
Merged
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
7 changes: 5 additions & 2 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ 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.
The ``tmt try`` command now supports the new
:ref:`/stories/cli/try/option/epel` option backed by the
:ref:`prepare/feature</plugins/prepare/feature>` plugin and the
new :ref:`/stories/cli/try/option/install` option backed by the
: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 @@ -1759,6 +1759,9 @@ def init(
@option(
"--epel", is_flag=True, default=False,
help="Enable epel repository.")
@option(
"--install", default=[], metavar="PACKAGE", multiple=True,
help="Install 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
19 changes: 18 additions & 1 deletion tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 @@ -105,7 +106,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 @@ -427,6 +428,22 @@ def handle_epel(self, plan: Plan) -> None:
plan.prepare, raw_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,
}

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 Down
Loading