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
2 changes: 1 addition & 1 deletion tests/core/source-script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rlJournalStart
# All tests are included in the tmt plan/test itself
rlRun -s "tmt run --id $run -a provision --how=${PROVISION_HOW}" 0 "Run tests"
# Make sure the file is still there
rlAssertExists $run/plan/data/plan-source-script.sh
rlAssertExists $run/plan/data/plan-source-script.sh-default-0
rlPhaseEnd

rlPhaseStartCleanup
Expand Down
14 changes: 0 additions & 14 deletions tmt/base/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
import tmt.log


#: Filename associated with ``TMT_PLAN_SOURCE_SCRIPT``
PLAN_SOURCE_SCRIPT_NAME: str = "plan-source-script.sh"


class _RemotePlanReference(_RawFmfId):
importing: Optional[str]
scope: Optional[str]
Expand Down Expand Up @@ -476,7 +472,6 @@ def _environment_from_intrinsics(self) -> Environment:

if self.my_run:
environment['TMT_PLAN_DATA'] = EnvVarValue(self.data_directory)
environment['TMT_PLAN_SOURCE_SCRIPT'] = EnvVarValue(self.plan_source_script)

return environment

Expand Down Expand Up @@ -720,15 +715,6 @@ def data_directory(self) -> Path:

return data_directory

@functools.cached_property
def plan_source_script(self) -> Path:
plan_sourced_file_path = self.data_directory / PLAN_SOURCE_SCRIPT_NAME
plan_sourced_file_path.touch(exist_ok=True)

self.debug(f"Create the environment file '{plan_sourced_file_path}'.", level=2)

return plan_sourced_file_path

@staticmethod
def edit_template(raw_content: str) -> str:
"""
Expand Down
30 changes: 26 additions & 4 deletions tmt/guest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
#: Name of the :ref:`plan environment file <step-variables>`.
PLAN_ENVIRONMENT_FILENAME = 'variables.env'

#: Name of the :ref:`plan source script <step-variables>`.
PLAN_SOURCE_SCRIPT_FILENAME: str = "plan-source-script.sh"

#: How many seconds to wait for a connection to succeed after guest boot.
#: This is the default value tmt would use unless told otherwise.
DEFAULT_CONNECT_TIMEOUT = 2 * 60
Expand Down Expand Up @@ -1891,6 +1894,22 @@ def plan_environment_path(self) -> Optional[Path]:

return path

@functools.cached_property
def plan_source_script_path(self) -> Optional[Path]:
"""
A path to the :ref:`plan source script <step-variables>` file.
"""

if not isinstance(self.parent, tmt.steps.provision.Provision):
return None

path = self.parent.plan.data_directory / f'{PLAN_SOURCE_SCRIPT_FILENAME}-{self.safe_name}'
Comment thread
LecrisUT marked this conversation as resolved.
path.touch(exist_ok=True)

self.debug(f"Create the plan source script '{path}'.", level=2)

return path

@property
def plan_environment(self) -> Environment:
"""
Expand Down Expand Up @@ -2236,13 +2255,16 @@ def _prepare_command_environment(
if isinstance(self.parent, tmt.steps.Step):
environment.update(self.parent.plan)

# TODO: this was owned by plan, but at wrong position, and it will
# be owned by plan again once the dust of environment untangling
# settles. Follow https://github.com/teemtee/tmt/issues/4241 for
# more.
# TODO: these are owned by plan, but at wrong position, and
# they will be owned by plan again once the dust of environment
# untangling settles. Follow https://github.com/teemtee/tmt/issues/4241
# for more.
if self.plan_environment_path:
environment['TMT_PLAN_ENVIRONMENT_FILE'] = EnvVarValue(self.plan_environment_path)

if self.plan_source_script_path:
environment['TMT_PLAN_SOURCE_SCRIPT'] = EnvVarValue(self.plan_source_script_path)

else:
# Create a copy of given environment - this prevents any
# accidental modification of the given environment.
Expand Down
20 changes: 14 additions & 6 deletions tmt/steps/execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,17 @@ def environment(self) -> Environment:
else:
environment = self._environment

# TODO: this was owned by plan, but at wrong position, and it will
# be owned by plan again once the dust of environment untangling
# settles. Follow https://github.com/teemtee/tmt/issues/4241 for
# more.
environment['TMT_PLAN_ENVIRONMENT_FILE'] = EnvVarValue(self.guest.plan_environment_path)
# TODO: these are owned by plan, but at wrong position, and
# they will be owned by plan again once the dust of environment
# untangling settles. Follow https://github.com/teemtee/tmt/issues/4241
# for more.
if self.guest.plan_environment_path:
environment['TMT_PLAN_ENVIRONMENT_FILE'] = EnvVarValue(
self.guest.plan_environment_path
)

if self.guest.plan_source_script_path:
environment['TMT_PLAN_SOURCE_SCRIPT'] = EnvVarValue(self.guest.plan_source_script_path)

environment.update(
# Add variables from invocation contexts
Expand Down Expand Up @@ -543,7 +549,9 @@ def _invoke(timeout: Optional[int] = None) -> CommandOutput:
on_process_end=_reset_process,
test_session=True,
friendly_command=str(self.test.test),
sourced_files=[self.phase.step.plan.plan_source_script],
sourced_files=[self.guest.plan_source_script_path]
if self.guest.plan_source_script_path
else [],
)

self.start_time = timer.start_time_formatted
Expand Down
15 changes: 10 additions & 5 deletions tmt/steps/prepare/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,16 @@ def go(
self.step.plan.environment,
)

# TODO: this was owned by plan, but at wrong position, and it will
# be owned by plan again once the dust of environment untangling
# settles. Follow https://github.com/teemtee/tmt/issues/4241 for
# more.
# TODO: these are owned by plan, but at wrong position, and
# they will be owned by plan again once the dust of environment
# untangling settles. Follow https://github.com/teemtee/tmt/issues/4241
# for more.
if guest.plan_environment_path:
environment['TMT_PLAN_ENVIRONMENT_FILE'] = EnvVarValue(guest.plan_environment_path)

if guest.plan_source_script_path:
environment['TMT_PLAN_SOURCE_SCRIPT'] = EnvVarValue(guest.plan_source_script_path)

# Give a short summary
overview = fmf.utils.listed(self.data.script, 'script')
logger.info('overview', f'{overview} found', 'green')
Expand Down Expand Up @@ -246,7 +249,9 @@ def _invoke_script(
command=command,
cwd=worktree,
environment=environment,
sourced_files=[self.step.plan.plan_source_script],
sourced_files=[guest.plan_source_script_path]
if guest.plan_source_script_path
else [],
immediately=False,
)

Expand Down
11 changes: 7 additions & 4 deletions tmt/steps/provision/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ def _prepare_command_environment(
if isinstance(self.parent, tmt.steps.Step):
environment.update(self.parent.plan)

# TODO: this was owned by plan, but at wrong position, and it will
# be owned by plan again once the dust of environment untangling
# settles. Follow https://github.com/teemtee/tmt/issues/4241 for
# more.
# TODO: these are owned by plan, but at wrong position, and
# they will be owned by plan again once the dust of environment
# untangling settles. Follow https://github.com/teemtee/tmt/issues/4241
# for more.
if self.plan_environment_path:
environment['TMT_PLAN_ENVIRONMENT_FILE'] = EnvVarValue(self.plan_environment_path)

if self.plan_source_script_path:
environment['TMT_PLAN_SOURCE_SCRIPT'] = EnvVarValue(self.plan_source_script_path)

else:
environment = super()._prepare_command_environment(environment=environment)

Expand Down
Loading