Skip to content

Commit f79f493

Browse files
committed
Add cleanup hints for failed delete operations
1 parent 731ae7b commit f79f493

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

ads/aqua/verify_policies/entities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from dataclasses import dataclass
2+
from typing import Optional
3+
24
from ads.common.extended_enum import ExtendedEnum
35
from ads.common.serializer import DataClassSerializable
46

@@ -20,6 +22,7 @@ class OperationResultFailure(DataClassSerializable):
2022
operation: str
2123
error: str
2224
policy_hint: str
25+
cleanup_hint: Optional[str] = None
2326
status: PolicyStatus = PolicyStatus.FAILURE
2427

2528

ads/aqua/verify_policies/messages.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@
6060
utils.aqua_model.delete_model.__name__: {
6161
"name": "Delete Model",
6262
"error": "Could not delete model. Please confirm you have delete permissions for Model Catalog resources in the compartment.",
63-
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-models in compartment <your-compartment-name>"
63+
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-models in compartment <your-compartment-name>",
64+
"cleanup_hint": (
65+
f'Automatic cleanup of resources failed due to missing policies. '
66+
f'A model with the name "{TEST_MODEL_NAME}" and a test file with the name "{OBS_MANAGE_TEST_FILE}" '
67+
f'have been created in the Object Storage bucket you specified. '
68+
f'Please manually delete the resources to prevent incurring charges.'
69+
)
70+
6471
},
6572
utils.create_job.__name__: {
6673
"name": "Create Job",
@@ -75,7 +82,13 @@
7582
"delete_job": {
7683
"name": "Delete Job",
7784
"error": "Job could not be deleted. Please check if you have permissions to delete Data Science jobs.",
78-
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-jobs in compartment <your-compartment-name>"
85+
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-jobs in compartment <your-compartment-name>",
86+
"cleanup_hint": (
87+
f'Automatic cleanup of resources failed due to missing policies. '
88+
f'A job with the name "{TEST_JOB_NAME}" and a test file with the name "{OBS_MANAGE_TEST_FILE}" '
89+
f'have been created in the Object Storage bucket you specified. '
90+
f'Please manually delete the resources to prevent incurring charges.'
91+
)
7992
},
8093
utils.aqua_model.create_model_version_set.__name__: {
8194
"name": "Create Model Version Set",
@@ -85,7 +98,13 @@
8598
utils.aqua_model.ds_client.delete_model_version_set.__name__: {
8699
"name": "Delete Model Version Set",
87100
"error": "Unable to delete a model version. Ensure that required Model Catalog permissions are set.",
88-
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-modelversionsets in compartment <your-compartment-name>"
101+
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-modelversionsets in compartment <your-compartment-name>",
102+
"cleanup_hint": (
103+
f'Automatic cleanup of resources failed due to missing policies. '
104+
f'A model version set with the name "{TEST_MVS_NAME}" and a test file with the name "{OBS_MANAGE_TEST_FILE}" '
105+
f'have been created in the Object Storage bucket you specified. '
106+
f'Please manually delete the resources to prevent incurring charges.'
107+
)
89108
},
90109
utils.create_model_deployment.__name__: {
91110
"name": "Create Model Deployment",
@@ -95,7 +114,13 @@
95114
utils.aqua_model.ds_client.delete_model_deployment.__name__: {
96115
"name": "Delete Model Deployment",
97116
"error": "Unable to delete the model deployment. Please check if you have appropriate permissions to manage deployments.",
98-
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-model-deployments in compartment <your-compartment-name>"
117+
"policy_hint": "Allow dynamic-group aqua-dynamic-group to manage data-science-model-deployments in compartment <your-compartment-name>",
118+
"cleanup_hint": (
119+
f'Automatic cleanup of resources failed due to missing policies. '
120+
f'A model deployment with the name "{TEST_MD_NAME}" and a test file with the name "{OBS_MANAGE_TEST_FILE}" '
121+
f'have been created in the Object Storage bucket you specified. '
122+
f'Please manually delete the resources to prevent incurring charges.'
123+
)
99124
}
100125

101126
}

ads/aqua/verify_policies/verify.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def run_func():
5454
logger.warning(result_message)
5555
logger.info(result_status.error)
5656
logger.info(f"Policy hint: {result_status.policy_hint}")
57+
if getattr(result_status, "cleanup_hint", None):
58+
logger.info(result_status.cleanup_hint)
5759
logger.info(f"Refer to: {POLICY_HELP_LINK}")
5860

5961
return return_value, result_status
@@ -115,6 +117,7 @@ def _get_operation_result(self, operation, status):
115117
operation=operation_message["name"],
116118
error=operation_message["error"],
117119
policy_hint=f"{operation_message['policy_hint']}",
120+
cleanup_hint=operation_message.get("cleanup_hint"),
118121
)
119122

120123
@with_spinner

0 commit comments

Comments
 (0)