Skip to content
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 @@ -147,4 +147,3 @@ def authentication_default_azure_credential(self):
sample.authentication_shared_access_key()
sample.authentication_shared_access_signature()
sample.authentication_default_azure_credential()

Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,3 @@ def acquire_file_lease(self):
sample.simple_file_operations()
sample.copy_file_from_url()
sample.acquire_file_lease()


Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,3 @@ def get_share_client(self):
sample.file_service_properties()
sample.list_shares_in_service()
sample.get_share_client()

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric.padding import (
OAEP,
Expand All @@ -16,6 +17,9 @@
)


_ERROR_UNKNOWN_KEY_WRAP_ALGORITHM = "Unknown keywrap algorithm specified. Supported algorithm: A256KW."


class KeyWrapper:
def __init__(self, kid='local:key1'):
# Must have constant key value for recorded tests, otherwise we could use a random generator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
# 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.storage.file import FileService
from azure.storage.file import FileService # pylint: disable=no-name-in-module

class _LegacyServiceTest(PerfStressTest):
service_client = None
async_service_client = None

def __init__(self, arguments):
super().__init__(arguments)
super().__init__(arguments) # pylint: disable=useless-parent-delegation
connection_string = self.get_from_env("AZURE_STORAGE_CONNECTION_STRING")
if not _LegacyServiceTest.service_client or self.args.no_client_share:
_LegacyServiceTest.service_client = FileService(connection_string=connection_string)
Expand All @@ -27,16 +26,42 @@ def __init__(self, arguments):
@staticmethod
def add_arguments(parser):
super(_LegacyServiceTest, _LegacyServiceTest).add_arguments(parser)
parser.add_argument('-r', '--max-range-size', nargs='?', type=int, help='Maximum size of data uploading in single HTTP PUT. Defaults to 4*1024*1024', default=4*1024*1024)
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(
'-r',
'--max-range-size',
nargs='?',
type=int,
help='Maximum size of data uploading in single HTTP PUT. Defaults to 4*1024*1024',
default=4*1024*1024
)
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 _LegacyShareTest(_LegacyServiceTest):
share_name = "perfstress-legacy-" + str(uuid.uuid4())

def __init__(self, arguments):
def __init__(self, arguments): # pylint: disable=useless-parent-delegation
super().__init__(arguments)

async def global_setup(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import uuid

from devtools_testutils.perfstress_tests import RandomStream, get_random_bytes
from devtools_testutils.perfstress_tests import RandomStream

from ._test_base import _LegacyShareTest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# 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
Expand All @@ -23,8 +22,14 @@ def __init__(self, arguments):
if self.args.max_range_size is not None:
kwargs['max_range_size'] = self.args.max_range_size
if not _ServiceTest.service_client or self.args.no_client_share:
_ServiceTest.service_client = SyncShareServiceClient.from_connection_string(conn_str=connection_string, **kwargs)
_ServiceTest.async_service_client = AsyncShareServiceClient.from_connection_string(conn_str=connection_string, **kwargs)
_ServiceTest.service_client = SyncShareServiceClient.from_connection_string(
conn_str=connection_string,
**kwargs
)
_ServiceTest.async_service_client = AsyncShareServiceClient.from_connection_string(
conn_str=connection_string,
**kwargs
)
self.service_client = _ServiceTest.service_client
self.async_service_client =_ServiceTest.async_service_client

Expand All @@ -35,10 +40,36 @@ async def close(self):
@staticmethod
def add_arguments(parser):
super(_ServiceTest, _ServiceTest).add_arguments(parser)
parser.add_argument('-r', '--max-range-size', nargs='?', type=int, help='Maximum size of data uploading in single HTTP PUT. Defaults to SDK default.', default=None)
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(
'-r',
'--max-range-size',
nargs='?',
type=int,
help='Maximum size of data uploading in single HTTP PUT. Defaults to SDK default.',
default=None
)
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 _ShareTest(_ServiceTest):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# 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 RandomStream, get_random_bytes
from devtools_testutils.perfstress_tests import RandomStream
from devtools_testutils.perfstress_tests import AsyncRandomStream

from ._test_base import _FileTest


class UploadTest(_FileTest):
def __init__(self, arguments):
Expand Down
34 changes: 13 additions & 21 deletions sdk/storage/azure-storage-file-share/tests/settings/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
# pylint: disable=unused-wildcard-import, wildcard-import

from __future__ import division

import functools
import os.path

try:
import unittest.mock as mock
except ImportError:
import mock

import logging
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 @@ -29,20 +21,18 @@
# Running on the pipeline - use fake values in order to create rg, etc.
from .settings_fake import *

try:
from devtools_testutils import mgmt_settings_real as settings
except ImportError:
from devtools_testutils import mgmt_settings_fake as settings



LOGGING_FORMAT = '%(asctime)s %(name)-20s %(levelname)-5s %(message)s'
os.environ['STORAGE_ACCOUNT_NAME'] = os.environ.get('STORAGE_ACCOUNT_NAME', None) or STORAGE_ACCOUNT_NAME
os.environ['STORAGE_ACCOUNT_KEY'] = os.environ.get('STORAGE_ACCOUNT_KEY', None) or STORAGE_ACCOUNT_KEY
os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_NAME'] = os.environ.get('PREMIUM_STORAGE_FILE_ACCOUNT_NAME', None) or PREMIUM_STORAGE_FILE_ACCOUNT_NAME
os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_KEY'] = os.environ.get('PREMIUM_STORAGE_FILE_ACCOUNT_KEY', None) or PREMIUM_STORAGE_FILE_ACCOUNT_KEY
os.environ['SECONDARY_STORAGE_ACCOUNT_NAME'] = os.environ.get('SECONDARY_STORAGE_ACCOUNT_NAME', None) or SECONDARY_STORAGE_ACCOUNT_NAME
os.environ['SECONDARY_STORAGE_ACCOUNT_KEY'] = os.environ.get('SECONDARY_STORAGE_ACCOUNT_KEY', None) or SECONDARY_STORAGE_ACCOUNT_KEY
os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_NAME'] = os.environ.get(
'PREMIUM_STORAGE_FILE_ACCOUNT_NAME', None) or PREMIUM_STORAGE_FILE_ACCOUNT_NAME
os.environ['PREMIUM_STORAGE_FILE_ACCOUNT_KEY'] = os.environ.get(
'PREMIUM_STORAGE_FILE_ACCOUNT_KEY', None) or PREMIUM_STORAGE_FILE_ACCOUNT_KEY
os.environ['SECONDARY_STORAGE_ACCOUNT_NAME'] = os.environ.get(
'SECONDARY_STORAGE_ACCOUNT_NAME', None) or SECONDARY_STORAGE_ACCOUNT_NAME
os.environ['SECONDARY_STORAGE_ACCOUNT_KEY'] = os.environ.get(
'SECONDARY_STORAGE_ACCOUNT_KEY', None) or SECONDARY_STORAGE_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
Expand All @@ -58,7 +48,9 @@
premium_storage_file_account_key=STORAGE_ACCOUNT_FAKE_KEY,
secondary_storage_account_name="pyrmtstoragestorname",
secondary_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
options=EnvironmentVariableOptions(hide_secrets=["storage_account_key", "secondary_storage_account_key", "premium_storage_file_account_key"]),
options=EnvironmentVariableOptions(
hide_secrets=["storage_account_key", "secondary_storage_account_key", "premium_storage_file_account_key"]
),
)


