Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LiliDeng committed Sep 11, 2024
1 parent a1358de commit 10ecc7a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
49 changes: 35 additions & 14 deletions lisa/runners/lisa_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,30 +290,51 @@ def _prepare_environments(self) -> None:
def _deploy_environment_task(
self, environment: Environment, test_results: List[TestResult]
) -> None:
try:
test_result = test_results[0]
retry_deployment = getattr(test_result.runtime_data, "retry_deployment", 0)
max_retries = max(retry_deployment, 1) # Ensure at least one attempt

for attempt in range(max_retries):
try:
# if throw_exception:
# raise LisaException("test")
# Attempt to deploy the environment
self.platform.deploy_environment(environment)
assert (
environment.status == EnvironmentStatus.Deployed
), f"actual: {environment.status}"
if environment.status != EnvironmentStatus.Deployed:
raise AssertionError(
f"Expected status: {EnvironmentStatus.Deployed}, actual: {environment.status}"
)

# Reset the awaitable timer and exit loop on success
self._reset_awaitable_timer("deploy")
break

except ResourceAwaitableException as identifier:
if self._is_awaitable_timeout("deploy"):
self._log.info(
f"[{environment.name}] timeout on waiting for more resource: "
f"{identifier}, skip assigning case."
f"[{environment.name}] Timeout while waiting for more resources: {identifier}. Skipping case."
)
raise SkippedException(identifier)
else:
# rerun prepare to calculate resource again.
# Recalculate resources and retry
environment.status = EnvironmentStatus.New
except Exception as identifier:
self._attach_failed_environment_to_result(
environment=environment,
result=test_results[0],
exception=identifier,
)
self._delete_environment_task(environment=environment, test_results=[])

except Exception as identifier:
if attempt >= max_retries - 1:
# Final attempt failed; attach result and delete environment
self._attach_failed_environment_to_result(
environment=environment,
result=test_result,
exception=identifier,
)
self._delete_environment_task(
environment=environment, test_results=[]
)
else:
# Log retry information and continue to the next attempt
self._log.info(
f"[{environment.name}] Deployment failed, retrying... (Attempt {attempt + 1}/{max_retries})"
)

def _initialize_environment_task(
self, environment: Environment, test_results: List[TestResult]
Expand Down
1 change: 1 addition & 0 deletions lisa/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ def __init__(self, metadata: TestCaseMetadata):
self.select_action: str = ""
self.times: int = 1
self.retry: int = 0
self.retry_deployment: int = 3
self.use_new_environment: bool = metadata.use_new_environment
self.ignore_failure: bool = False
self.environment_name: str = ""
Expand Down

0 comments on commit 10ecc7a

Please sign in to comment.