зеркало из https://github.com/microsoft/lisa.git
Support bool/string format for reserve_environment (#1103)
This commit is contained in:
Родитель
5973f6f1b7
Коммит
0fa3416979
|
@ -28,13 +28,13 @@ jobs:
|
|||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --preview --version 1.1.3
|
||||
echo "::add-path::$HOME/.poetry/bin"
|
||||
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install Poetry for Windows
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python - --preview --version 1.1.3
|
||||
echo "::add-path::$env:USERPROFILE\.poetry\bin"
|
||||
echo "$env:USERPROFILE\.poetry\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: make setup
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import copy
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, cast
|
||||
|
||||
from dataclasses_json import ( # type: ignore
|
||||
|
@ -27,6 +28,7 @@ Schema is dealt with three components,
|
|||
|
||||
|
||||
T = TypeVar("T")
|
||||
ReserveEnvStatus = Enum("ReserveEnvStatus", ["no", "always", "failed"])
|
||||
|
||||
|
||||
def metadata(
|
||||
|
@ -678,13 +680,13 @@ class Platform(TypedSchema, ExtendableSchemaMixin):
|
|||
admin_password: str = ""
|
||||
admin_private_key_file: str = ""
|
||||
|
||||
# True means not to delete an environment, even it's created by lisa
|
||||
reserve_environment: bool = False
|
||||
# no/False: means to delete the environment regardless case fail or pass
|
||||
# yes/always/True: means to keep the environment regardless case fail or pass
|
||||
reserve_environment: Optional[Union[str, bool]] = False
|
||||
|
||||
def __post_init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
add_secret(self.admin_username, PATTERN_HEADTAIL)
|
||||
add_secret(self.admin_password)
|
||||
add_secret(self.admin_private_key_file)
|
||||
|
||||
if self.type != constants.PLATFORM_READY:
|
||||
if self.admin_password and self.admin_private_key_file:
|
||||
|
@ -696,6 +698,14 @@ class Platform(TypedSchema, ExtendableSchemaMixin):
|
|||
"one of admin_password and admin_private_key_file must be set"
|
||||
)
|
||||
|
||||
if isinstance(self.reserve_environment, str):
|
||||
self.reserve_environment = self.reserve_environment.lower()
|
||||
allow_list = [x for x in ReserveEnvStatus.__members__.keys()]
|
||||
if self.reserve_environment not in allow_list:
|
||||
raise LisaException(
|
||||
f"reserve_environment only can be set as one of {allow_list}"
|
||||
)
|
||||
|
||||
|
||||
@dataclass_json(letter_case=LetterCase.CAMEL)
|
||||
@dataclass
|
||||
|
|
|
@ -557,7 +557,10 @@ class AzurePlatform(Platform):
|
|||
f"skipped to delete resource group: {resource_group_name}, "
|
||||
f"as it's not created by this run."
|
||||
)
|
||||
elif self._runbook.reserve_environment:
|
||||
elif (
|
||||
self._runbook.reserve_environment == schema.ReserveEnvStatus.always.name
|
||||
or self._runbook.reserve_environment is True
|
||||
):
|
||||
log.info(
|
||||
f"skipped to delete resource group: {resource_group_name}, "
|
||||
f"as runbook set to reserve environment."
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from dataclasses import dataclass, field
|
||||
from typing import Any, List, Type
|
||||
from typing import Any, List, Optional, Type, Union
|
||||
from unittest.case import TestCase
|
||||
|
||||
from dataclasses_json import LetterCase, dataclass_json # type: ignore
|
||||
|
@ -105,7 +105,7 @@ class MockPlatform(Platform):
|
|||
|
||||
|
||||
def generate_platform(
|
||||
reserve_environment: bool = False,
|
||||
reserve_environment: Optional[Union[str, bool]] = False,
|
||||
admin_password: str = "donot use for real",
|
||||
admin_key_file: str = "",
|
||||
) -> MockPlatform:
|
||||
|
|
Загрузка…
Ссылка в новой задаче