Skip to content

Commit

Permalink
additional error handling for role assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
landscapepainter committed Jul 3, 2024
1 parent 0cd9d73 commit 33fff63
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions sky/data/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,8 +2272,8 @@ def _create_storage_account(self, resource_group_name: str, storage_account_name
Raises:
StorageBucketCreateError: If storage account attempted to be
created already exists
AttributeError: When role assignment to the storage account fails.
created already exists or fails to assign role to the create
storage account.
"""
try:
creation_response = (
Expand Down Expand Up @@ -2339,6 +2339,9 @@ async def get_object_id():
# it propagates
role_assignment_start = time.time()
retry = 0
role_assignment_failure_error_msg = (
'Failed to assign Storage Blob Data Owner role to the '
f'storage account {storage_account_name!r}. ')
while (
time.time() - role_assignment_start
< _WAIT_FOR_STORAGE_ACCOUNT_CREATION):
Expand All @@ -2365,7 +2368,27 @@ async def get_object_id():
time.sleep(1)
retry += 1
continue
raise
with ux_utils.print_exception_no_traceback():
raise exceptions.StorageBucketCreateError(
f'{role_assignment_failure_error_msg}'
f'Details: {common_utils.format_exception(error, use_bracket=True)}'
)
except azure.exceptions().HttpResponseError as e:
if 'AuthorizationFailed' in str(e):
with ux_utils.print_exception_no_traceback():
raise exceptions.StorageBucketCreateError(
f'{role_assignment_failure_error_msg}'
'Please check to see if you have the authorization'
' "Microsoft.Authorization/roleAssignments/write" '
'to assign the role.'
)
else:
with ux_utils.print_exception_no_traceback():
raise exceptions.StorageBucketCreateError(
f'{role_assignment_failure_error_msg}'
f'Details: {common_utils.format_exception(error, use_bracket=True)}'
)


def upload(self):
"""Uploads source to store bucket.
Expand Down

0 comments on commit 33fff63

Please sign in to comment.