Expand Down
22 changes: 13 additions & 9 deletions sdk/storage/azure-storage-file-share/tests/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
from datetime import datetime, timedelta, timezone

import pytest
from azure.core.exceptions import ClientAuthenticationError, ResourceExistsError, ResourceNotFoundError

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

from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
from azure.storage.fileshare import (
ContentSettings,
generate_share_sas,
NTFSAttributes,
ShareDirectoryClient,
Expand All @@ -19,9 +23,7 @@
StorageErrorCode,
)

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

# ------------------------------------------------------------------------------
TEST_FILE_PERMISSIONS = 'O:S-1-5-21-2127521184-1604012920-1887927527-21560751G:S-1-5-21-2127521184-' \
'1604012920-1887927527-513D:AI(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;' \
Expand Down Expand Up @@ -111,7 +113,8 @@ def test_create_directory_set_smb_properties(self, **kwargs):

directory_client = share_client.get_directory_client('dir1')
file_attributes = NTFSAttributes(read_only=True, directory=True)
file_creation_time = file_last_write_time = file_change_time = datetime(2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc)
file_creation_time = file_last_write_time = file_change_time = datetime(
2022, 3, 10, 10, 14, 30, 500000, tzinfo=timezone.utc)

# Act
directory_client.create_directory(
Expand Down Expand Up @@ -873,7 +876,8 @@ def test_list_subdirectories_and_files_include_other_data(self, **kwargs):
directory.upload_file("file3", "data3")

# Act
list_dir = list(directory.list_directories_and_files(include=["timestamps", "Etag", "Attributes", "PermissionKey"]))
list_dir = list(directory.list_directories_and_files(
include=["timestamps", "Etag", "Attributes", "PermissionKey"]))

assert len(list_dir) == 6
assert list_dir[0].etag is not None
Expand Down Expand Up @@ -1279,7 +1283,7 @@ def test_rename_directory_smb_properties(self, **kwargs):
props = new_directory.get_directory_properties()
assert props is not None
assert props.is_directory
assert str(file_attributes), props.file_attributes.replace(' ' == '')
assert str(file_attributes).replace(' ', '') == props.file_attributes.replace(' ', '')
assert file_creation_time == props.creation_time
assert file_last_write_time == props.last_write_time
assert file_change_time == props.change_time
Expand Down Expand Up @@ -1415,7 +1419,7 @@ def test_bad_audience_directory_client(self, **kwargs):
share_client.share_name, 'dir1.',
credential=token_credential,
token_intent=TEST_INTENT,
audience=f'https://badaudience.file.core.windows.net'
audience='https://badaudience.file.core.windows.net'
)

# Assert
Expand Down
Loading