|
1 | 1 | import copy |
| 2 | +from collections.abc import Iterator |
2 | 3 | from typing import Any, Optional, Union, cast |
3 | 4 |
|
4 | 5 | import fmf.utils |
@@ -228,29 +229,20 @@ def discover(self) -> Union[Discover, DiscoverFmf]: |
228 | 229 | def discover(self, plugin: Optional[DiscoverPlugin[DiscoverStepData]]) -> None: |
229 | 230 | self._discover = plugin |
230 | 231 |
|
231 | | - def gather_tasks( |
| 232 | + def tasks( |
232 | 233 | self, |
233 | | - ) -> list[tuple['ExecutePlugin[ExecuteStepData]', list['tmt.guest.Guest']]]: |
234 | | - """ |
235 | | - Return tasks to be enqueued for execution. |
236 | | -
|
237 | | - upgrade plugin is expected to (potentially) execute multiple |
238 | | - discover phases on old, perform the upgrade, then execute |
239 | | - those same discover phases again on new. All of this should occur |
240 | | - in a single task. |
241 | | - """ |
| 234 | + ) -> Iterator[tuple['ExecutePlugin[ExecuteStepData]', list['tmt.guest.Guest']]]: |
| 235 | + # upgrade plugin is expected to (potentially) execute multiple |
| 236 | + # discover phases on old, perform the upgrade, then execute |
| 237 | + # those same discover phases again on new. All of this should occur |
| 238 | + # in a single task. |
242 | 239 | phase_copy = cast(ExecutePlugin[ExecuteStepData], copy.copy(self)) |
243 | 240 | # We want to run all discover phases on old and new, so set discover_phase to None. |
244 | 241 | # This comes with the responsibility to later only run discover phases that are enabled |
245 | 242 | # for that guest, based on discover.enabled_by_when and discover.enabled_on_guest(guest). |
246 | 243 | phase_copy.discover_phase = None |
247 | 244 |
|
248 | | - return [ |
249 | | - ( |
250 | | - phase_copy, |
251 | | - self.step.plan.provision.ready_guests, |
252 | | - ) |
253 | | - ] |
| 245 | + yield (phase_copy, self.step.plan.provision.ready_guests) |
254 | 246 |
|
255 | 247 | def go( |
256 | 248 | self, |
@@ -497,31 +489,36 @@ def _run_test_phase(self, guest: tmt.guest.Guest, prefix: str, logger: tmt.log.L |
497 | 489 | # Backup the original discover phase, it should be None |
498 | 490 | original_discover_phase = self.discover_phase |
499 | 491 |
|
500 | | - # Run discover phases one at a time, |
501 | | - # only running phases that are enabled for this guest. |
502 | | - for discover in self.step.plan.discover.phases(classes=(DiscoverPlugin,)): |
503 | | - if discover.enabled_by_when and discover.enabled_on_guest(guest): |
504 | | - self.discover_phase = discover.name |
505 | | - |
506 | | - # Backup and modify test names for this discover phase |
507 | | - test_name_backups: list[tuple[tmt.base.core.Test, str]] = [] |
508 | | - for test_origin in self.discover.tests( |
509 | | - phase_name=self.discover_phase, enabled=True |
510 | | - ): |
511 | | - test_name_backups.append((test_origin.test, test_origin.test.name)) |
512 | | - test_origin.test.name = f'/{prefix}/{test_origin.test.name.lstrip("/")}' |
513 | | - |
514 | | - self._run_tests( |
515 | | - guest=guest, |
516 | | - extra_environment=Environment({STATUS_VARIABLE: EnvVarValue(prefix)}), |
517 | | - logger=logger, |
518 | | - ) |
519 | | - |
520 | | - # Restore test names immediately after this phase |
521 | | - for test, original_name in test_name_backups: |
522 | | - test.name = original_name |
523 | | - |
524 | | - self.discover_phase = original_discover_phase |
| 492 | + try: |
| 493 | + # Run discover phases one at a time, |
| 494 | + # only running phases that are enabled for this guest. |
| 495 | + for discover in self.step.plan.discover.phases(classes=(DiscoverPlugin,)): |
| 496 | + if discover.enabled_by_when and discover.enabled_on_guest(guest): |
| 497 | + self.discover_phase = discover.name |
| 498 | + |
| 499 | + test_name_backups: list[tuple[tmt.base.core.Test, str]] = [] |
| 500 | + try: |
| 501 | + # Backup and modify test names for this discover phase |
| 502 | + for test_origin in self.discover.tests( |
| 503 | + phase_name=self.discover_phase, enabled=True |
| 504 | + ): |
| 505 | + test_name_backups.append((test_origin.test, test_origin.test.name)) |
| 506 | + test_origin.test.name = ( |
| 507 | + f'/{prefix}/{test_origin.test.name.lstrip("/")}' |
| 508 | + ) |
| 509 | + |
| 510 | + self._run_tests( |
| 511 | + guest=guest, |
| 512 | + extra_environment=Environment({STATUS_VARIABLE: EnvVarValue(prefix)}), |
| 513 | + logger=logger, |
| 514 | + ) |
| 515 | + |
| 516 | + finally: |
| 517 | + # Restore test names immediately after this phase |
| 518 | + for test, original_name in test_name_backups: |
| 519 | + test.name = original_name |
| 520 | + finally: |
| 521 | + self.discover_phase = original_discover_phase |
525 | 522 |
|
526 | 523 | self._remove_old_results(prefix) |
527 | 524 |
|
|
0 commit comments