Skip to content

Commit 6b029c9

Browse files
[translation] update yaml to include dogfood (Azure#22000)
* update yaml to include int cloud * fix * change storage api version * try lower api versions * conditionally use static storage for dogfood * try later template * switch to supported version * rename parameter * fixes for static resource * avoid calling template functions * don't need to output storage key * try updating credential scopes to be ppe specific * enable more logging * pass in authority host directly * skip running samples and set authority host through env var * set scopes based on auth host * add correct static acc and revert unecessary changes * try condition for the other list funcs * update to leverage env var for scope
1 parent e167a7f commit 6b029c9

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

sdk/translation/azure-ai-translation-document/tests/test_translation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ class TestTranslation(DocumentTranslationTest):
3232
def test_active_directory_auth(self):
3333
token = self.generate_oauth_token()
3434
endpoint = self.get_oauth_endpoint()
35-
client = DocumentTranslationClient(endpoint, token)
35+
kwargs = {}
36+
if os.getenv("AZURE_COGNITIVE_SCOPE"):
37+
kwargs["credential_scopes"] = [os.getenv("AZURE_COGNITIVE_SCOPE")]
38+
client = DocumentTranslationClient(endpoint, token, **kwargs)
3639
# prepare containers and test data
3740
blob_data = b'This is some text'
3841
source_container_sas_url = self.create_source_container(data=Document(data=blob_data))

sdk/translation/azure-ai-translation-document/tests/test_translation_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class TestTranslation(AsyncDocumentTranslationTest):
2929
async def test_active_directory_auth_async(self):
3030
token = self.generate_oauth_token()
3131
endpoint = self.get_oauth_endpoint()
32-
client = DocumentTranslationClient(endpoint, token)
32+
kwargs = {}
33+
if os.getenv("AZURE_COGNITIVE_SCOPE"):
34+
kwargs["credential_scopes"] = [os.getenv("AZURE_COGNITIVE_SCOPE")]
35+
client = DocumentTranslationClient(endpoint, token, **kwargs)
3336
# prepare containers and test data
3437
blob_data = b'This is some text'
3538
source_container_sas_url = self.create_source_container(data=Document(data=blob_data))
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
$StorageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $DeploymentOutputs["TRANSLATION_DOCUMENT_STORAGE_NAME"]
2-
$ctx = $StorageAccount.Context
3-
Set-AzStorageBlobContent -File "./sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.tsv" -Container "sourcecontainer" -Blob "glosario.tsv" -Context $ctx
4-
Set-AzStorageBlobContent -File "./sdk/translation/azure-ai-translation-document/samples/assets/translate.txt" -Container "sourcecontainer" -Blob "translate.txt" -Context $ctx
1+
if ($DeploymentOutputs["TRANSLATION_DOCUMENT_STORAGE_NAME"] -ne "pythontranslationstorage") {
2+
$StorageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $DeploymentOutputs["TRANSLATION_DOCUMENT_STORAGE_NAME"]
3+
$ctx = $StorageAccount.Context
4+
Set-AzStorageBlobContent -File "./sdk/translation/azure-ai-translation-document/samples/assets/glossary_sample.tsv" -Container "sourcecontainer" -Blob "glosario.tsv" -Context $ctx
5+
Set-AzStorageBlobContent -File "./sdk/translation/azure-ai-translation-document/samples/assets/translate.txt" -Container "sourcecontainer" -Blob "translate.txt" -Context $ctx
6+
}

sdk/translation/test-resources.json

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
2+
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
33
"contentVersion": "1.0.0.0",
44
"parameters": {
55
"baseName": {
@@ -42,13 +42,24 @@
4242
"description": "The application client secret used to run tests."
4343
}
4444
},
45-
"docTranslationEndpointSuffix": {
45+
"cognitiveServicesEndpointSuffix": {
4646
"defaultValue": ".cognitiveservices.azure.com/",
4747
"type": "string"
4848
},
49+
"useStaticStorageResource": {
50+
"type": "bool",
51+
"defaultValue": false,
52+
"metadata": {
53+
"description": "A static storage resource is used for Dogfood env."
54+
}
55+
},
56+
"staticStorageName": {
57+
"defaultValue": "pythontranslationstorage",
58+
"type": "string"
59+
},
4960
"blobStorageAccount": {
5061
"type": "string",
51-
"defaultValue": "[concat(parameters('baseName'), 'prim')]"
62+
"defaultValue": "[if(parameters('useStaticStorageResource'), parameters('staticStorageName'), parameters('baseName'))]"
5263
},
5364
"storageAccResourceId": {
5465
"type": "string",
@@ -128,10 +139,10 @@
128139
"authorizationApiVersion": "2018-09-01-preview",
129140
"docTranslationBaseName": "[parameters('baseName')]",
130141
"docTranslationApiVersion": "2017-04-18",
131-
"storageMgmtApiVersion": "2019-04-01",
132-
"storageAccountName": "[concat(parameters('baseName'), 'prim')]",
142+
"storageMgmtApiVersion": "2017-10-01",
143+
"storageAccountName": "[parameters('blobStorageAccount')]",
133144
"location": "[resourceGroup().location]",
134-
"azureDocTranslationUrl": "[concat('https://', variables('docTranslationBaseName'), parameters('docTranslationEndpointSuffix'))]",
145+
"azureDocTranslationUrl": "[if(parameters('useStaticStorageResource'), concat('https://', variables('docTranslationBaseName'), '.ppe', parameters('cognitiveServicesEndpointSuffix')), concat('https://', variables('docTranslationBaseName'), parameters('cognitiveServicesEndpointSuffix')))]",
135146
"azureStorageEndpoint": "[concat('https://', parameters('blobStorageAccount'), '.blob.core.windows.net/')]",
136147
"cognitiveServiceUserRoleId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/a97b65f3-24c7-4388-baec-2e87135dc908')]",
137148
"encryption": {
@@ -176,6 +187,7 @@
176187
}
177188
},
178189
{
190+
"condition": "[not(parameters('useStaticStorageResource'))]",
179191
"type": "Microsoft.Storage/storageAccounts",
180192
"apiVersion": "[variables('storageMgmtApiVersion')]",
181193
"name": "[variables('storageAccountName')]",
@@ -193,6 +205,7 @@
193205
},
194206
"resources": [
195207
{
208+
"condition": "[not(parameters('useStaticStorageResource'))]",
196209
"type": "blobServices/containers",
197210
"apiVersion": "[variables('storageMgmtApiVersion')]",
198211
"name": "[concat('default/', parameters('targetContainerName_1'))]",
@@ -201,6 +214,7 @@
201214
]
202215
},
203216
{
217+
"condition": "[not(parameters('useStaticStorageResource'))]",
204218
"type": "blobServices/containers",
205219
"apiVersion": "[variables('storageMgmtApiVersion')]",
206220
"name": "[concat('default/', parameters('targetContainerName_2'))]",
@@ -209,6 +223,7 @@
209223
]
210224
},
211225
{
226+
"condition": "[not(parameters('useStaticStorageResource'))]",
212227
"type": "blobServices/containers",
213228
"apiVersion": "[variables('storageMgmtApiVersion')]",
214229
"name": "[concat('default/', parameters('targetContainerName_3'))]",
@@ -217,14 +232,16 @@
217232
]
218233
},
219234
{
235+
"condition": "[not(parameters('useStaticStorageResource'))]",
220236
"type": "blobServices/containers",
221237
"apiVersion": "[variables('storageMgmtApiVersion')]",
222238
"name": "[concat('default/', parameters('targetContainerName_4'))]",
223239
"dependsOn": [
224240
"[parameters('blobStorageAccount')]"
225241
]
226-
},
242+
},
227243
{
244+
"condition": "[not(parameters('useStaticStorageResource'))]",
228245
"type": "blobServices/containers",
229246
"apiVersion": "[variables('storageMgmtApiVersion')]",
230247
"name": "[concat('default/', parameters('sourceContainerName'))]",
@@ -265,6 +282,7 @@
265282
"value": "[parameters('blobStorageAccount')]"
266283
},
267284
"TRANSLATION_DOCUMENT_STORAGE_KEY": {
285+
"condition": "[not(parameters('useStaticStorageResource'))]",
268286
"type": "string",
269287
"value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('storageMgmtApiVersion')).keys[0].value]"
270288
},
@@ -281,6 +299,7 @@
281299
"value": "[parameters('blobStorageAccount')]"
282300
},
283301
"AZURE_STORAGE_SOURCE_KEY": {
302+
"condition": "[not(parameters('useStaticStorageResource'))]",
284303
"type": "string",
285304
"value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('storageMgmtApiVersion')).keys[0].value]"
286305
},
@@ -289,34 +308,42 @@
289308
"value": "[variables('azureStorageEndpoint')]"
290309
},
291310
"AZURE_SOURCE_CONTAINER_URL": {
311+
"condition": "[not(parameters('useStaticStorageResource'))]",
292312
"type": "string",
293313
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
294314
},
295315
"AZURE_SOURCE_CONTAINER_URL_1": {
316+
"condition": "[not(parameters('useStaticStorageResource'))]",
296317
"type": "string",
297318
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
298319
},
299320
"AZURE_SOURCE_CONTAINER_URL_2": {
321+
"condition": "[not(parameters('useStaticStorageResource'))]",
300322
"type": "string",
301323
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
302324
},
303325
"AZURE_TRANSLATION_GLOSSARY_URL": {
326+
"condition": "[not(parameters('useStaticStorageResource'))]",
304327
"type": "string",
305328
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('sourceContainerName'), '/', parameters('glossaryFileName'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('sourceContainerSasProperties')).serviceSasToken)]"
306329
},
307330
"AZURE_TARGET_CONTAINER_URL": {
331+
"condition": "[not(parameters('useStaticStorageResource'))]",
308332
"type": "string",
309333
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_1'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('targetContainerSasProperties_1')).serviceSasToken)]"
310334
},
311335
"AZURE_TARGET_CONTAINER_URL_FR": {
336+
"condition": "[not(parameters('useStaticStorageResource'))]",
312337
"type": "string",
313338
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_2'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('targetContainerSasProperties_2')).serviceSasToken)]"
314339
},
315340
"AZURE_TARGET_CONTAINER_URL_AR": {
341+
"condition": "[not(parameters('useStaticStorageResource'))]",
316342
"type": "string",
317343
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_3'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('targetContainerSasProperties_3')).serviceSasToken)]"
318344
},
319345
"AZURE_TARGET_CONTAINER_URL_ES": {
346+
"condition": "[not(parameters('useStaticStorageResource'))]",
320347
"type": "string",
321348
"value": "[concat(reference(parameters('storageAccResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('targetContainerName_4'), '?', listServiceSas(parameters('storageAccResourceId'), '2019-06-01', parameters('targetContainerSasProperties_4')).serviceSasToken)]"
322349
}

sdk/translation/tests.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ stages:
55
parameters:
66
BuildTargetingString: azure-ai-translation-document
77
ServiceDirectory: translation
8-
MatrixReplace:
9-
- TestSamples=.*/true
8+
Clouds: Public,Int
9+
CloudConfig:
10+
Public:
11+
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
12+
MatrixReplace:
13+
- TestSamples=.*/true
14+
Int:
15+
SubscriptionConfiguration: $(sub-config-translation-int-test-resources)
1016
EnvVars:
1117
AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id)
1218
AZURE_CLIENT_SECRET: $(aad-azure-sdk-test-client-secret)

0 commit comments

Comments
 (0)