Skip to content

Commit 2b3c060

Browse files
committed
Merge branch 'main' into ericasp/number-lookup-ga-staging
2 parents 8e2997a + 4b81874 commit 2b3c060

File tree

2,473 files changed

+494622
-33519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,473 files changed

+494622
-33519
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
/sdk/mixedreality/azure-mixedreality-authentication/ @RamonArguelles
278278
/sdk/remoterendering/ @FlorianBorn71
279279

280-
# PRLabel: %Open AI
280+
# PRLabel: %OpenAI
281281
/sdk/openai/ @kristapratico @glecaros
282282

283283
# PRLabel: %Purview

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Python cache
55
__pycache__/
6-
*.pyc
6+
*.py[cod]
77
.pytest_cache
88
.mypy_cache
99
.cache

.vscode/cspell.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"sdk/translation/azure-ai-translation-document/samples/assets/**",
9191
"sdk/translation/azure-ai-translation-document/tests/glossaries-valid.csv",
9292
"sdk/storage/azure-storage-blob/**",
93+
"sdk/storage/azure-storage-extensions/**",
9394
"sdk/ml/azure-ai-ml/azure/ai/ml/_restclient/**",
9495
"sdk/ml/azure-ai-ml/azure/ai/ml/_utils/_virtual_cluster_utils/_restclient/**",
9596
"sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/job_name_generator.py",
@@ -549,6 +550,13 @@
549550
"Jwcmlud"
550551
]
551552
},
553+
{
554+
"filename": "sdk/identity/test-resources*",
555+
"words": [
556+
"kubelet",
557+
"otsv"
558+
]
559+
},
552560
{
553561
"filename": "sdk/identity/azure-identity/TROUBLESHOOTING.md",
554562
"words": [

doc/dev/tests.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ Live Azure resources will be necessary in order to run live tests and produce re
181181
resource management commands, documented in [/eng/common/TestResources][test_resources], that streamline this process.
182182
Both pure ARM templates (`test-resources.json`) and BICEP files (`test-resources.bicep`) are supported.
183183

184+
User-based authentication is preferred when using test resources. To enable this:
185+
- Use the [`-UserAuth` command flag][user_auth_flag] when running the `New-TestResources` script.
186+
- Set the environment variable `AZURE_TEST_USE_PWSH_AUTH` to "true" to authenticate with Azure PowerShell, or
187+
`AZURE_TEST_USE_CLI_AUTH` to "true" to authenticate with Azure CLI.
188+
- Ensure you're logged into the tool you choose -- if
189+
you used `New-TestResources.ps1` to deploy resources, you'll already have logged in with Azure PowerShell.
190+
184191
If you haven't yet set up a `test-resources` file for test resource deployment and/or want to use test resources of
185192
your own, you can just configure credentials to target these resources instead.
186193

@@ -209,14 +216,20 @@ environment variables necessary to run live tests for the service. After storing
209216
-- formatted as `VARIABLE=value` on separate lines -- your credentials and test configuration variables will be set in
210217
our environment when running tests.
211218

219+
If you used the [`-UserAuth` command flag][user_auth_flag] to deploy test resources, set either
220+
`AZURE_TEST_USE_PWSH_AUTH` or `AZURE_TEST_USE_CLI_AUTH` to "true" to authenticate with Azure PowerShell or Azure CLI,
221+
respectively. If both are set to true, Azure PowerShell will be used.
222+
212223
If your service doesn't have a `test-resources` file for test deployment, you'll need to set environment variables
213-
for `AZURE_SUBSCRIPTION_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, and `AZURE_CLIENT_SECRET` at minimum.
224+
for authentication at minimum. For user-based authentication, use `AZURE_TEST_USE_PWSH_AUTH` or
225+
`AZURE_TEST_USE_CLI_AUTH` as described above.
214226

227+
For service principal authentication:
215228
1. Set the `AZURE_SUBSCRIPTION_ID` variable to your organization's subscription ID. You can find it in the "Overview"
216229
section of the "Subscriptions" blade in the [Azure Portal][azure_portal].
217230
2. Define the `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, and `AZURE_CLIENT_SECRET` of a test service principal. If you do not
218-
have a service principal, use the Azure CLI's [az ad sp create-for-rbac][azure_cli_service_principal] command (ideally,
219-
using your alias as the service principal's name prefix):
231+
have a service principal, use the Azure CLI's [az ad sp create-for-rbac][azure_cli_service_principal] command
232+
(ideally, using your alias as the service principal's name prefix):
220233

221234
```
222235
az login
@@ -326,7 +339,9 @@ well. To run tests in playback, either set `AZURE_TEST_RUN_LIVE` to "false" or l
326339

327340
### Run and record tests
328341

329-
With the `AZURE_TEST_RUN_LIVE` environment variable set to "true", use `pytest` to run your test(s) in live mode.
342+
First, refer to the [Configure test variables](#configure-test-variables) section to ensure environment variables are
343+
set for test resources and authentication. With the `AZURE_TEST_RUN_LIVE` environment variable set to "true", use
344+
`pytest` to run your test(s) in live mode.
330345

331346
```
332347
(env) azure-sdk-for-python\sdk\my-service\my-package> pytest tests
@@ -339,18 +354,18 @@ Playback test errors most frequently indicate a need for additional sanitizers a
339354
[Sanitize secrets](#sanitize-secrets)). If you encounter any unexpected errors, refer to the
340355
[test proxy troubleshooting guide][troubleshooting_guide].
341356

342-
At this point there should folder called `recordings` inside your package's `tests` directory. Each recording in this
343-
folder will be a `.json` file that captures the HTTP traffic that was generated while running the test matching the
344-
file's name.
357+
If tests were recorded for a new library, there should now be a folder called `recordings` inside your package's
358+
`tests` directory. Each recording in this folder will be a `.json` file that captures the HTTP traffic that was
359+
generated while running the test matching the file's name.
345360

346361
The final step in setting up recordings is to move these files out of the `azure-sdk-for-python` and into the
347362
`azure-sdk-assets` repository. The [recording migration guide][recording_move] describes how to do so. This step only
348-
needs to be completed once. Your library will have an `assets.json` file at its root, which stores the `azure-sdk-assets`
349-
tag that contains the current set of recordings.
363+
needs to be completed once. Your library will have an `assets.json` file at its root, which stores the
364+
`azure-sdk-assets` tag that contains the current set of recordings.
350365

351-
From this point on, recordings will automatically be fetched when tests are run in playback mode -- either from
352-
a local cache (described in [Update test recordings](#update-test-recordings)), or from `azure-sdk-assets` if they're
353-
not locally available.
366+
From this point on, recordings will automatically be fetched when tests are run in playback mode -- either from a local
367+
cache (described in [Update test recordings](#update-test-recordings)), or from `azure-sdk-assets` if they're not
368+
locally available.
354369

355370
#### Update test recordings
356371

@@ -725,3 +740,4 @@ Tests that use the Shared Access Signature (SAS) to authenticate a client should
725740
[test_proxy_startup]: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_migration_guide.md#start-the-proxy-server
726741
[test_resources]: https://github.com/Azure/azure-sdk-for-python/tree/main/eng/common/TestResources#readme
727742
[troubleshooting_guide]: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_troubleshooting.md
743+
[user_auth_flag]: https://github.com/Azure/azure-sdk-for-python/blob/main/eng/common/TestResources/New-TestResources.ps1.md#-userauth

eng/.docsettings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ omitted_paths:
1414
- sdk/**/swagger/*
1515
- sdk/ml/azure-ai-ml/tests/*
1616
- sdk/vision/azure-ai-vision-imageanalysis/tests/*
17+
- sdk/storage/azure-storage-extensions/*
1718

1819
language: python
1920
root_check_enabled: True

eng/common/TestResources/New-TestResources.ps1

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ param (
9292
[Parameter()]
9393
[switch] $SuppressVsoCommands = ($null -eq $env:SYSTEM_TEAMPROJECTID),
9494

95+
[Parameter()]
96+
[switch] $UserAuth,
97+
9598
# Captures any arguments not declared here (no parameter errors)
9699
# This enables backwards compatibility with old script versions in
97100
# hotfix branches if and when the dynamic subscription configuration
@@ -611,8 +614,19 @@ try {
611614
}
612615
}
613616

617+
if ($UserAuth) {
618+
if ($TestApplicationId) {
619+
Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when UserAuth is set."
620+
}
621+
622+
$userAccount = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account)
623+
$TestApplicationOid = $userAccount.Id
624+
$TestApplicationId = $testApplicationOid
625+
$userAccountName = $userAccount.UserPrincipalName
626+
Log "User authentication with user '$userAccountName' ('$TestApplicationId') will be used."
627+
}
614628
# If no test application ID was specified during an interactive session, create a new service principal.
615-
if (!$CI -and !$TestApplicationId) {
629+
elseif (!$CI -and !$TestApplicationId) {
616630
# Cache the created service principal in this session for frequent reuse.
617631
$servicePrincipal = if ($AzureTestPrincipal -and (Get-AzADServicePrincipal -ApplicationId $AzureTestPrincipal.AppId) -and $AzureTestSubscription -eq $SubscriptionId) {
618632
Log "TestApplicationId was not specified; loading cached service principal '$($AzureTestPrincipal.AppId)'"
@@ -674,11 +688,11 @@ try {
674688
$PSBoundParameters['TestApplicationOid'] = $TestApplicationOid
675689
$PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret
676690

677-
# If the role hasn't been explicitly assigned to the resource group and a cached service principal is in use,
691+
# If the role hasn't been explicitly assigned to the resource group and a cached service principal or user authentication is in use,
678692
# query to see if the grant is needed.
679-
if (!$resourceGroupRoleAssigned -and $AzureTestPrincipal) {
693+
if (!$resourceGroupRoleAssigned -and $TestApplicationOid) {
680694
$roleAssignment = Get-AzRoleAssignment `
681-
-ObjectId $AzureTestPrincipal.Id `
695+
-ObjectId $TestApplicationOid `
682696
-RoleDefinitionName 'Owner' `
683697
-ResourceGroupName "$ResourceGroupName" `
684698
-ErrorAction SilentlyContinue
@@ -690,19 +704,20 @@ try {
690704
# considered a critical failure, as the test application may have subscription-level permissions and not require
691705
# the explicit grant.
692706
if (!$resourceGroupRoleAssigned) {
693-
Log "Attempting to assigning the 'Owner' role for '$ResourceGroupName' to the Test Application '$TestApplicationId'"
694-
$principalOwnerAssignment = New-AzRoleAssignment `
695-
-RoleDefinitionName "Owner" `
696-
-ApplicationId "$TestApplicationId" `
697-
-ResourceGroupName "$ResourceGroupName" `
698-
-ErrorAction SilentlyContinue
699-
700-
if ($principalOwnerAssignment.RoleDefinitionName -eq 'Owner') {
701-
Write-Verbose "Successfully assigned ownership of '$ResourceGroupName' to the Test Application '$TestApplicationId'"
707+
$idSlug = if ($userAuth) { "User '$userAccountName' ('$TestApplicationId')"} else { "Test Application '$TestApplicationId'"};
708+
Log "Attempting to assign the 'Owner' role for '$ResourceGroupName' to the $idSlug"
709+
$ownerAssignment = New-AzRoleAssignment `
710+
-RoleDefinitionName "Owner" `
711+
-ObjectId "$TestApplicationOId" `
712+
-ResourceGroupName "$ResourceGroupName" `
713+
-ErrorAction SilentlyContinue
714+
715+
if ($ownerAssignment.RoleDefinitionName -eq 'Owner') {
716+
Write-Verbose "Successfully assigned ownership of '$ResourceGroupName' to the $idSlug"
702717
} else {
703718
Write-Warning ("The 'Owner' role for '$ResourceGroupName' could not be assigned. " +
704719
"You may need to manually grant 'Owner' for the resource group to the " +
705-
"Test Application '$TestApplicationId' if it does not have subscription-level permissions.")
720+
"$idSlug if it does not have subscription-level permissions.")
706721
}
707722
}
708723

@@ -1001,6 +1016,14 @@ The environment file will be named for the test resources template that it was
10011016
generated for. For ARM templates, it will be test-resources.json.env. For
10021017
Bicep templates, test-resources.bicep.env.
10031018
1019+
.PARAMETER UserAuth
1020+
Create the resource group and deploy the template using the signed in user's credentials.
1021+
No service principal will be created or used.
1022+
1023+
The environment file will be named for the test resources template that it was
1024+
generated for. For ARM templates, it will be test-resources.json.env. For
1025+
Bicep templates, test-resources.bicep.env.
1026+
10041027
.PARAMETER SuppressVsoCommands
10051028
By default, the -CI parameter will print out secrets to logs with Azure Pipelines log
10061029
commands that cause them to be redacted. For CI environments that don't support this (like

0 commit comments

Comments
 (0)