Skip to content
Open
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
93 changes: 92 additions & 1 deletion tests/plan/import/basic.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

cleanup() {
rm -rf ~/'.cache/fmf/https:__github.com_teemtee_tmt'
}

rlJournalStart
rlPhaseStartSetup
rlRun "pushd data"
Expand All @@ -9,7 +13,7 @@ rlJournalStart
rlPhaseStartTest "Explore Plans"
rlRun -s "tmt plan"
rlAssertNotGrep "warn" $rlRun_LOG
rlAssertGrep "Found 9 plans" $rlRun_LOG
rlAssertGrep "Found 11 plans" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Show Plans (deep)"
Expand Down Expand Up @@ -139,6 +143,93 @@ rlJournalStart
rlRun -s "tmt -c how=full run -r --dry plan -n /plans/full/tmt" 0 "Run plan (dry mode)"
rlPhaseEnd

rlPhaseStartTest "Remote plan should not be fetched if disabled by adjust"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh boy, what happened with all of the diff in this test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, removed everything and added mine, will bring them back

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a new test script to cover these scenarios? They are not basic anymore... Perhaps tests/plan/import/inaccessible.sh?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure separating one test case (with four sub-cases) makes much sense here. Maybe in the future when things like plans show get covered more correctly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite a long one, so would still lean toward the separation, but not a blocker.

cleanup
rlRun -s "tmt -ddd -c distro=rhel-10 -c how=full run --remove --dry plan --name /plans/importing/disabled-by-adjust" 0 "Run enabled plan"
rlAssertGrep "Plan '/plans/importing/disabled-by-adjust' importing" $rlRun_LOG
rlAssertNotGrep "Plan '/plans/importing/disabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertNotGrep "No plans found." $rlRun_LOG

cleanup
rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full run --remove --dry plan --name /plans/importing/disabled-by-adjust" 2 "Expect no plans to be found"
rlAssertNotGrep "Plan '/plans/importing/disabled-by-adjust' importing" $rlRun_LOG
rlAssertGrep "Plan '/plans/importing/disabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertGrep "No plans found." $rlRun_LOG

rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full plan show /plans/importing/disabled-by-adjust --shallow" 0 "Show dummy plan"
rlAssertNotGrep "Plan '/plans/importing/disabled-by-adjust' importing" $rlRun_LOG

rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full plan show /plans/importing/disabled-by-adjust" 0 "Show plan correctly"
rlAssertGrep "Plan '/plans/importing/disabled-by-adjust' importing" $rlRun_LOG

cleanup
rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full plan ls /plans/importing/disabled-by-adjust" 0 "List disabled plan"
rlAssertGrep "Plan '/plans/importing/disabled-by-adjust' importing" $rlRun_LOG
rlAssertNotGrep "Plan '/plans/importing/disabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertEquals "Verify last line is the plan" "/plans/importing/disabled-by-adjust" $(tail -1 $rlRun_LOG)

cleanup
rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full plan ls /plans/importing/disabled-by-adjust --enabled" 0 "Do not list with --enabled option"
rlAssertNotGrep "Plan '/plans/importing/disabled-by-adjust' importing" $rlRun_LOG
rlAssertGrep "Plan '/plans/importing/disabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertNotEquals "Verify last line is not the plan" "/plans/importing/disabled-by-adjust" $(tail -1 $rlRun_LOG)
rlPhaseEnd

rlPhaseStartTest "Disabled remote plan should be fetched if enabled by adjust"
cleanup
rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full run --remove --dry plan --name /plans/importing/enabled-by-adjust" 0 "Run enabled plan"
rlAssertGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG
rlAssertNotGrep "Plan '/plans/importing/enabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertNotGrep "No plans found." $rlRun_LOG

cleanup
rlRun -s "tmt -ddd -c distro=rhel-10 -c how=full run --remove --dry plan --name /plans/importing/enabled-by-adjust" 2 "Expect no plans to be found"
rlAssertNotGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG
rlAssertGrep "Plan '/plans/importing/enabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertGrep "No plans found." $rlRun_LOG

rlRun -s "tmt -ddd -c distro=rhel-10 -c how=full plan show /plans/importing/enabled-by-adjust --shallow" 0 "Show dummy plan"
rlAssertNotGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG

rlRun -s "tmt -ddd -c distro=rhel-10 -c how=full plan show /plans/importing/enabled-by-adjust" 0 "Show plan correctly"
rlAssertGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG

cleanup
rlRun -s "tmt -ddd -c distro=rhel-10 -c how=full plan ls /plans/importing/enabled-by-adjust" 0 "List disabled plan"
rlAssertGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG
rlAssertNotGrep "Plan '/plans/importing/enabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertEquals "Verify last line is the plan" "/plans/importing/enabled-by-adjust" $(tail -1 $rlRun_LOG)

cleanup
rlRun -s "tmt -ddd -c distro=rhel-10 -c how=full plan ls /plans/importing/enabled-by-adjust --enabled" 0 "List enabled plans"
rlAssertNotGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG
rlAssertGrep "Plan '/plans/importing/enabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertNotEquals "Verify last line is not the plan" "/plans/importing/enabled-by-adjust" $(tail -1 $rlRun_LOG)

