Skip to content

Commit 57301e6

Browse files
authored
[Storage] add entra id auth to blob perf tests (#35074)
* add entra id auth * add entra id to perf-tests.yml * pass correct cclient secret cred into sync client * address pauls comments
1 parent 85b34b7 commit 57301e6

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

sdk/storage/azure-storage-blob/perf-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Tests:
1515
Class: DownloadTest
1616
Arguments: &sizes
1717
- --size 10240 --parallel 64
18+
- --size 10240 --parallel 64 --use-entra-id
1819
- --size 10485760 --parallel 32
1920
- --size 1073741824 --parallel 1 --warmup 60 --duration 60
2021
- --size 1073741824 --parallel 8 --warmup 60 --duration 60
@@ -28,4 +29,5 @@ Tests:
2829
Arguments:
2930
- --count 5 --parallel 64
3031
- --count 500 --parallel 32
32+
- --count 500 --parallel 32 --use-entra-id
3133
- --count 50000 --parallel 32 --warmup 60 --duration 60

sdk/storage/azure-storage-blob/tests/perfstress_tests/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ Note that tests for T1 and T2 SDKs cannot be run from the same environment, and
66

77
### Setup for test resources
88

9-
These tests will run against a pre-configured Storage account. The following environment variable will need to be set for the tests to access the live resources:
9+
These tests will run against a pre-configured Storage account. The following environment variable will need to be set for the tests to access the live resources using the connection string for authentication:
1010
```
1111
AZURE_STORAGE_CONNECTION_STRING=<live storage account connection string>
1212
```
1313

14+
The following environment variables will need to be set for the tests to access the live resources using Microsoft Entra ID for authentication:
15+
```
16+
AZURE-STORAGE-BLOB_TENANT_ID=<Microsoft Entra ID tenant ID>
17+
AZURE-STORAGE-BLOB_CLIENT_ID=<Microsoft Entra ID client ID>
18+
AZURE-STORAGE-BLOB_CLIENT_SECRET=<Microsoft Entra ID client secret>
19+
AZURE_STORAGE_ACCOUNT_NAME=<live storage account name>
20+
```
21+
22+
1423
### Setup for T2 perf test runs
1524

1625
```cmd
@@ -46,6 +55,7 @@ These options are available for all perf tests:
4655
- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted).
4756
- `-x --test-proxies` Whether to run the tests against the test proxy server. Specfiy the URL(s) for the proxy endpoint(s) (e.g. "https://localhost:5001"). WARNING: When using with Legacy tests - only HTTPS is supported.
4857
- `--profile` Whether to run the perftest with cProfile. If enabled (default is False), the output file of the **last completed single iteration** will be written to the current working directory in the format `"cProfile-<TestClassName>-<TestID>-<sync/async>.pstats"`.
58+
- `--use-entra-id` - Flag to pass in to use Microsoft Entra ID as the authentication. By default, set to False.
4959

5060
### Common Blob command line options
5161
The options are available for all Blob perf tests:

sdk/storage/azure-storage-blob/tests/perfstress_tests/_test_base.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from devtools_testutils.perfstress_tests import PerfStressTest
99
from azure.storage.blob import BlobServiceClient as SyncBlobServiceClient
1010
from azure.storage.blob.aio import BlobServiceClient as AsyncBlobServiceClient
11+
from azure.identity import ClientSecretCredential as SyncClientSecretCredential
12+
from azure.identity.aio import ClientSecretCredential as AsyncClientSecretCredential
1113

1214
from .key_wrapper import KeyWrapper
1315

@@ -18,7 +20,6 @@ class _ServiceTest(PerfStressTest):
1820

1921
def __init__(self, arguments):
2022
super().__init__(arguments)
21-
connection_string = self.get_from_env("AZURE_STORAGE_CONNECTION_STRING")
2223
if self.args.test_proxies:
2324
self._client_kwargs['_additional_pipeline_policies'] = self._client_kwargs['per_retry_policies']
2425
self._client_kwargs['max_single_put_size'] = self.args.max_put_size
@@ -32,8 +33,29 @@ def __init__(self, arguments):
3233
# self._client_kwargs['api_version'] = '2019-02-02' # Used only for comparison with T1 legacy tests
3334

3435
if not _ServiceTest.service_client or self.args.no_client_share:
35-
_ServiceTest.service_client = SyncBlobServiceClient.from_connection_string(conn_str=connection_string, **self._client_kwargs)
36-
_ServiceTest.async_service_client = AsyncBlobServiceClient.from_connection_string(conn_str=connection_string, **self._client_kwargs)
36+
if self.args.use_entra_id:
37+
tenant_id = self.get_from_env("AZURE-STORAGE-BLOB_TENANT_ID")
38+
client_id = self.get_from_env("AZURE-STORAGE-BLOB_CLIENT_ID")
39+
client_secret = self.get_from_env("AZURE-STORAGE-BLOB_CLIENT_SECRET")
40+
sync_token_credential = SyncClientSecretCredential(
41+
tenant_id,
42+
client_id,
43+
client_secret
44+
)
45+
async_token_credential = AsyncClientSecretCredential(
46+
tenant_id,
47+
client_id,
48+
client_secret
49+
)
50+
account_name = self.get_from_env("AZURE_STORAGE_ACCOUNT_NAME")
51+
# We assume these tests will only be run on the Azure public cloud for now.
52+
url = f"https://{account_name}.blob.core.windows.net"
53+
_ServiceTest.service_client = SyncBlobServiceClient(account_url=url, credential=sync_token_credential, **self._client_kwargs)
54+
_ServiceTest.async_service_client = AsyncBlobServiceClient(account_url=url, credential=async_token_credential, **self._client_kwargs)
55+
else:
56+
connection_string = self.get_from_env("AZURE_STORAGE_CONNECTION_STRING")
57+
_ServiceTest.service_client = SyncBlobServiceClient.from_connection_string(conn_str=connection_string, **self._client_kwargs)
58+
_ServiceTest.async_service_client = AsyncBlobServiceClient.from_connection_string(conn_str=connection_string, **self._client_kwargs)
3759
self.service_client = _ServiceTest.service_client
3860
self.async_service_client = _ServiceTest.async_service_client
3961

@@ -51,6 +73,9 @@ def add_arguments(parser):
5173
parser.add_argument('--max-concurrency', nargs='?', type=int, help='Maximum number of concurrent threads used for data transfer. Defaults to 1', default=1)
5274
parser.add_argument('-s', '--size', nargs='?', type=int, help='Size of data to transfer. Default is 10240.', default=10240)
5375
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)
76+
parser.add_argument(
77+
"--use-entra-id", action="store_true", help="Use Microsoft Entra ID authentication instead of connection string."
78+
)
5479

5580

5681
class _ContainerTest(_ServiceTest):

0 commit comments

Comments
 (0)