|
1 | 1 | # Copyright (c) Microsoft Corporation.
|
2 | 2 | # Licensed under the MIT license.
|
3 | 3 |
|
| 4 | +from dataclasses import dataclass, field |
4 | 5 | from pathlib import Path
|
5 |
| -from typing import List, Optional, Type |
| 6 | +from typing import Any, List, Optional, Type |
| 7 | + |
| 8 | +from dataclasses_json import dataclass_json |
6 | 9 |
|
7 | 10 | from lisa import feature, features
|
8 |
| -from lisa.environment import Environment |
| 11 | +from lisa.environment import Environment, EnvironmentStatus |
9 | 12 | from lisa.feature import Feature
|
10 | 13 | from lisa.platform_ import Platform
|
11 | 14 | from lisa.schema import DiskOptionSettings, NetworkInterfaceOptionSettings
|
|
14 | 17 | from . import READY
|
15 | 18 |
|
16 | 19 |
|
| 20 | +@dataclass_json() |
| 21 | +@dataclass |
| 22 | +class ReadyPlatformSchema: |
| 23 | + # If set to True, a dirty environment will be retained and reused |
| 24 | + # instead of being deleted and recreated. |
| 25 | + reuse_dirty_env: bool = field(default=True) |
| 26 | + |
| 27 | + |
17 | 28 | class ReadyPlatform(Platform):
|
18 | 29 | @classmethod
|
19 | 30 | def type_name(cls) -> str:
|
20 | 31 | return READY
|
21 | 32 |
|
| 33 | + def _initialize(self, *args: Any, **kwargs: Any) -> None: |
| 34 | + ready_runbook: ReadyPlatformSchema = self.runbook.get_extended_runbook( |
| 35 | + ReadyPlatformSchema |
| 36 | + ) |
| 37 | + assert ready_runbook, "platform runbook cannot be empty" |
| 38 | + self._ready_runbook = ready_runbook |
| 39 | + |
22 | 40 | @classmethod
|
23 | 41 | def supported_features(cls) -> List[Type[Feature]]:
|
24 | 42 | return [
|
@@ -65,8 +83,14 @@ def _deploy_environment(self, environment: Environment, log: Logger) -> None:
|
65 | 83 | pass
|
66 | 84 |
|
67 | 85 | def _delete_environment(self, environment: Environment, log: Logger) -> None:
|
68 |
| - # ready platform doesn't support delete environment |
69 |
| - pass |
| 86 | + if self._ready_runbook.reuse_dirty_env: |
| 87 | + log.debug( |
| 88 | + f"Environment '{environment.name}' was marked as 'Deleted' " |
| 89 | + "because it was dirty. Now resetting it to 'Prepared' since " |
| 90 | + "'reuse_dirty_env' is true, allowing test cases to reuse " |
| 91 | + "the environment." |
| 92 | + ) |
| 93 | + environment.status = EnvironmentStatus.Prepared |
70 | 94 |
|
71 | 95 |
|
72 | 96 | class SerialConsole(features.SerialConsole):
|
|
0 commit comments