Skip to content

Commit

Permalink
Correctly update environment from importing plan
Browse files Browse the repository at this point in the history
The environment from the importing plan was ignored.

As agreed, let's make the `environment` a cached property and inherit
the importing plan environment automatically.

Resolves teemtee#2446

Signed-off-by: Miroslav Vadkerti <[email protected]>
  • Loading branch information
thrix committed Nov 28, 2023
1 parent ecac615 commit a0bc749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/plan/import/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ rlJournalStart
rlAssertGrep "pass /lint/tests" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Environment is inherited from the importing plan"
rlRun -s "tmt run -ddd discover plan --name /plans/environment"
rlAssertGrep "EXPECTED: some-string$" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlPhaseEnd
Expand Down
9 changes: 9 additions & 0 deletions tests/plan/import/data/plans.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
url: https://github.com/teemtee/tmt
name: /plans/provision

/environment:
summary: Honor importing plan environment
plan:
import:
url: https://github.com/teemtee/tmt
name: /plans/sanity/lint
environment:
EXPECTED: some-string

/dynamic-ref:
summary: Git URL and dynamic ref
context:
Expand Down
5 changes: 4 additions & 1 deletion tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,12 +1668,15 @@ def draw_test_serial_number(self, test: Test) -> int:

return next(self._test_serial_number_generator)

@property
@tmt.utils.cached_property
def environment(self) -> EnvironmentType:
""" Return combined environment from plan data and command line """
if self.my_run:
combined = self._plan_environment.copy()
combined.update(self._environment)
# Include environment of the importing plan
if self._original_plan is not None:
combined.update(self._original_plan.environment)
# Command line variables take precedence
combined.update(self.my_run.environment)
# Include path to the plan data directory
Expand Down

0 comments on commit a0bc749

Please sign in to comment.