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

[Storage] Fix #21966: az storage blob download-batch: Fix failure when --pattern is blob name #22072

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ def test_storage_blob_batch_download_scenarios(self, test_dir, storage_account_i
# upload test files to storage account
self.storage_cmd('storage blob upload-batch -s "{}" -d {} --max-connections 3', storage_account_info,
test_dir, src_container)
from azure.cli.core.azclierror import AzureResponseError
with self.assertRaises(AzureResponseError):
self.storage_cmd('storage blob upload-batch -s "{}" -d {} --max-connections 3', storage_account_info,
test_dir, src_container)

# test upload-batch with & without --overwrite
self.storage_cmd('storage blob upload-batch -s "{}" -d {} --max-connections 3', storage_account_info,
test_dir, src_container).assert_with_checks(JMESPathCheck('length(@)', 0))
self.storage_cmd('storage blob upload-batch -s "{}" -d {} --max-connections 3 --overwrite', storage_account_info,
test_dir, src_container)
self.storage_cmd('storage blob list -c {}', storage_account_info, src_container).assert_with_checks(
JMESPathCheck('length(@)', 41))
test_dir, src_container).assert_with_checks(JMESPathCheck('length(@)', 41))

# download recursively without pattern
local_folder = self.create_temp_dir()
Expand Down Expand Up @@ -57,6 +55,12 @@ def test_storage_blob_batch_download_scenarios(self, test_dir, storage_account_i
local_folder, '*/file_0')
self.assertEqual(4, sum(len(f) for r, d, f in os.walk(local_folder)))

# download blob without wild cards
local_folder = self.create_temp_dir()
self.storage_cmd('storage blob download-batch -s {} -d "{}" --pattern {}', storage_account_info, src_container,
local_folder, 'apple/file_0')
self.assertEqual(1, sum(len(f) for r, d, f in os.walk(local_folder)))

# upload blobs with names that start with path separator
local_file = self.create_temp_file(1)
src_container = self.create_container(storage_account_info)
Expand Down
7 changes: 5 additions & 2 deletions src/azure-cli/azure/cli/command_modules/storage/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ def collect_blob_objects(blob_service, container, pattern=None):
raise ValueError('missing parameter container')

if not _pattern_has_wildcards(pattern):
if blob_service.exists(container, pattern):
yield pattern, blob_service.get_blob_properties(container, pattern)
from azure.core.exceptions import ResourceNotFoundError
try:
yield pattern, blob_service.get_blob_client(container, pattern).get_blob_properties()
except ResourceNotFoundError:
return
else:
if hasattr(blob_service, 'list_blobs'):
blobs = blob_service.list_blobs(container)
Expand Down