|
48 | 48 | Stopwatch, |
49 | 49 | configure_bool_constant, |
50 | 50 | ) |
51 | | -from tmt.utils.environment import Environment, EnvVarValue, HasEnvironment |
| 51 | +from tmt.utils.environment import Environment, EnvVarValue, HasEnvironment, HasIntrinsicEnvironment |
52 | 52 |
|
53 | 53 | if TYPE_CHECKING: |
54 | 54 | import tmt.base.plan |
@@ -111,7 +111,7 @@ class ExecuteStepData(tmt.steps.WhereableStepData, tmt.steps.StepData): |
111 | 111 |
|
112 | 112 |
|
113 | 113 | @container |
114 | | -class TestInvocation(HasStepWorkdir, HasEnvironment): |
| 114 | +class TestInvocation(HasStepWorkdir, HasEnvironment, HasIntrinsicEnvironment): |
115 | 115 | """ |
116 | 116 | A bundle describing one test invocation. |
117 | 117 |
|
@@ -352,56 +352,62 @@ def restraint(self) -> RestraintContext: |
352 | 352 | logger=self.logger, |
353 | 353 | ) |
354 | 354 |
|
| 355 | + @property |
| 356 | + def intrinsic_environment(self) -> Environment: |
| 357 | + # narrow type |
| 358 | + assert isinstance(self.phase.step.plan.my_run, tmt.base.run.Run) |
| 359 | + |
| 360 | + environment = Environment() |
| 361 | + |
| 362 | + environment["TMT_TEST_NAME"] = EnvVarValue(self.test.name) |
| 363 | + environment["TMT_TEST_INVOCATION_PATH"] = EnvVarValue(self.path) |
| 364 | + environment["TMT_TEST_DATA"] = EnvVarValue(self.test_data_path) |
| 365 | + environment["TMT_TEST_SUBMITTED_FILES"] = EnvVarValue(self.submission_log_path) |
| 366 | + environment['TMT_TEST_SERIAL_NUMBER'] = EnvVarValue(str(self.test.serial_number)) |
| 367 | + environment["TMT_TEST_METADATA"] = EnvVarValue(self.path / TEST_METADATA_FILENAME) |
| 368 | + |
| 369 | + environment['TMT_TEST_ITERATION_ID'] = EnvVarValue( |
| 370 | + f"{self.phase.step.plan.my_run.unique_id}-{self.test.serial_number}" |
| 371 | + ) |
| 372 | + |
| 373 | + environment['TMT_SOURCE_DIR'] = EnvVarValue(self.discover_phase.source_dir) |
| 374 | + |
| 375 | + environment.update( |
| 376 | + # Add variables from plan |
| 377 | + self.phase.step.plan.intrinsic_environment, |
| 378 | + # Add variables from guest |
| 379 | + self.guest.intrinsic_environment, |
| 380 | + # Add variables from invocation contexts |
| 381 | + self.abort.intrinsic_environment, |
| 382 | + self.reboot.intrinsic_environment, |
| 383 | + self.restart.intrinsic_environment, |
| 384 | + self.pidfile.intrinsic_environment, |
| 385 | + self.restraint.intrinsic_environment, |
| 386 | + # Add variables the framework wants to expose |
| 387 | + self.test.test_framework.get_environment_variables(self, self.logger), |
| 388 | + ) |
| 389 | + |
| 390 | + return environment |
| 391 | + |
355 | 392 | @property |
356 | 393 | def environment(self) -> Environment: |
357 | 394 | if self._environment is None: |
358 | 395 | # narrow type |
359 | | - assert isinstance(self.phase.parent, Execute) |
360 | | - |
361 | | - # narrow type |
362 | | - assert isinstance(self.phase.parent.plan.my_run, tmt.base.run.Run) |
| 396 | + assert isinstance(self.phase.step.plan.my_run, tmt.base.run.Run) |
363 | 397 |
|
364 | 398 | environment = Environment() |
365 | 399 |
|
366 | 400 | environment.update( |
367 | 401 | self.guest.environment, |
368 | 402 | self.test.environment, |
369 | 403 | self.guest.plan_environment, |
370 | | - self.phase.parent.plan.environment, |
| 404 | + self.phase.step.plan.environment, |
371 | 405 | ) |
372 | 406 |
|
373 | | - environment["TMT_TEST_NAME"] = EnvVarValue(self.test.name) |
374 | | - environment["TMT_TEST_INVOCATION_PATH"] = EnvVarValue(self.path) |
375 | | - environment["TMT_TEST_DATA"] = EnvVarValue(self.test_data_path) |
376 | | - environment["TMT_TEST_SUBMITTED_FILES"] = EnvVarValue(self.submission_log_path) |
377 | | - environment['TMT_TEST_SERIAL_NUMBER'] = EnvVarValue(str(self.test.serial_number)) |
378 | | - environment["TMT_TEST_METADATA"] = EnvVarValue(self.path / TEST_METADATA_FILENAME) |
379 | | - |
380 | | - environment['TMT_TEST_ITERATION_ID'] = EnvVarValue( |
381 | | - f"{self.phase.parent.plan.my_run.unique_id}-{self.test.serial_number}" |
382 | | - ) |
383 | | - |
384 | | - environment['TMT_SOURCE_DIR'] = EnvVarValue(self.discover_phase.source_dir) |
385 | | - |
386 | 407 | else: |
387 | 408 | environment = self._environment |
388 | 409 |
|
389 | | - # TODO: this was owned by plan, but at wrong position, and it will |
390 | | - # be owned by plan again once the dust of environment untangling |
391 | | - # settles. Follow https://github.com/teemtee/tmt/issues/4241 for |
392 | | - # more. |
393 | | - environment['TMT_PLAN_ENVIRONMENT_FILE'] = EnvVarValue(self.guest.plan_environment_path) |
394 | | - |
395 | | - environment.update( |
396 | | - # Add variables from invocation contexts |
397 | | - self.abort, |
398 | | - self.reboot, |
399 | | - self.restart, |
400 | | - self.pidfile, |
401 | | - self.restraint, |
402 | | - # Add variables the framework wants to expose |
403 | | - self.test.test_framework.get_environment_variables(self, self.logger), |
404 | | - ) |
| 410 | + environment.update(self.intrinsic_environment) |
405 | 411 |
|
406 | 412 | self._environment = environment |
407 | 413 |
|
|
0 commit comments