Skip to content

Commit

Permalink
add _global_storage_account_check_create_lock to prevent, two process…
Browse files Browse the repository at this point in the history
…es create the same storage account at the same time.
  • Loading branch information
LiliDeng committed May 6, 2023
1 parent 85201c5 commit bb8bd24
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lisa/sut_orchestrator/azure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
# when call sdk APIs, it's easy to have conflict on access auth files. Use lock
# to prevent it happens.
global_credential_access_lock = Lock()
# if user uses lisa for the first time in parallel, there will be a possiblilty
# to create the same stroage account at the same time.
# add a lock to prevent it happens.
_global_storage_account_check_create_lock = Lock()


@dataclass
Expand Down Expand Up @@ -1092,26 +1096,27 @@ def check_or_create_storage_account(
# will be error like below
# Creating the deployment 'name' would exceed the quota of '800'.
storage_client = get_storage_client(credential, subscription_id, cloud)
try:
storage_client.storage_accounts.get_properties(
account_name=account_name,
resource_group_name=resource_group_name,
)
log.debug(f"found storage account: {account_name}")
except Exception:
log.debug(f"creating storage account: {account_name}")
parameters = StorageAccountCreateParameters(
sku=Sku(name=sku),
kind=kind,
location=location,
enable_https_traffic_only=enable_https_traffic_only,
)
operation = storage_client.storage_accounts.begin_create(
resource_group_name=resource_group_name,
account_name=account_name,
parameters=parameters,
)
wait_operation(operation)
with _global_storage_account_check_create_lock:
try:
storage_client.storage_accounts.get_properties(
account_name=account_name,
resource_group_name=resource_group_name,
)
log.debug(f"found storage account: {account_name}")
except Exception:
log.debug(f"creating storage account: {account_name}")
parameters = StorageAccountCreateParameters(
sku=Sku(name=sku),
kind=kind,
location=location,
enable_https_traffic_only=enable_https_traffic_only,
)
operation = storage_client.storage_accounts.begin_create(
resource_group_name=resource_group_name,
account_name=account_name,
parameters=parameters,
)
wait_operation(operation)


def delete_storage_account(
Expand Down

0 comments on commit bb8bd24

Please sign in to comment.