From fc3fa0c24a423cdbdc2b8e8223b8d8967230d3c3 Mon Sep 17 00:00:00 2001 From: Bin Du Date: Fri, 12 Mar 2021 13:24:13 -0800 Subject: [PATCH 1/5] Use "exists" api to check storage blob existence --- .../cli/command_modules/acr/_stream_utils.py | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py index 0fcaf285b41..0b1ae326bf2 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py @@ -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 @@ -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( - container_name=container_name, blob_name=blob_name) - metadata = props.metadata - available = props.properties.content_length + # 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) + + 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: + # Wait a little bit before checking the existence again + time.sleep(1) except (AttributeError, AzureHttpError): pass @@ -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( + 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) - metadata = props.metadata - available = props.properties.content_length except AzureHttpError as ae: if ae.status_code != 404: raise CLIError(ae) From 8b4f4ffd8bf9fa08441f64ea1483a9e729f62fe5 Mon Sep 17 00:00:00 2001 From: Bin Du Date: Fri, 12 Mar 2021 14:02:40 -0800 Subject: [PATCH 2/5] fix bug --- src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py index 0b1ae326bf2..bad45afae6e 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py @@ -78,7 +78,7 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme if not no_format: colorama.init() - log_exist = false + log_exist = False stream = BytesIO() metadata = {} start = 0 From 19511eb8f91d4e8bc7e028ed52e26f0912e7edf7 Mon Sep 17 00:00:00 2001 From: Bin Du Date: Fri, 12 Mar 2021 14:19:06 -0800 Subject: [PATCH 3/5] fix style --- src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py index bad45afae6e..4580f41cffe 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py @@ -156,7 +156,7 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme available = props.properties.content_length else: log_exist = blob_service.exists( - container_name=container_name, blob_name=blob_name) + container_name=container_name, blob_name=blob_name) except AzureHttpError as ae: if ae.status_code != 404: raise CLIError(ae) From ceb61c2d8c91fdb195d06042f951d06cf5298b6a Mon Sep 17 00:00:00 2001 From: Bin Du Date: Sat, 13 Mar 2021 11:59:42 -0800 Subject: [PATCH 4/5] fix style --- src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py index 4580f41cffe..acd85054b15 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py @@ -95,7 +95,7 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme try: # 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) + container_name=container_name, blob_name=blob_name) if log_exist: props = blob_service.get_blob_properties( From 31aca5318a97588dcb94729e6a75164cda4f483c Mon Sep 17 00:00:00 2001 From: Bin Du Date: Sat, 13 Mar 2021 12:23:46 -0800 Subject: [PATCH 5/5] fix indentation --- .../cli/command_modules/acr/_stream_utils.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py index acd85054b15..c97f63ff983 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py +++ b/src/azure-cli/azure/cli/command_modules/acr/_stream_utils.py @@ -98,13 +98,13 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme container_name=container_name, blob_name=blob_name) 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 + props = blob_service.get_blob_properties( + container_name=container_name, blob_name=blob_name) + metadata = props.metadata + available = props.properties.content_length else: - # Wait a little bit before checking the existence again - time.sleep(1) + # Wait a little bit before checking the existence again + time.sleep(1) except (AttributeError, AzureHttpError): pass @@ -150,13 +150,13 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme try: 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 + 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) + 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)