Skip to content

Commit e951241

Browse files
authored
Fix environment from command line updated twice (teemtee#2614)
1 parent d5b5a76 commit e951241

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tmt/base.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -1662,16 +1662,6 @@ def __init__(
16621662

16631663
self._initialize_data_directory()
16641664

1665-
# Store 'environment' and 'environment-file' keys content
1666-
self._environment = tmt.utils.environment_from_spec(
1667-
raw_fmf_environment_files=node.get("environment-file") or [],
1668-
raw_fmf_environment=node.get('environment', {}),
1669-
raw_cli_environment_files=self.opt('environment-file') or [],
1670-
raw_cli_environment=self.opt('environment'),
1671-
file_root=Path(node.root) if node.root else None,
1672-
key_address=node.name,
1673-
logger=self._logger)
1674-
16751665
self._plan_environment: EnvironmentType = {}
16761666

16771667
# Expand all environment and context variables in the node
@@ -1732,13 +1722,27 @@ def draw_test_serial_number(self, test: Test) -> int:
17321722

17331723
@property
17341724
def environment(self) -> EnvironmentType:
1735-
""" Return combined environment from plan data and command line """
1725+
""" Return combined environment from plan data, command line and original plan """
1726+
1727+
# Store 'environment' and 'environment-file' keys content
1728+
environment_from_spec = tmt.utils.environment_from_spec(
1729+
raw_fmf_environment_files=self.node.get("environment-file") or [],
1730+
raw_fmf_environment=self.node.get('environment', {}),
1731+
raw_cli_environment_files=self.opt('environment-file') or [],
1732+
raw_cli_environment=self.opt('environment'),
1733+
file_root=Path(self.node.root) if self.node.root else None,
1734+
key_address=self.node.name,
1735+
logger=self._logger)
1736+
1737+
# If this is an imported plan, update it with local environment stored in the original plan
1738+
environment_from_original_plan = {}
1739+
if self._original_plan:
1740+
environment_from_original_plan = self._original_plan.environment
1741+
17361742
if self.my_run:
17371743
combined = self._plan_environment.copy()
1738-
combined.update(self._environment)
1739-
# Include environment of the importing plan
1740-
if self._original_plan is not None:
1741-
combined.update(self._original_plan.environment)
1744+
combined.update(environment_from_spec)
1745+
combined.update(environment_from_original_plan)
17421746
# Command line variables take precedence
17431747
combined.update(self.my_run.environment)
17441748
# Include path to the plan data directory
@@ -1751,7 +1755,8 @@ def environment(self) -> EnvironmentType:
17511755
# And tmt version
17521756
combined["TMT_VERSION"] = tmt.__version__
17531757
return combined
1754-
return self._environment
1758+
1759+
return {**environment_from_spec, **environment_from_original_plan}
17551760

17561761
def _source_plan_environment_file(self) -> None:
17571762
""" Add variables from the plan environment file to the environment """
@@ -2443,8 +2448,6 @@ def import_plan(self) -> Optional['Plan']:
24432448
self._imported_plan = Plan(node=node, run=self.my_run, logger=self._logger)
24442449
self._imported_plan._original_plan = self
24452450

2446-
# Update imported plan environment with the local environment
2447-
self._imported_plan.environment.update(self.environment)
24482451
with tmt.utils.modify_environ(self.environment):
24492452
expand_node_data(node.data, {
24502453
key: ','.join(value)

0 commit comments

Comments
 (0)