diff --git a/securitycenter/snippets_management_api/security_health_analytics_custom_module_test.py b/securitycenter/snippets_management_api/security_health_analytics_custom_module_test.py index b48b85e557e3..8fddb4ea3141 100644 --- a/securitycenter/snippets_management_api/security_health_analytics_custom_module_test.py +++ b/securitycenter/snippets_management_api/security_health_analytics_custom_module_test.py @@ -17,14 +17,14 @@ import backoff -from google.api_core.exceptions import InternalServerError, NotFound, ServiceUnavailable - import random -from google.cloud import securitycentermanagement_v1 +from google.api_core.exceptions import InternalServerError, NotFound, ServiceUnavailable import time +from google.cloud import securitycentermanagement_v1 + import pytest import security_health_analytics_custom_modules @@ -54,7 +54,8 @@ def cleanup_existing_custom_modules(org_id: str): """ client = securitycentermanagement_v1.SecurityCenterManagementClient() parent = f"organizations/{org_id}/locations/global" - + print(f"Parent path: {parent}") + try: custom_modules = client.list_security_health_analytics_custom_modules( request={"parent": parent} @@ -65,8 +66,11 @@ def cleanup_existing_custom_modules(org_id: str): request={"name": module.name} ) print(f"Deleted custom module: {module.name}") - except NotFound: - print(f"Custom Module not found for deletion: {module.name}") + except NotFound as e: + print(f"Resource not found: {e}") + except Exception as e: + print(f"Unexpected error during cleanup: {e}") + raise def add_custom_module(org_id: str):