diff --git a/tests/try/plan-env-file/data/.fmf/version b/tests/try/plan-env-file/data/.fmf/version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/try/plan-env-file/data/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/try/plan-env-file/data/plan.fmf b/tests/try/plan-env-file/data/plan.fmf new file mode 100644 index 0000000000..eaf75558c6 --- /dev/null +++ b/tests/try/plan-env-file/data/plan.fmf @@ -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 diff --git a/tests/try/plan-env-file/data/start_ask_manual.exp b/tests/try/plan-env-file/data/start_ask_manual.exp new file mode 100755 index 0000000000..5d95673103 --- /dev/null +++ b/tests/try/plan-env-file/data/start_ask_manual.exp @@ -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 diff --git a/tests/try/plan-env-file/data/start_ask_test.exp b/tests/try/plan-env-file/data/start_ask_test.exp new file mode 100755 index 0000000000..f22f9def6a --- /dev/null +++ b/tests/try/plan-env-file/data/start_ask_test.exp @@ -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 diff --git a/tests/try/plan-env-file/data/start_ask_test_skip.exp b/tests/try/plan-env-file/data/start_ask_test_skip.exp new file mode 100755 index 0000000000..80fc195a1b --- /dev/null +++ b/tests/try/plan-env-file/data/start_ask_test_skip.exp @@ -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 diff --git a/tests/try/plan-env-file/data/start_login.exp b/tests/try/plan-env-file/data/start_login.exp new file mode 100755 index 0000000000..6f448cc61b --- /dev/null +++ b/tests/try/plan-env-file/data/start_login.exp @@ -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 diff --git a/tests/try/plan-env-file/data/start_test.exp b/tests/try/plan-env-file/data/start_test.exp new file mode 100755 index 0000000000..998cd383ce --- /dev/null +++ b/tests/try/plan-env-file/data/start_test.exp @@ -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 diff --git a/tests/try/plan-env-file/data/test.fmf b/tests/try/plan-env-file/data/test.fmf new file mode 100644 index 0000000000..07ccfc7c05 --- /dev/null +++ b/tests/try/plan-env-file/data/test.fmf @@ -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 diff --git a/tests/try/plan-env-file/main.fmf b/tests/try/plan-env-file/main.fmf new file mode 100644 index 0000000000..633094eb9a --- /dev/null +++ b/tests/try/plan-env-file/main.fmf @@ -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. + diff --git a/tests/try/plan-env-file/test.sh b/tests/try/plan-env-file/test.sh new file mode 100755 index 0000000000..53ba4a4c0c --- /dev/null +++ b/tests/try/plan-env-file/test.sh @@ -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 diff --git a/tmt/trying.py b/tmt/trying.py index e0f7f9b484..70e198c203 100644 --- a/tmt/trying.py +++ b/tmt/trying.py @@ -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) @@ -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 """ @@ -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 """