Skip to content

Commit

Permalink
extension: add wait_for_all_extensions_to_finish before installing ex…
Browse files Browse the repository at this point in the history
…tension
  • Loading branch information
LiliDeng committed Sep 19, 2024
1 parent a5ef096 commit 40f31c7
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lisa/sut_orchestrator/azure/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import re
import string
import time
from dataclasses import dataclass, field
from functools import partial
from pathlib import Path
Expand Down Expand Up @@ -2810,6 +2811,47 @@ def get(
)
return extension

def wait_for_all_extensions_to_finish(
self, wait_for_all_extensions_to_finish: bool = True
) -> None:
if not wait_for_all_extensions_to_finish:
return

start_time = time.time()
max_wait_time = 300
check_interval = 10

while True:
extension_list = self.list_all()

if not extension_list:
self._log.debug("No extensions found for the VM. Exiting loop.")
break

all_extensions_completed = True

for extension in extension_list:
provisioning_state = extension.provisioning_state
self._log.debug(
f"Provisioning state of {extension.name}: {provisioning_state}"
)

if provisioning_state not in ["Failed", "Succeeded"]:
all_extensions_completed = False

if all_extensions_completed:
self._log.debug("All extensions have completed successfully.")
break

elapsed_time = time.time() - start_time
if elapsed_time > max_wait_time:
self._log.error(
f"Max wait time of {max_wait_time} seconds exceeded. Exiting loop."
)
break

time.sleep(check_interval)

def create_or_update(
self,
type_: str,
Expand All @@ -2824,6 +2866,7 @@ def create_or_update(
protected_settings: Any = None,
suppress_failures: Optional[bool] = None,
timeout: int = 60 * 25,
wait_for_all_extensions_to_finish: bool = True,
) -> Any:
platform: AzurePlatform = self._platform # type: ignore
compute_client = get_compute_client(platform)
Expand Down Expand Up @@ -2851,6 +2894,8 @@ def create_or_update(
sub="***REDACTED***",
)

self.wait_for_all_extensions_to_finish(wait_for_all_extensions_to_finish)

self._log.debug(f"extension_parameters: {extension_parameters.as_dict()}")

operation = compute_client.virtual_machine_extensions.begin_create_or_update(
Expand Down

0 comments on commit 40f31c7

Please sign in to comment.