Skip to content

Commit d168020

Browse files
authored
[EG] add back envvars to tests (#36606)
* add back to tests * remove conn str * Update sdk/eventgrid/tests.yml * update * update * update * add location
1 parent c66b691 commit d168020

File tree

5 files changed

+236
-10
lines changed

5 files changed

+236
-10
lines changed

sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_cloud_events_from_eventhub.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
import json
2222
from azure.core.messaging import CloudEvent
2323
from azure.eventhub import EventHubConsumerClient
24+
from azure.identity import DefaultAzureCredential
2425

25-
CONNECTION_STR = os.environ["EVENT_HUB_CONN_STR"]
2626
EVENTHUB_NAME = os.environ["EVENT_HUB_NAME"]
27+
EVENTHUB_FULLY_QUALIFIED_NAMESPACE = os.environ["EVENT_HUB_HOSTNAME"]
2728

2829

2930
def on_event(partition_context, event):
3031
dict_event: CloudEvent = CloudEvent.from_json(event)
3132
print("data: {}\n".format(dict_event.data))
3233

3334

34-
consumer_client = EventHubConsumerClient.from_connection_string(
35-
conn_str=CONNECTION_STR,
35+
consumer_client = EventHubConsumerClient(
36+
fully_qualified_namespace=EVENTHUB_FULLY_QUALIFIED_NAMESPACE,
37+
credential=DefaultAzureCredential(),
3638
consumer_group="$Default",
3739
eventhub_name=EVENTHUB_NAME,
3840
)

sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_cloud_events_from_storage_queue.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
from typing import List
1717
from azure.core.messaging import CloudEvent
1818
from azure.storage.queue import QueueServiceClient, BinaryBase64DecodePolicy
19+
from azure.identity import DefaultAzureCredential
1920
import os
2021
import json
2122

2223
# all types of CloudEvents below produce same DeserializedEvent
23-
connection_str = os.environ["AZURE_STORAGE_CONNECTION_STRING"]
2424
queue_name = os.environ["STORAGE_QUEUE_NAME"]
25+
queue_account_url = os.environ["STORAGE_QUEUE_ACCOUNT_URL"]
2526

26-
with QueueServiceClient.from_connection_string(connection_str) as qsc:
27+
with QueueServiceClient(queue_account_url, DefaultAzureCredential()) as qsc:
2728
payload = qsc.get_queue_client(queue=queue_name, message_decode_policy=BinaryBase64DecodePolicy()).peek_messages(
2829
max_messages=32
2930
)

sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_eventgrid_events_from_service_bus_queue.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
from azure.eventgrid import EventGridEvent
2121
from azure.servicebus import ServiceBusClient
22+
from azure.identity import DefaultAzureCredential
2223
import os
2324
import json
2425

2526
# all types of EventGridEvents below produce same DeserializedEvent
26-
connection_str = os.environ["SERVICE_BUS_CONNECTION_STR"]
2727
queue_name = os.environ["SERVICE_BUS_QUEUE_NAME"]
28+
fully_qualified_namespace = os.environ["SERVICEBUS_FULLY_QUALIFIED_NAMESPACE"]
2829

29-
with ServiceBusClient.from_connection_string(connection_str) as sb_client:
30+
with ServiceBusClient(fully_qualified_namespace, DefaultAzureCredential()) as sb_client:
3031
payload = sb_client.get_queue_receiver(queue_name).receive_messages()
3132

3233
## deserialize payload into a list of typed Events

sdk/eventgrid/test-resources.json

Lines changed: 221 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
"metadata": {
2121
"description": "The application client ID used to run tests."
2222
}
23+
},
24+
"serviceBusEndpointSuffix": {
25+
"type": "string",
26+
"defaultValue": ".servicebus.windows.net",
27+
"metadata": {
28+
"description": "The url suffix to use when creating eventhubs connection strings."
29+
}
30+
},
31+
"location": {
32+
"type": "string",
33+
"defaultValue": "[resourceGroup().location]",
34+
"metadata": {
35+
"description": "The location of the resources. By default, this is the same as the resource group."
36+
}
2337
}
2438
},
2539
"variables": {
@@ -38,7 +52,25 @@
3852
"partnerChannelName": "[concat(parameters('baseName'), 'partner-channel')]",
3953
"partnerTopicName": "[concat(parameters('baseName'), 'partner-topic')]",
4054
"eventGridDataSenderRoleId": "d5a91429-5739-47e2-a06b-3470a27159e7",
41-
"eventGridDataContributorRoleId": "1d8c3fe3-8864-474b-8749-01e3783e8157"
55+
"eventGridDataContributorRoleId": "1d8c3fe3-8864-474b-8749-01e3783e8157",
56+
"ehVersion": "2017-04-01",
57+
"contributorRoleId": "b24988ac-6180-42a0-ab88-20f7382dd24c",
58+
"eventHubsDataOwnerRoleId": "f526a384-b230-433a-b45c-95f59c4a2dec",
59+
"eventHubsNamespace": "[concat('eh-', parameters('baseName'))]",
60+
"eventHubName": "[concat('eh-', parameters('baseName'), '-hub')]",
61+
"eventHubAuthRuleName": "[concat('eh-', parameters('baseName'), '-hub-auth-rule')]",
62+
"serviceBusNamespace": "[concat('sb-', parameters('baseName'))]",
63+
"serviceBusSubscriptionName": "[concat('sb-', parameters('baseName'), '-subscription')]",
64+
"serviceBusTopicName": "[concat('sb-', parameters('baseName'), '-topic')]",
65+
"serviceBusQueueName": "[concat('sb-', parameters('baseName'), '-queue')]",
66+
"queueAuthorizationRuleName": "[concat('sb-', parameters('baseName'), '-queue-auth')]",
67+
"serviceBusSessionQueueName": "[concat('sb-', parameters('baseName'), '-session-queue')]",
68+
"sessionQueueAuthorizationRuleName": "[concat('sb-', parameters('baseName'), '-session-queue-auth')]",
69+
"serviceBusSessionId": "[concat('sb-', parameters('baseName'), '-session-queue-id')]",
70+
"defaultSASKeyName": "RootManageSharedAccessKey",
71+
"authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', variables('serviceBusNamespace'), variables('defaultSASKeyName'))]",
72+
"sbVersion": "2017-04-01",
73+
"serviceBusDataOwnerRoleId": "090c5cfd-751d-490a-894a-3ce6f1109419"
4274
},
4375
"resources": [
4476
{
@@ -55,6 +87,145 @@
5587
"publicNetworkAccess": "Enabled"
5688
}
5789
},
90+
{
91+
"apiVersion": "[variables('sbVersion')]",
92+
"name": "[variables('serviceBusNamespace')]",
93+
"type": "Microsoft.ServiceBus/Namespaces",
94+
"location": "[parameters('location')]",
95+
"sku": {
96+
"name": "Standard"
97+
},
98+
"resources": [
99+
{
100+
"apiVersion": "[variables('sbVersion')]",
101+
"name": "[variables('serviceBusTopicName')]",
102+
"type": "Topics",
103+
"dependsOn": [
104+
"[concat('Microsoft.ServiceBus/namespaces/', variables('serviceBusNamespace'))]"
105+
],
106+
"properties": {
107+
"path": "[variables('serviceBusTopicName')]"
108+
},
109+
"resources": [{
110+
"apiVersion": "[variables('sbVersion')]",
111+
"name": "[variables('serviceBusSubscriptionName')]",
112+
"type": "Subscriptions",
113+
"dependsOn": [
114+
"[variables('serviceBusTopicName')]"
115+
],
116+
"properties": {}
117+
}]
118+
},
119+
{
120+
"type": "Queues",
121+
"apiVersion": "[variables('sbVersion')]",
122+
"name": "[variables('serviceBusQueueName')]",
123+
"dependsOn": [
124+
"[resourceId('Microsoft.ServiceBus/namespaces', variables('serviceBusNamespace'))]"
125+
],
126+
"properties": {
127+
"lockDuration": "PT5M",
128+
"maxSizeInMegabytes": 1024,
129+
"requiresDuplicateDetection": false,
130+
"requiresSession": false,
131+
"defaultMessageTimeToLive": "P10675199DT2H48M5.4775807S",
132+
"deadLetteringOnMessageExpiration": false,
133+
"duplicateDetectionHistoryTimeWindow": "PT10M",
134+
"maxDeliveryCount": 10,
135+
"autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",
136+
"enablePartitioning": false,
137+
"enableExpress": false
138+
},
139+
"resources": [
140+
{
141+
"apiVersion": "[variables('sbVersion')]",
142+
"name": "[variables('queueAuthorizationRuleName')]",
143+
"type": "authorizationRules",
144+
"dependsOn": [
145+
"[variables('serviceBusQueueName')]"
146+
],
147+
"properties": {
148+
"Rights": ["Manage", "Send", "Listen"]
149+
}
150+
}
151+
]
152+
},
153+
{
154+
"type": "Queues",
155+
"apiVersion": "[variables('sbVersion')]",
156+
"name": "[variables('serviceBusSessionQueueName')]",
157+
"dependsOn": [
158+
"[resourceId('Microsoft.ServiceBus/namespaces', variables('serviceBusNamespace'))]"
159+
],
160+
"properties": {
161+
"lockDuration": "PT5M",
162+
"maxSizeInMegabytes": 1024,
163+
"requiresDuplicateDetection": false,
164+
"requiresSession": true,
165+
"defaultMessageTimeToLive": "P10675199DT2H48M5.4775807S",
166+
"deadLetteringOnMessageExpiration": false,
167+
"duplicateDetectionHistoryTimeWindow": "PT10M",
168+
"maxDeliveryCount": 10,
169+
"autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",
170+
"enablePartitioning": false,
171+
"enableExpress": false
172+
},
173+
"resources": [
174+
{
175+
"apiVersion": "[variables('sbVersion')]",
176+
"name": "[variables('sessionQueueAuthorizationRuleName')]",
177+
"type": "authorizationRules",
178+
"dependsOn": [
179+
"[variables('serviceBusSessionQueueName')]"
180+
],
181+
"properties": {
182+
"Rights": ["Manage", "Send", "Listen"]
183+
}
184+
}
185+
]
186+
}
187+
],
188+
"properties": {}
189+
},
190+
{
191+
"apiVersion": "[variables('ehVersion')]",
192+
"name": "[variables('eventHubsNamespace')]",
193+
"type": "Microsoft.EventHub/Namespaces",
194+
"location": "[parameters('location')]",
195+
"sku": {
196+
"name": "Standard",
197+
"tier": "Standard"
198+
},
199+
"resources": [
200+
{
201+
"type": "Microsoft.EventHub/namespaces/eventhubs",
202+
"apiVersion": "[variables('ehVersion')]",
203+
"name": "[concat(variables('eventHubsNamespace'), '/', variables('eventHubName'))]",
204+
"location": "[parameters('location')]",
205+
"dependsOn": [
206+
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespace'))]"
207+
],
208+
"properties": {
209+
"messageRetentionInDays": 7,
210+
"partitionCount": 1
211+
},
212+
"resources": [
213+
{
214+
"apiVersion": "[variables('ehVersion')]",
215+
"name": "[variables('eventHubAuthRuleName')]",
216+
"type": "authorizationRules",
217+
"dependsOn": [
218+
"[variables('eventHubName')]"
219+
],
220+
"properties": {
221+
"Rights": ["Manage", "Send", "Listen"]
222+
}
223+
}
224+
]
225+
}
226+
],
227+
"properties": {}
228+
},
58229
{
59230
"type": "Microsoft.EventGrid/namespaces/topics",
60231
"apiVersion": "2024-06-01-preview",
@@ -229,6 +400,42 @@
229400
"principalId": "[parameters('testApplicationOid')]",
230401
"scope": "[resourceGroup().id]"
231402
}
403+
},
404+
{
405+
"type": "Microsoft.Authorization/roleAssignments",
406+
"apiVersion": "2019-04-01-preview",
407+
"name": "[guid(resourceGroup().id, deployment().name, parameters('baseName'), variables('eventHubsDataOwnerRoleId'), parameters('testApplicationOid'))]",
408+
"properties": {
409+
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', variables('eventHubsDataOwnerRoleId'))]",
410+
"principalId": "[parameters('testApplicationOid')]",
411+
"scope": "[resourceGroup().id]"
412+
}
413+
},
414+
{
415+
"type": "Microsoft.Authorization/roleAssignments",
416+
"apiVersion": "2019-04-01-preview",
417+
"name": "[guid(resourceGroup().id, parameters('testApplicationOid'), variables('serviceBusDataOwnerRoleId'))]",
418+
"dependsOn": [
419+
"[resourceId('Microsoft.ServiceBus/Namespaces', variables('serviceBusNamespace'))]"
420+
],
421+
"properties": {
422+
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', variables('serviceBusDataOwnerRoleId'))]",
423+
"principalId": "[parameters('testApplicationOid')]",
424+
"scope": "[resourceGroup().id]"
425+
}
426+
},
427+
{
428+
"type": "Microsoft.Authorization/roleAssignments",
429+
"apiVersion": "2019-04-01-preview",
430+
"name": "[guid(resourceGroup().id, parameters('testApplicationOid'), variables('contributorRoleId'))]",
431+
"dependsOn": [
432+
"[resourceId('Microsoft.ServiceBus/Namespaces', variables('serviceBusNamespace'))]"
433+
],
434+
"properties": {
435+
"roleDefinitionId": "[resourceId('Microsoft.Authorization/roleDefinitions', variables('contributorRoleId'))]",
436+
"principalId": "[parameters('testApplicationOid')]",
437+
"scope": "[resourceGroup().id]"
438+
}
232439
}
233440
],
234441
"outputs": {
@@ -307,6 +514,18 @@
307514
"AZURE_SUBSCRIPTION_ID": {
308515
"type": "string",
309516
"value": "[subscription().subscriptionId]"
310-
}
517+
},
518+
"EVENT_HUB_NAMESPACE": {
519+
"type": "string",
520+
"value": "[variables('eventHubsNamespace')]"
521+
},
522+
"EVENT_HUB_HOSTNAME": {
523+
"type": "string",
524+
"value": "[concat(variables('eventHubsNamespace'), parameters('serviceBusEndpointSuffix'))]"
525+
},
526+
"SERVICEBUS_FULLY_QUALIFIED_NAMESPACE": {
527+
"type": "string",
528+
"value": "[concat(variables('serviceBusNamespace'), parameters('serviceBusEndpointSuffix'))]"
529+
}
311530
}
312531
}

sdk/eventgrid/tests.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ extends:
1212
EnvVars:
1313
TEST_MODE: 'RunLiveNoRecord'
1414
AZURE_TEST_RUN_LIVE: 'true'
15-
AZURE_SKIP_LIVE_RECORDING: 'True'
15+
AZURE_SKIP_LIVE_RECORDING: 'True'
16+
EVENTGRID_SAS: $(python-sdk-test-eg-sas)
17+
STORAGE_QUEUE_NAME: $(python-storage-queue-name)
18+
STORAGE_QUEUE_ACCOUNT_URL: $(python-storage-blob-storage-account-name)

0 commit comments

Comments
 (0)