Skip to content

Commit

Permalink
Add epel prepare plugin using feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismail Ibrahim Quwarah committed Jun 17, 2024
1 parent ce83cc2 commit c163d95
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tmt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,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 @@ -88,6 +88,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
37 changes: 37 additions & 0 deletions tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import tmt.templates
import tmt.utils
from tmt import Plan
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 All @@ -44,6 +46,7 @@ class Action(enum.Enum):
START_LOGIN = "-", "jump directly to login after start"
START_ASK = "-", "do nothing without first asking the user"
START_TEST = "-", "start directly with executing detected tests"
START_CLI_OPTION = "-", "do requested cli option then ask the user"

@property
def key(self) -> str:
Expand Down Expand Up @@ -102,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 @@ -295,6 +299,13 @@ def action_start_ask(self, plan: Plan) -> None:

plan.provision.go()

def action_start_cli_option(self, plan: Plan) -> None:
""" Do requested cli option """
self.action_start(plan)

plan.provision.go()
plan.prepare.go()

def action_test(self, plan: Plan) -> None:
""" Test again """
plan.discover.go(force=True)
Expand Down Expand Up @@ -388,6 +399,29 @@ 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"""

option = [o for o in self.cli_options if self.opt(o)]
if not option:
return
getattr(self, f"handle_{option[0]}")(plan)

def handle_epel(self, plan: Plan) -> None:
""" Enable EPEL repository"""

# tmt run prepare --how feature --epel enabled
data: _RawPrepareFeatureStepData = {
"name": "prepare-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 @@ -403,13 +437,16 @@ def go(self) -> None:

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

# Choose the initial action
if self.opt("login"):
action = Action.START_LOGIN
elif self.opt("ask"):
action = Action.START_ASK
elif any(self.opt(o) for o in self.cli_options):
action = Action.START_CLI_OPTION
elif self.tests:
action = Action.START_TEST
else:
Expand Down

0 comments on commit c163d95

Please sign in to comment.