handle azure-storage deleting nonexistent containers (#948)

This commit is contained in:
bmc-msft
2021-06-02 11:11:33 -04:00
committed by GitHub
parent 74c0e0a5c5
commit 60ae07c34f

View File

@ -10,7 +10,7 @@ import urllib.parse
from typing import Dict, Optional, Union, cast from typing import Dict, Optional, Union, cast
from azure.common import AzureHttpError, AzureMissingResourceHttpError from azure.common import AzureHttpError, AzureMissingResourceHttpError
from azure.core.exceptions import ResourceExistsError from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.storage.blob import ( from azure.storage.blob import (
BlobClient, BlobClient,
BlobSasPermissions, BlobSasPermissions,
@ -146,12 +146,16 @@ def create_container(
def delete_container(container: Container, storage_type: StorageType) -> bool: def delete_container(container: Container, storage_type: StorageType) -> bool:
accounts = get_accounts(storage_type) accounts = get_accounts(storage_type)
deleted = False
for account in accounts: for account in accounts:
service = get_blob_service(account) service = get_blob_service(account)
if bool(service.delete_container(container)): try:
return True service.delete_container(container)
deleted = True
except ResourceNotFoundError:
pass
return False return deleted
def get_container_sas_url_service( def get_container_sas_url_service(