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

Fix tmt try not sourcing plan environment file after prepare and execute #3316

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions tests/try/plan-env-file/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
13 changes: 13 additions & 0 deletions tests/try/plan-env-file/data/plan.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
summary: Telling how it is
discover:
how: fmf
provision:
how: local
prepare:
how: shell
script: echo "MY_VAR=good" >> $TMT_PLAN_ENVIRONMENT_FILE
execute:
how: tmt
finish:
how: shell
script: echo "and yours is $YOUR_VAR..." # Check if env-file sourced after execute
23 changes: 23 additions & 0 deletions tests/try/plan-env-file/data/start_ask_manual.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/expect -f
# Run all the steps manually and quit

spawn tmt try -a -p /plan

expect "What do we do next?"
send -- "d\r"

expect "What do we do next?"
send -- "p\r"

expect "What do we do next?"
send -- "e\r"

expect "What do we do next?"
send -- "r\r"

expect "What do we do next?"
send -- "f\r"

expect "What do we do next?"
send -- "q\r"
expect eof
14 changes: 14 additions & 0 deletions tests/try/plan-env-file/data/start_ask_test.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/expect -f
# Run the prepare step, start the test and quit

spawn tmt try -a -p /plan

expect "What do we do next?"
send -- "p\r"

expect "What do we do next?"
send -- "t\r"

expect "What do we do next?"
send -- "q\r"
expect eof
11 changes: 11 additions & 0 deletions tests/try/plan-env-file/data/start_ask_test_skip.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/expect -f
# Skip the prepare step, start the test and quit

spawn tmt try -a -p /plan

expect "What do we do next?"
send -- "t\r"

expect "What do we do next?"
send -- "q\r"
expect eof
18 changes: 18 additions & 0 deletions tests/try/plan-env-file/data/start_login.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/expect -f
# Login to guest, run the test and quit

# ord('D') % 32
set ctrlD \x04

spawn tmt try -l -p /plan

expect "Starting interactive shell"
sleep 3
send -- $ctrlD

expect "What do we do next?"
send -- "t\r"

expect "What do we do next?"
send -- "q\r"
expect eof
8 changes: 8 additions & 0 deletions tests/try/plan-env-file/data/start_test.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/expect -f
# Try the plan and quit

spawn tmt try -p /plan

expect "What do we do next?"
send -- "q\r"
expect eof
5 changes: 5 additions & 0 deletions tests/try/plan-env-file/data/test.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary: How it is
framework: shell
test: |
echo "My variable is $MY_VAR..." # Check whether plan-file sourced after prepare
echo "YOUR_VAR=bad" >> $TMT_PLAN_ENVIRONMENT_FILE # Variable to source after execute
5 changes: 5 additions & 0 deletions tests/try/plan-env-file/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary: Verify plan environment file gets sourced
description:
Check that environment file inside TMT_PLAN_ENVIRONMENT_FILE are
sourced after prepare and execute steps when running tmt try.

44 changes: 44 additions & 0 deletions tests/try/plan-env-file/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "export TMT_NO_COLOR=1"
rlRun "pushd data"
rlPhaseEnd

rlPhaseStartTest "Try the plan and quit"
rlRun -s "LANG=en_US ./start_test.exp" 0
rlAssertGrep "My variable is good" $rlRun_LOG
rlAssertGrep "and yours is bad" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Run the prepare step, start the test and quit"
rlRun -s "LANG=en_US ./start_ask_test.exp" 0
rlAssertGrep "My variable is good" $rlRun_LOG
rlAssertGrep "and yours is bad" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Login to guest, run the test and quit"
rlRun -s "LANG=en_US ./start_login.exp" 0
rlAssertGrep "My variable is good" $rlRun_LOG
rlAssertGrep "and yours is bad" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Run all the steps manually and quit"
rlRun -s "LANG=en_US ./start_ask_manual.exp" 0
rlAssertGrep "My variable is good" $rlRun_LOG
rlAssertGrep "and yours is bad" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Skip the prepare step, start the test and quit"
rlRun -s "LANG=en_US ./start_ask_test_skip.exp" 0
rlAssertNotGrep "My variable is good" $rlRun_LOG
rlAssertGrep "and yours is bad" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd
10 changes: 6 additions & 4 deletions tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ def action_start_test(self, plan: Plan) -> None:

plan.discover.go()
plan.provision.go()
plan.prepare.go()
plan.execute.go()
self.action_prepare(plan)
self.action_execute(plan)

def action_start_login(self, plan: Plan) -> None:
""" Start with login """
self.action_start(plan)

plan.provision.go()
plan.prepare.go()
self.action_prepare(plan)
assert plan.login is not None # Narrow type
plan.login.go(force=True)

Expand All @@ -314,7 +314,7 @@ def action_start_ask(self, plan: Plan) -> None:
def action_test(self, plan: Plan) -> None:
""" Test again """
plan.discover.go(force=True)
plan.execute.go(force=True)
self.action_execute(plan)

def action_login(self, plan: Plan) -> None:
""" Log into the guest """
Expand Down Expand Up @@ -373,10 +373,12 @@ def action_discover(self, plan: Plan) -> None:
def action_prepare(self, plan: Plan) -> None:
""" Prepare the guest """
plan.prepare.go(force=True)
plan._source_plan_environment_file()

def action_execute(self, plan: Plan) -> None:
""" Execute tests """
plan.execute.go(force=True)
plan._source_plan_environment_file()

def action_report(self, plan: Plan) -> None:
""" Report results """
Expand Down