From 97aad300112e2b9c9dd9527880b766cf3772bd97 Mon Sep 17 00:00:00 2001 From: Yogesh Mohanraj Date: Tue, 7 Mar 2023 09:08:39 -0800 Subject: [PATCH 1/4] Adding PPE live tests --- sdk/communication/azure-communication-email/tests.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-email/tests.yml b/sdk/communication/azure-communication-email/tests.yml index bb35b376d96c..d6faf7f1d6b9 100644 --- a/sdk/communication/azure-communication-email/tests.yml +++ b/sdk/communication/azure-communication-email/tests.yml @@ -12,9 +12,17 @@ stages: - $(sub-config-azure-cloud-test-resources) - $(sub-config-communication-services-cloud-test-resources-common) - $(sub-config-communication-services-cloud-test-resources-python) + Int: + SubscriptionConfigurations: + - $(sub-config-communication-int-test-resources-common) + - $(sub-config-communication-int-test-resources-python) + PPE: + SubscriptionConfigurations: + - $(sub-config-communication-ppe-test-resources-common) + - $(sub-config-communication-ppe-test-resources-python) MatrixReplace: - TestSamples=.*/true - Clouds: Public + Clouds: 'Public,PPE,Int' EnvVars: AZURE_SKIP_LIVE_RECORDING: 'True' AZURE_TEST_RUN_LIVE: 'true' From db195a36a7786efc393cb2c1b92b4159b8766879 Mon Sep 17 00:00:00 2001 From: Yogesh Mohanraj Date: Tue, 7 Mar 2023 15:57:34 -0800 Subject: [PATCH 2/4] Separating email live test resources --- .../azure-communication-chat/tests.yml | 2 + .../test-resources.json | 0 .../azure-communication-email/tests.yml | 2 + .../azure-communication-identity/tests.yml | 2 + .../tests.yml | 2 + .../tests.yml | 2 + .../azure-communication-rooms/tests.yml | 2 + .../azure-communication-sms/tests.yml | 2 + .../test-resources/test-resources.json | 100 ++++++++++++++++++ sdk/communication/tests.yml | 5 + 10 files changed, 119 insertions(+) rename sdk/communication/{ => azure-communication-email}/test-resources.json (100%) create mode 100644 sdk/communication/test-resources/test-resources.json diff --git a/sdk/communication/azure-communication-chat/tests.yml b/sdk/communication/azure-communication-chat/tests.yml index 75731ab2906c..e6c6ac25eb06 100644 --- a/sdk/communication/azure-communication-chat/tests.yml +++ b/sdk/communication/azure-communication-chat/tests.yml @@ -19,3 +19,5 @@ stages: - $(sub-config-communication-int-test-resources-common) - $(sub-config-communication-int-test-resources-python) Clouds: Public,Int + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/test-resources.json b/sdk/communication/azure-communication-email/test-resources.json similarity index 100% rename from sdk/communication/test-resources.json rename to sdk/communication/azure-communication-email/test-resources.json diff --git a/sdk/communication/azure-communication-email/tests.yml b/sdk/communication/azure-communication-email/tests.yml index d6faf7f1d6b9..8d9607c446b3 100644 --- a/sdk/communication/azure-communication-email/tests.yml +++ b/sdk/communication/azure-communication-email/tests.yml @@ -26,3 +26,5 @@ stages: EnvVars: AZURE_SKIP_LIVE_RECORDING: 'True' AZURE_TEST_RUN_LIVE: 'true' + TestResourceDirectories: + - communication/azure-communication-email/ diff --git a/sdk/communication/azure-communication-identity/tests.yml b/sdk/communication/azure-communication-identity/tests.yml index 254a5634baa4..058c7f9ab01f 100644 --- a/sdk/communication/azure-communication-identity/tests.yml +++ b/sdk/communication/azure-communication-identity/tests.yml @@ -26,3 +26,5 @@ stages: EnvVars: AZURE_SKIP_LIVE_RECORDING: 'True' AZURE_TEST_RUN_LIVE: 'true' + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/azure-communication-networktraversal/tests.yml b/sdk/communication/azure-communication-networktraversal/tests.yml index 122fe6170843..8e37ea332098 100644 --- a/sdk/communication/azure-communication-networktraversal/tests.yml +++ b/sdk/communication/azure-communication-networktraversal/tests.yml @@ -19,3 +19,5 @@ stages: - $(sub-config-communication-int-test-resources-common) - $(sub-config-communication-int-test-resources-python) Clouds: Public + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/azure-communication-phonenumbers/tests.yml b/sdk/communication/azure-communication-phonenumbers/tests.yml index 1cb8d45b4fea..5c5523f88a1c 100644 --- a/sdk/communication/azure-communication-phonenumbers/tests.yml +++ b/sdk/communication/azure-communication-phonenumbers/tests.yml @@ -29,3 +29,5 @@ stages: Path: sdk/communication/azure-communication-phonenumbers/phonenumbers-livetest-matrix.json Selection: sparse GenerateVMJobs: true + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/azure-communication-rooms/tests.yml b/sdk/communication/azure-communication-rooms/tests.yml index 1c24dc4cab2b..18d27a3eb811 100644 --- a/sdk/communication/azure-communication-rooms/tests.yml +++ b/sdk/communication/azure-communication-rooms/tests.yml @@ -20,4 +20,6 @@ stages: - $(sub-config-communication-int-test-resources-common) - $(sub-config-communication-int-test-resources-python) Clouds: Public,Int + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/azure-communication-sms/tests.yml b/sdk/communication/azure-communication-sms/tests.yml index 939a126afc54..978a2dbec0d5 100644 --- a/sdk/communication/azure-communication-sms/tests.yml +++ b/sdk/communication/azure-communication-sms/tests.yml @@ -18,3 +18,5 @@ stages: EnvVars: AZURE_SKIP_LIVE_RECORDING: 'True' AZURE_TEST_RUN_LIVE: 'True' + TestResourceDirectories: + - communication/test-resources/ diff --git a/sdk/communication/test-resources/test-resources.json b/sdk/communication/test-resources/test-resources.json new file mode 100644 index 000000000000..b2d8f7539581 --- /dev/null +++ b/sdk/communication/test-resources/test-resources.json @@ -0,0 +1,100 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "baseName": { + "type": "string", + "defaultValue": "[resourceGroup().name]", + "metadata": { + "description": "The base resource name." + } + }, + "endpointPrefix": { + "defaultValue": "communication", + "type": "string" + }, + "communicationServicesEndpointSuffix": { + "defaultValue": ".communication.azure.com", + "type": "string" + }, + "testApplicationOid": { + "type": "string", + "metadata": { + "description": "The client OID to grant access to test resources." + } + }, + "tenantId": { + "type": "String", + "metadata": { + "description": "The tenant id to which the application and resources belong." + } + }, + "testApplicationId": { + "type": "String", + "metadata": { + "description": "The application client id used to run tests." + } + }, + "testApplicationSecret": { + "type": "String", + "metadata": { + "description": "The application client secret used to run tests." + } + } + }, + "variables": { + "uniqueSubDomainName": "[format('{0}-{1}', parameters('baseName'), parameters('endpointPrefix'))]", + "contributorRoleId": "b24988ac-6180-42a0-ab88-20f7382dd24c" + }, + "resources": [ + { + "type": "Microsoft.Communication/CommunicationServices", + "apiVersion": "2020-08-20-preview", + "name": "[variables('uniqueSubDomainName')]", + "location": "global", + "properties": { + "dataLocation": "UnitedStates" + } + }, + { + "type": "Microsoft.Authorization/roleAssignments", + "apiVersion": "2019-04-01-preview", + "name": "[guid(resourceGroup().id, deployment().name, parameters('baseName'), variables('contributorRoleId'))]", + "properties": { + "roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', variables('contributorRoleId'))]", + "principalId": "[parameters('testApplicationOid')]", + "scope": "[resourceGroup().id]" + } + } + ], + "outputs": { + "AZURE_TENANT_ID": { + "type": "String", + "value": "[parameters('tenantId')]" + }, + "AZURE_CLIENT_ID": { + "type": "String", + "value": "[parameters('testApplicationId')]" + }, + "AZURE_CLIENT_SECRET": { + "type": "String", + "value": "[parameters('testApplicationSecret')]" + }, + "COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Communication/CommunicationServices',variables('uniqueSubDomainName')), '2021-10-01-preview').primaryConnectionString]" + }, + "COMMUNICATION_SERVICE_ENDPOINT": { + "type": "string", + "value": "[concat('https://', parameters('baseName'), '-', parameters('endpointPrefix'), parameters('communicationServicesEndpointSuffix'))]" + }, + "COMMUNICATION_SERVICE_ACCESS_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.Communication/CommunicationServices',variables('uniqueSubDomainName')), '2021-10-01-preview').primaryKey]" + }, + "RESOURCE_GROUP_NAME": { + "type": "string", + "value": "[resourceGroup().Name]" + } + } +} diff --git a/sdk/communication/tests.yml b/sdk/communication/tests.yml index 4ccf33189988..6b145cf506ea 100644 --- a/sdk/communication/tests.yml +++ b/sdk/communication/tests.yml @@ -12,6 +12,10 @@ parameters: - azure-communication-rooms - azure-communication-sms - azure-communication-jobrouter + - name: TestResourceDirectories + type: object + default: + - communication/test-resources/ stages: - ${{ each service in parameters.Services }}: @@ -22,6 +26,7 @@ stages: # All 5 service stages run in parallel, and with no parallel limits the tests may get throttled. MaxParallel: 2 ServiceDirectory: communication + TestResourceDirectories: ${{ parameters.TestResourceDirectories }} ${{ if contains(service, 'phonenumbers') }}: CloudConfig: From a1f4df1a5fc6c0677badab833a94ad36d7a97ed2 Mon Sep 17 00:00:00 2001 From: Yogesh Mohanraj Date: Tue, 14 Mar 2023 17:11:30 -0700 Subject: [PATCH 3/4] Adding TestResourceDirectories parameter --- eng/pipelines/templates/jobs/live.tests.yml | 40 ++++++++++++++----- .../templates/stages/archetype-sdk-tests.yml | 4 ++ sdk/communication/CONTRIBUTING.md | 4 ++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/eng/pipelines/templates/jobs/live.tests.yml b/eng/pipelines/templates/jobs/live.tests.yml index 5677cdc9d907..13427adbe193 100644 --- a/eng/pipelines/templates/jobs/live.tests.yml +++ b/eng/pipelines/templates/jobs/live.tests.yml @@ -2,6 +2,9 @@ parameters: - name: ServiceDirectory type: string default: '' + - name: TestResourceDirectories + type: object + default: - name: PreSteps type: object default: [] @@ -99,12 +102,21 @@ jobs: SubscriptionConfiguration: ${{ parameters.CloudConfig.SubscriptionConfiguration }} SubscriptionConfigurations: ${{ parameters.CloudConfig.SubscriptionConfigurations }} - - template: /eng/common/TestResources/deploy-test-resources.yml - parameters: - Location: ${{ coalesce(parameters.Location, parameters.CloudConfig.Location) }} - ServiceDirectory: '${{ parameters.ServiceDirectory }}' - SubscriptionConfiguration: $(SubscriptionConfiguration) - ArmTemplateParameters: $(ArmTemplateParameters) + - ${{ if parameters.TestResourceDirectories }}: + - ${{ each directory in parameters.TestResourceDirectories }}: + - template: /eng/common/TestResources/deploy-test-resources.yml + parameters: + Location: ${{ coalesce(parameters.Location, parameters.CloudConfig.Location) }} + ServiceDirectory: '${{ directory }}' + SubscriptionConfiguration: $(SubscriptionConfiguration) + ArmTemplateParameters: $(ArmTemplateParameters) + - ${{ if not(parameters.TestResourceDirectories) }}: + - template: /eng/common/TestResources/deploy-test-resources.yml + parameters: + Location: ${{ coalesce(parameters.Location, parameters.CloudConfig.Location) }} + ServiceDirectory: '${{ parameters.ServiceDirectory }}' + SubscriptionConfiguration: $(SubscriptionConfiguration) + ArmTemplateParameters: $(ArmTemplateParameters) - template: ../steps/build-test.yml parameters: @@ -125,7 +137,15 @@ jobs: BuildDocs: ${{ parameters.BuildDocs }} TestProxy: ${{ parameters.TestProxy }} - - template: /eng/common/TestResources/remove-test-resources.yml - parameters: - ServiceDirectory: '${{ parameters.ServiceDirectory }}' - SubscriptionConfiguration: $(SubscriptionConfiguration) + + - ${{ if parameters.TestResourceDirectories }}: + - ${{ each directory in parameters.TestResourceDirectories }}: + - template: /eng/common/TestResources/remove-test-resources.yml + parameters: + ServiceDirectory: '${{ directory }}' + SubscriptionConfiguration: $(SubscriptionConfiguration) + - ${{ if not(parameters.TestResourceDirectories) }}: + - template: /eng/common/TestResources/remove-test-resources.yml + parameters: + ServiceDirectory: '${{ parameters.ServiceDirectory }}' + SubscriptionConfiguration: $(SubscriptionConfiguration) diff --git a/eng/pipelines/templates/stages/archetype-sdk-tests.yml b/eng/pipelines/templates/stages/archetype-sdk-tests.yml index 0f3c22c1ef6d..edba9c745dc1 100644 --- a/eng/pipelines/templates/stages/archetype-sdk-tests.yml +++ b/eng/pipelines/templates/stages/archetype-sdk-tests.yml @@ -2,6 +2,9 @@ parameters: - name: ServiceDirectory type: string default: '' + - name: TestResourceDirectories + type: object + default: - name: PreSteps type: object default: [] @@ -105,6 +108,7 @@ stages: JobTemplatePath: /eng/pipelines/templates/jobs/live.tests.yml AdditionalParameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} + TestResourceDirectories: ${{ parameters.TestResourceDirectories }} PreSteps: - ${{ parameters.PlatformPreSteps }} - ${{ parameters.PreSteps }} diff --git a/sdk/communication/CONTRIBUTING.md b/sdk/communication/CONTRIBUTING.md index 560d45645f67..5d09aceb4e95 100644 --- a/sdk/communication/CONTRIBUTING.md +++ b/sdk/communication/CONTRIBUTING.md @@ -50,6 +50,10 @@ If you are testing against a personal resource, you can check the [Managed Ident For a more in-depth look on how to authenticate using managed identity, refer to the [Azure Identity client library for Python](https://docs.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python) documentation. This document also has more ways for you to authenticate using the DefaultAzureCredential object besides the ones we discussed in this contributing file. +### Running the New-TestResources and Remove-TestResources Scripts + +You may want to run the `New-TestResources.ps1` or `Remove-TestResources.ps1` scripts to test resource deployments in the SDK Live Test pipelines locally. You will need to add the additional `-TestResourceDirectories` parameter when running these scripts. If you are using the shared `test-resources.json` you can point to `communication/test-resources/`. If you are using a custom `test-resources.json`, you can point to `communication//test-resources.json`. + ## Submitting a Pull Request The easiest way for you to test and not worry about any breaking changes you may cause is to create a fork from the [Python Azure SDK repo](https://github.com/Azure/azure-sdk-for-python). After downloading your repo, make sure to add the original repo as an upstream. To do this, use the `git remote add upstream` command followed by the repo's URL. From a5ef998126c44ba2fdef86b3113e3d63b1312b78 Mon Sep 17 00:00:00 2001 From: Yogesh Mohanraj Date: Tue, 14 Mar 2023 17:52:46 -0700 Subject: [PATCH 4/4] Fixing spelling --- sdk/communication/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/CONTRIBUTING.md b/sdk/communication/CONTRIBUTING.md index 5d09aceb4e95..6effc4c65403 100644 --- a/sdk/communication/CONTRIBUTING.md +++ b/sdk/communication/CONTRIBUTING.md @@ -32,7 +32,7 @@ If the tests are successful, we can proceed to run the tests in LIVE mode. Because in LIVE mode we are hitting an actual resource, we must set the appropriate environment variable to make sure the code tests against the resource we want. Set up an env variable called `COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING` (just needed for SMS and Phone Numbers SDKs) and set it to the connection string of the resource you want to test against. -Depending on which package you are testing, it may need special environment variables to test succesfully. The names of these variables can be found inside each test file in the `setUp()` function. Make sure to set these variables before running the tests themselves. You may need to restart your development environment after creating or updating these environment variables. +Depending on which package you are testing, it may need special environment variables to test successfully. The names of these variables can be found inside each test file in the `setUp()` function. Make sure to set these variables before running the tests themselves. You may need to restart your development environment after creating or updating these environment variables. You can run the `pytest .` command after setting the `AZURE_TEST_RUN_LIVE` variable to `true`.