Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACR] Fix#16700: Use "exists" api to check storage blob existence #17299

Merged
merged 5 commits into from
Mar 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
if not no_format:
colorama.init()

log_exist = False
stream = BytesIO()
metadata = {}
start = 0
Expand All @@ -92,10 +93,18 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
# Try to get the initial properties so there's no waiting.
# If the storage call fails, we'll just sleep and try again after.
try:
props = blob_service.get_blob_properties(
# Need to call "exists" API to prevent storage SDK logging BlobNotFound error
log_exist = blob_service.exists(
container_name=container_name, blob_name=blob_name)
metadata = props.metadata
available = props.properties.content_length

if log_exist:
props = blob_service.get_blob_properties(
container_name=container_name, blob_name=blob_name)
metadata = props.metadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@northtyphoon can props be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it will throw error like AureHttpError, in that case, we will retry or just exit if the code doesn't know how to handle it

available = props.properties.content_length
else:
# Wait a little bit before checking the existence again
time.sleep(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does it retry after sleep?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code will continue to the loop, since log_exists is false in this case, it will execute L158-159 to check the existence again

except (AttributeError, AzureHttpError):
pass

Expand Down Expand Up @@ -140,10 +149,14 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
return

try:
props = blob_service.get_blob_properties(
container_name=container_name, blob_name=blob_name)
metadata = props.metadata
available = props.properties.content_length
if log_exist:
props = blob_service.get_blob_properties(
container_name=container_name, blob_name=blob_name)
metadata = props.metadata
available = props.properties.content_length
else:
log_exist = blob_service.exists(
container_name=container_name, blob_name=blob_name)
except AzureHttpError as ae:
if ae.status_code != 404:
raise CLIError(ae)
Expand Down