From 7154139ce769ee74793bd774ecd97df7c94ba91e Mon Sep 17 00:00:00 2001 From: Tony Schneider Date: Tue, 12 Nov 2024 14:13:08 -0600 Subject: [PATCH] handle ResourceGroup ScopeLocked error --- .gitignore | 2 ++ .../azure-automation/resources-cleanup/requirements.txt | 2 +- .../resources-cleanup/src/resources_cleanup.py | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 39b5e0ea2..a3383022b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ env */archive.tar.gz tooling/bin tooling/image-sync/config.yml +**/venv +**/__pycache__ \ No newline at end of file diff --git a/tooling/azure-automation/resources-cleanup/requirements.txt b/tooling/azure-automation/resources-cleanup/requirements.txt index 54c2e3990..288fc1819 100644 --- a/tooling/azure-automation/resources-cleanup/requirements.txt +++ b/tooling/azure-automation/resources-cleanup/requirements.txt @@ -19,7 +19,7 @@ portalocker==2.8.2 pycparser==2.21 PyJWT==2.8.0 pytest==7.4.4 -requests==2.32.0 +requests==2.32.3 six==1.16.0 tomli==2.0.1 typing_extensions==4.9.0 diff --git a/tooling/azure-automation/resources-cleanup/src/resources_cleanup.py b/tooling/azure-automation/resources-cleanup/src/resources_cleanup.py index 5a7b00f45..3fb135541 100644 --- a/tooling/azure-automation/resources-cleanup/src/resources_cleanup.py +++ b/tooling/azure-automation/resources-cleanup/src/resources_cleanup.py @@ -120,10 +120,10 @@ def process_resource_group(resource_group: ResourceGroup, resource_client: Resou result_poller = resource_client.resource_groups.begin_delete(resource_group_name) print(f"result_poller of resource group deletion: {result_poller}") except HttpResponseError as err: - target_error_code = "DenyAssignmentAuthorizationFailed" - if err.error.code == target_error_code: - print("skipping deletion of resource group due to deny assignment in the resource group") - else: + error_codes = ("DenyAssignmentAuthorizationFailed", "ScopeLocked") + if err.error.code in error_codes: + print(f"skipping deletion of resource group due to error code {err.error.code}") + else: raise err