rlRun -s "tmt -ddd -c distro=fedora-rawhide -c how=full plan ls /plans/importing/enabled-by-adjust --enabled" 0 "List enabled plans with correct environment"
rlAssertGrep "Plan '/plans/importing/enabled-by-adjust' importing" $rlRun_LOG
rlAssertNotGrep "Plan '/plans/importing/enabled-by-adjust' is not enabled, skipping imports resolution" $rlRun_LOG
rlAssertEquals "Verify last line is the plan" "/plans/importing/enabled-by-adjust" $(tail -1 $rlRun_LOG)
rlPhaseEnd

rlPhaseStartTest "Unimportable plan should not raise errors when disabled"
rlRun -s "tmt -ddd -c how=full plan ls /plans/inaccessible/disabled" 2 "Error out when trying to import internal URL"
rlAssertGrep "Plan '/plans/inaccessible/disabled' importing" $rlRun_LOG
rlAssertGrep "Failed to import remote plan from '/plans/inaccessible/disabled'" $rlRun_LOG

rlRun -s "tmt -ddd -c how=full plan ls /plans/inaccessible/disabled --enabled" 0 "Skip disabled plan with --enabled flag"
rlAssertNotGrep "Plan '/plans/inaccessible/disabled' importing" $rlRun_LOG
rlAssertNotGrep "Failed to import remote plan from '/plans/inaccessible/disabled'" $rlRun_LOG

rlRun -s "tmt -ddd -c how=full plan show /plans/inaccessible/disabled" 2 "Error out when showing"
rlAssertGrep "Plan '/plans/inaccessible/disabled' importing" $rlRun_LOG
rlAssertGrep "Failed to import remote plan from '/plans/inaccessible/disabled'" $rlRun_LOG

rlRun -s "tmt -ddd -c how=full plan show /plans/inaccessible/disabled --shallow" 0 "Show dummy plan"
rlAssertNotGrep "Plan '/plans/inaccessible/disabled' importing" $rlRun_LOG
rlAssertNotGrep "Failed to import remote plan from '/plans/inaccessible/disabled'" $rlRun_LOG
rlPhaseEnd
Comment thread
pkhartsk marked this conversation as resolved.

rlPhaseStartCleanup
rlRun "popd"
rlPhaseEnd
Expand Down
41 changes: 41 additions & 0 deletions tests/plan/import/data/plans.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,47 @@
name: /plans/provision/connect
enabled: true

/inaccessible:
plan:
import:
url: https://secret.internal
name: /secret/internal/plan
/disabled:
summary: Unimportable plan should not raise errors when disabled
enabled: false

/disabled-by-adjust:
summary: Local plan disabled by adjust should not import remote plan
adjust:
enabled: false
when: distro == fedora-rawhide

/enabled-by-adjust:
summary: Local plan enabled by adjust should import remote plan
adjust:
enabled: true
when: distro == fedora-rawhide
enabled: false

/importing:
plan:
import:
url: https://github.com/teemtee/tmt
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
url: https://github.com/teemtee/tmt
url: https://github.com/teemtee/tests

What about using the tests repo? It's smaller and thus faster.

name: /plans/provision/connect

/disabled-by-adjust:
summary: Local plan disabled by adjust should not import remote plan
adjust:
enabled: false
when: distro == fedora-rawhide

/enabled-by-adjust:
summary: Local plan enabled by adjust should import remote plan
adjust:
enabled: true
when: distro == fedora-rawhide
enabled: false

/disabled:
summary: Imported plan will be disabled by local plan
plan:
Expand Down
12 changes: 11 additions & 1 deletion tmt/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,7 @@ def plans(
links: Optional[list['LinkNeedle']] = None,
excludes: Optional[list[str]] = None,
apply_command_line: bool = True,
resolve_enabled_only: bool = False,
) -> list["Plan"]:
"""
Search available plans
Expand Down Expand Up @@ -2621,10 +2622,19 @@ def plans(
for policy in run.policies:
policy.apply_to_plans(plans=plans, logger=logger)

if Plan._opt('enabled') or ('enabled:true' in filters):
resolve_enabled_only = True

if not Plan._opt('shallow'):
unresolved_plans = plans
plans = []
for plan in unresolved_plans:
# Do not resolve disabled plans unless forced to
if resolve_enabled_only and not plan.enabled:
plan.debug(
f"Plan '{plan.name}' is not enabled, skipping imports resolution",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"Plan '{plan.name}' is not enabled, skipping imports resolution",
f"Plan '{plan.name}' is not enabled, skipping imports resolution.",

A consistency nitipick.

)
continue
try:
plans += plan.resolve_imports()
except Exception as error:
Expand Down Expand Up @@ -3144,7 +3154,7 @@ def load(self) -> None:
else:
plan_names = [f"^{re.escape(plan_name)}$" for plan_name in self.data.plans]

self._plans = self.tree.plans(run=self, names=plan_names)
self._plans = self.tree.plans(run=self, names=plan_names, resolve_enabled_only=True)

# Initialize steps only if not selected on the command line
step_options = ['all', 'since', 'until', 'after', 'before', 'skip']
Expand Down
2 changes: 1 addition & 1 deletion tmt/cli/_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ def plans_show(context: Context, /, **kwargs: Any) -> None:

logger = context.obj.logger.clone().apply_verbosity_options(**kwargs)

for plan in context.obj.tree.plans(logger=logger):
for plan in context.obj.tree.plans(logger=logger, resolve_enabled_only=False):
plan.show()
context.obj.print()

Expand Down
Loading