Skip to content
Open
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
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-file-datalake/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/storage/azure-storage-file-datalake",
"Tag": "python/storage/azure-storage-file-datalake_c0870501f2"
"Tag": "python/storage/azure-storage-file-datalake_b358bed301"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"""
import os
import sys

from azure.core.exceptions import HttpResponseError
from azure.storage.filedatalake import DataLakeServiceClient, DelimitedJsonDialect, DelimitedTextDialect

CSV_DATA = b'Service,Package,Version,RepoPath,MissingDocs\r\nApp Configuration,' \
Expand Down Expand Up @@ -64,7 +66,7 @@ def main():
filesystem_client = datalake_service_client.get_file_system_client(filesystem_name)
try:
filesystem_client.create_file_system()
except:
except HttpResponseError:
pass
# [START query]
errors = []
Expand All @@ -77,9 +79,20 @@ def on_error(error):

# select the second column of the csv file
query_expression = "SELECT _2 from DataLakeStorage"
input_format = DelimitedTextDialect(delimiter=',', quotechar='"', lineterminator='\n', escapechar="", has_header=False)
input_format = DelimitedTextDialect(
delimiter=',',
quotechar='"',
lineterminator='\n',
escapechar="",
has_header=False
)
output_format = DelimitedJsonDialect(delimiter='\n')
reader = file_client.query_file(query_expression, on_error=on_error, file_format=input_format, output_format=output_format)
reader = file_client.query_file(
query_expression,
on_error=on_error,
file_format=input_format,
output_format=output_format
)
content = reader.readall()
# [END query]
print(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import asyncio
import os

from datetime import datetime, timedelta
from azure.storage.filedatalake.aio import DataLakeServiceClient


connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING']
account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "")

Expand All @@ -34,8 +38,6 @@ async def main():

# Instantiate a DataLakeServiceClient using a connection string
# [START create_datalake_service_client]
from azure.storage.filedatalake.aio import DataLakeServiceClient
from datetime import datetime, timedelta, timezone

datalake_service_client = DataLakeServiceClient.from_connection_string(connection_string)
# [END create_datalake_service_client]
Expand All @@ -51,7 +53,6 @@ async def main():
async with datalake_service_client:
# get user delegation key
# [START get_user_delegation_key]
from datetime import datetime, timedelta
user_delegation_key = await datalake_service_client.get_user_delegation_key(datetime.utcnow(),
datetime.utcnow() + timedelta(hours=1))
# [END get_user_delegation_key]
Expand Down Expand Up @@ -84,7 +85,8 @@ async def main():
from azure.storage.filedatalake import ContentSettings
content_settings = ContentSettings(
content_language='spanish',
content_disposition='inline')
content_disposition='inline'
)
await file_client.create_file(content_settings=content_settings)
await file_client.set_metadata(metadata=metadata)
file_props = await file_client.get_file_properties()
Expand All @@ -103,5 +105,6 @@ async def main():

await token_credential.close()


if __name__ == '__main__':
asyncio.run(main())
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import uuid

from devtools_testutils.perfstress_tests import PerfStressTest

from azure.core.exceptions import ResourceNotFoundError
from azure.storage.filedatalake import DataLakeServiceClient as SyncDataLakeServiceClient
from azure.storage.filedatalake.aio import DataLakeServiceClient as AsyncDataLakeServiceClient

Expand All @@ -22,7 +20,8 @@ def __init__(self, arguments):
connection_string = self.get_from_env("AZURE_STORAGE_CONNECTION_STRING")
if not _ServiceTest.service_client or self.args.no_client_share:
_ServiceTest.service_client = SyncDataLakeServiceClient.from_connection_string(conn_str=connection_string)
_ServiceTest.async_service_client = AsyncDataLakeServiceClient.from_connection_string(conn_str=connection_string)
_ServiceTest.async_service_client = AsyncDataLakeServiceClient.from_connection_string(
conn_str=connection_string)
self.service_client = _ServiceTest.service_client
self.async_service_client =_ServiceTest.async_service_client

Expand All @@ -33,9 +32,28 @@ async def close(self):
@staticmethod
def add_arguments(parser):
super(_ServiceTest, _ServiceTest).add_arguments(parser)
parser.add_argument('-c', '--max-concurrency', nargs='?', type=int, help='Maximum number of concurrent threads used for data transfer. Defaults to 1', default=1)
parser.add_argument('-s', '--size', nargs='?', type=int, help='Size of data to transfer. Default is 10240.', default=10240)
parser.add_argument('--no-client-share', action='store_true', help='Create one ServiceClient per test instance. Default is to share a single ServiceClient.', default=False)
parser.add_argument(
'-c',
'--max-concurrency',
nargs='?',
type=int,
help='Maximum number of concurrent threads used for data transfer. Defaults to 1',
default=1
)
parser.add_argument(
'-s',
'--size',
nargs='?',
type=int,
help='Size of data to transfer. Default is 10240.',
default=10240
)
parser.add_argument(
'--no-client-share',
action='store_true',
help='Create one ServiceClient per test instance. Default is to share a single ServiceClient.',
default=False
)


class _FileSystemTest(_ServiceTest):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from ._test_base import _FileTest
from devtools_testutils.perfstress_tests import AsyncRandomStream, RandomStream

from devtools_testutils.perfstress_tests import RandomStream
from devtools_testutils.perfstress_tests import AsyncRandomStream
from ._test_base import _FileTest


class UploadTest(_FileTest):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=unused-wildcard-import, wildcard-import

import functools
import os.path

from devtools_testutils import EnvironmentVariableLoader, EnvironmentVariableOptions
from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY

try:
from cStringIO import StringIO # Python 2
except ImportError:
from io import StringIO

try:
# Running locally - use configuration in settings_real.py
Expand All @@ -25,14 +22,19 @@

LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s'
LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s'
os.environ['DATALAKE_STORAGE_ACCOUNT_NAME'] = os.environ.get('DATALAKE_STORAGE_ACCOUNT_NAME', None) or DATALAKE_STORAGE_ACCOUNT_NAME
os.environ['DATALAKE_STORAGE_ACCOUNT_KEY'] = os.environ.get('DATALAKE_STORAGE_ACCOUNT_KEY', None) or DATALAKE_STORAGE_ACCOUNT_KEY
os.environ['DATALAKE_STORAGE_ACCOUNT_NAME'] = (os.environ.get('DATALAKE_STORAGE_ACCOUNT_NAME', None) or
DATALAKE_STORAGE_ACCOUNT_NAME)
os.environ['DATALAKE_STORAGE_ACCOUNT_KEY'] = (os.environ.get('DATALAKE_STORAGE_ACCOUNT_KEY', None) or
DATALAKE_STORAGE_ACCOUNT_KEY)

os.environ['STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME'] = os.environ.get('STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME', None) or STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME
os.environ['STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_KEY'] = os.environ.get('STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_KEY', None) or STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_KEY
os.environ['STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME'] = os.environ.get(
'STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME', None) or STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME
os.environ['STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_KEY'] = os.environ.get(
'STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_KEY', None) or STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_KEY

os.environ['AZURE_TEST_RUN_LIVE'] = os.environ.get('AZURE_TEST_RUN_LIVE', None) or RUN_IN_LIVE
os.environ['AZURE_SKIP_LIVE_RECORDING'] = os.environ.get('AZURE_SKIP_LIVE_RECORDING', None) or SKIP_LIVE_RECORDING
os.environ['AZURE_SKIP_LIVE_RECORDING'] = os.environ.get(
'AZURE_SKIP_LIVE_RECORDING', None) or SKIP_LIVE_RECORDING
os.environ['PROTOCOL'] = PROTOCOL
os.environ['ACCOUNT_URL_SUFFIX'] = ACCOUNT_URL_SUFFIX

Expand All @@ -42,5 +44,7 @@
datalake_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
storage_data_lake_soft_delete_account_name="storagesoftdelname",
storage_data_lake_soft_delete_account_key=STORAGE_ACCOUNT_FAKE_KEY,
options=EnvironmentVariableOptions(hide_secrets=["datalake_storage_account_key", "storage_data_lake_soft_delete_account_key"]),
options=EnvironmentVariableOptions(
hide_secrets=["datalake_storage_account_key", "storage_data_lake_soft_delete_account_key"]
),
)
7 changes: 4 additions & 3 deletions sdk/storage/azure-storage-file-datalake/tests/test_cpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
# license information.
# --------------------------------------------------------------------------

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.storage.filedatalake import CustomerProvidedEncryptionKey, DataLakeServiceClient

from devtools_testutils import recorded_by_proxy
from devtools_testutils.storage import StorageRecordedTestCase
from settings.testcase import DataLakePreparer
from test_quick_query import DATALAKE_CSV_DATA

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.storage.filedatalake import CustomerProvidedEncryptionKey, DataLakeServiceClient


# ------------------------------------------------------------------------------
TEST_DIRECTORY_PREFIX = 'directory'
TEST_FILE_PREFIX = 'file'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
# license information.
# --------------------------------------------------------------------------

import asyncio
from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase
from settings.testcase import DataLakePreparer

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.storage.filedatalake import CustomerProvidedEncryptionKey
from azure.storage.filedatalake.aio import DataLakeServiceClient

from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase
from settings.testcase import DataLakePreparer

# ------------------------------------------------------------------------------
TEST_DIRECTORY_PREFIX = 'directory'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
# license information.
# --------------------------------------------------------------------------

import pytest
from typing import NamedTuple
from unittest.mock import MagicMock

import pytest

from devtools_testutils import recorded_by_proxy
from devtools_testutils.storage import StorageRecordedTestCase
from settings.testcase import DataLakePreparer

from azure.core.credentials import AzureNamedKeyCredential
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
from azure.core.exceptions import HttpResponseError
from azure.storage.filedatalake import (
AnalyticsLogging,
CorsRule,
Expand All @@ -19,13 +24,10 @@
FileSystemClient,
Metrics,
RetentionPolicy,
StaticWebsite
StaticWebsite,
)
from azure.storage.filedatalake._shared.parser import DEVSTORE_ACCOUNT_KEY, DEVSTORE_ACCOUNT_NAME

from devtools_testutils import recorded_by_proxy
from devtools_testutils.storage import StorageRecordedTestCase
from settings.testcase import DataLakePreparer

# ------------------------------------------------------------------------------
TEST_FILE_SYSTEM_PREFIX = 'filesystem'
Expand Down Expand Up @@ -99,9 +101,7 @@ def _assert_cors_equal(self, cors1, cors2):

assert len(cors1) == len(cors2)

for i in range(0, len(cors1)):
rule1 = cors1[i]
rule2 = cors2[i]
for rule1, rule2 in zip(cors1, cors2):
assert len(rule1.allowed_origins) == len(rule2.allowed_origins)
assert len(rule1.allowed_methods) == len(rule2.allowed_methods)
assert rule1.max_age_in_seconds == rule2.max_age_in_seconds
Expand Down Expand Up @@ -441,7 +441,7 @@ def test_azure_named_key_credential_access(self, **kwargs):
assert props is not None

@DataLakePreparer()
def test_datalake_clients_properly_close(self, **kwargs):
def test_datalake_clients_properly_close(self):
account_name = "adlsstorage"
# secret attribute necessary for credential parameter because of hidden environment variables from loader
account_key = NamedTuple("StorageAccountKey", [("secret", str)])("adlskey")
Expand All @@ -463,13 +463,13 @@ def test_datalake_clients_properly_close(self, **kwargs):

# Act
with self.dsc as dsc:
pass
pass # pylint: disable=unnecessary-pass
with file_system_client as fsc:
pass
pass # pylint: disable=unnecessary-pass
with dir_client as dc:
pass
pass # pylint: disable=unnecessary-pass
with file_client as fc:
pass
pass # pylint: disable=unnecessary-pass

# Assert
self.dsc._blob_service_client.__exit__.assert_called_once()
Expand Down Expand Up @@ -520,7 +520,7 @@ def test_bad_audience_service_client(self, **kwargs):
dsc = DataLakeServiceClient(
self.account_url(datalake_storage_account_name, "blob"),
credential=token_credential,
audience=f'https://badaudience.blob.core.windows.net/'
audience='https://badaudience.blob.core.windows.net/'
)

# Will not raise ClientAuthenticationError despite bad audience due to Bearer Challenge
Expand Down
Loading
Loading