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..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`. @@ -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. 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 bb35b376d96c..8d9607c446b3 100644 --- a/sdk/communication/azure-communication-email/tests.yml +++ b/sdk/communication/azure-communication-email/tests.yml @@ -12,9 +12,19 @@ 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' + 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 71611e72ea69..d1e74bdb1d26 100644 --- a/sdk/communication/tests.yml +++ b/sdk/communication/tests.yml @@ -13,6 +13,10 @@ parameters: - azure-communication-sms - azure-communication-jobrouter - azure-communication-callautomation + - name: TestResourceDirectories + type: object + default: + - communication/test-resources/ stages: - ${{ each service in parameters.Services }}: @@ -23,6 +27,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: