Skip to content

Commit d93cf74

Browse files
authored
[Tables] Update dev test files (#41018)
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent a9fca87 commit d93cf74

File tree

7 files changed

+142
-337
lines changed

7 files changed

+142
-337
lines changed
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
-e ../../../tools/azure-sdk-tools
2-
-e ../../cosmos/azure-mgmt-cosmosdb
3-
-e ../../resources/azure-mgmt-resource
42
../../core/azure-core
5-
../../nspkg/azure-data-nspkg
3+
../../identity/azure-identity
64
# Aiohttp 3.8.6 triggers https://github.com/aio-libs/aiohttp/issues/4581 on pypy for some reasons
75
aiohttp<3.8.6 ; platform_python_implementation == "PyPy"
86
aiohttp ; platform_python_implementation != "PyPy"
9-
azure-identity
10-
python-dateutil>=2.8.0
7+
python-dateutil>=2.8.0

sdk/tables/azure-data-tables/samples/async_samples/sample_copy_table_async.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
1) TABLES_STORAGE_ENDPOINT_SUFFIX - the Table storage service account URL suffix
2020
2) TABLES_STORAGE_ACCOUNT_NAME - the Tables storage account name
2121
3) TABLES_PRIMARY_STORAGE_ACCOUNT_KEY - the Tables storage account access key
22-
4) STORAGE_ACCOUNT_NAME - the blob storage account name
23-
5) STORAGE_ACCOUNT_KEY - the blob storage account key
2422
"""
2523
import asyncio
2624
import json
@@ -63,13 +61,10 @@ def __init__(self):
6361
self.access_key = os.getenv("TABLES_PRIMARY_STORAGE_ACCOUNT_KEY")
6462
self.endpoint_suffix = os.getenv("TABLES_STORAGE_ENDPOINT_SUFFIX")
6563
self.account_name = os.getenv("TABLES_STORAGE_ACCOUNT_NAME")
66-
self.table_connection_string = f"DefaultEndpointsProtocol=https;AccountName={self.account_name};AccountKey={self.access_key};EndpointSuffix={self.endpoint_suffix}"
64+
self.storage_account_connection_string = f"DefaultEndpointsProtocol=https;AccountName={self.account_name};AccountKey={self.access_key};EndpointSuffix={self.endpoint_suffix}"
6765
self.copy_to_blob_table_name = "copytoblobtablename" + uuid4().hex
6866
self.copy_to_table_table_name = "copytotabletablename" + uuid4().hex
69-
self.blob_account_name = os.getenv("STORAGE_ACCOUNT_NAME")
70-
self.blob_account_key = os.getenv("STORAGE_ACCOUNT_KEY")
71-
self.blob_connection_string = f"DefDefaultEndpointsProtocol=https;AccountName={self.blob_account_name};AccountKey={self.blob_account_key};EndpointSuffix=core.windows.net"
72-
self.blob_service_client = BlobServiceClient.from_connection_string(self.blob_connection_string)
67+
self.blob_service_client = BlobServiceClient.from_connection_string(self.storage_account_connection_string)
7368
self.entity: EntityType = {
7469
"PartitionKey": "color",
7570
"text": "Marker",
@@ -110,7 +105,7 @@ async def copy_table_from_blob_to_table(self):
110105
blob_list = self.container_client.list_blobs()
111106
# Upload entities to a table
112107
table_service_client = TableServiceClient.from_connection_string(
113-
conn_str=self.table_connection_string, table_name=self.copy_to_table_table_name
108+
conn_str=self.storage_account_connection_string, table_name=self.copy_to_table_table_name
114109
)
115110
self.table_client = table_service_client.get_table_client(self.copy_to_table_table_name)
116111
await self.table_client.create_table()
@@ -129,7 +124,7 @@ async def copy_table_from_blob_to_table(self):
129124

130125
async def _setup_table(self):
131126
table_service_client = TableServiceClient.from_connection_string(
132-
conn_str=self.table_connection_string, table_name=self.copy_to_blob_table_name
127+
conn_str=self.storage_account_connection_string, table_name=self.copy_to_blob_table_name
133128
)
134129
self.table_client = table_service_client.get_table_client(self.copy_to_blob_table_name)
135130
await self.table_client.create_table()

sdk/tables/azure-data-tables/samples/sample_copy_table.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
1) TABLES_STORAGE_ENDPOINT_SUFFIX - the Table storage service account URL suffix
2020
2) TABLES_STORAGE_ACCOUNT_NAME - the Tables storage account name
2121
3) TABLES_PRIMARY_STORAGE_ACCOUNT_KEY - the Tables storage account access key
22-
4) STORAGE_ACCOUNT_NAME - the blob storage account name
23-
5) STORAGE_ACCOUNT_KEY - the blob storage account key
2422
"""
2523
import json
2624
import os
@@ -62,13 +60,10 @@ def __init__(self):
6260
self.access_key = os.getenv("TABLES_PRIMARY_STORAGE_ACCOUNT_KEY")
6361
self.endpoint_suffix = os.getenv("TABLES_STORAGE_ENDPOINT_SUFFIX")
6462
self.account_name = os.getenv("TABLES_STORAGE_ACCOUNT_NAME")
65-
self.table_connection_string = f"DefaultEndpointsProtocol=https;AccountName={self.account_name};AccountKey={self.access_key};EndpointSuffix={self.endpoint_suffix}"
63+
self.storage_account_connection_string = f"DefaultEndpointsProtocol=https;AccountName={self.account_name};AccountKey={self.access_key};EndpointSuffix={self.endpoint_suffix}"
6664
self.copy_to_blob_table_name = "copytoblobtablename" + uuid4().hex
6765
self.copy_to_table_table_name = "copytotabletablename" + uuid4().hex
68-
self.blob_account_name = os.getenv("STORAGE_ACCOUNT_NAME")
69-
self.blob_account_key = os.getenv("STORAGE_ACCOUNT_KEY")
70-
self.blob_connection_string = f"DefDefaultEndpointsProtocol=https;AccountName={self.blob_account_name};AccountKey={self.blob_account_key};EndpointSuffix=core.windows.net"
71-
self.blob_service_client = BlobServiceClient.from_connection_string(self.blob_connection_string)
66+
self.blob_service_client = BlobServiceClient.from_connection_string(self.storage_account_connection_string)
7267
self.entity: EntityType = {
7368
"PartitionKey": "color",
7469
"text": "Marker",
@@ -109,7 +104,7 @@ def copy_table_from_blob_to_table(self):
109104
blob_list = self.container_client.list_blobs()
110105
# Upload entities to a table
111106
table_service_client = TableServiceClient.from_connection_string(
112-
conn_str=self.table_connection_string, table_name=self.copy_to_table_table_name
107+
conn_str=self.storage_account_connection_string, table_name=self.copy_to_table_table_name
113108
)
114109
self.table_client = table_service_client.get_table_client(self.copy_to_table_table_name)
115110
self.table_client.create_table()
@@ -128,7 +123,7 @@ def copy_table_from_blob_to_table(self):
128123

129124
def _setup_table(self):
130125
table_service_client = TableServiceClient.from_connection_string(
131-
conn_str=self.table_connection_string, table_name=self.copy_to_blob_table_name
126+
conn_str=self.storage_account_connection_string, table_name=self.copy_to_blob_table_name
132127
)
133128
self.table_client = table_service_client.get_table_client(self.copy_to_blob_table_name)
134129
self.table_client.create_table()

sdk/tables/azure-data-tables/tests/_shared/cosmos_testcase.py

Lines changed: 0 additions & 115 deletions
This file was deleted.

sdk/tables/test-resources.bicep

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
@description('The base resource name.')
2+
param baseName string
3+
4+
@description('The principal to assign the role to. This is application object id.')
5+
param testApplicationOid string
6+
7+
@description('The url suffix to use when accessing the storage data plane.')
8+
param storageEndpointSuffix string = 'core.windows.net'
9+
10+
@description('The url suffix to use when accessing the cosmos data plane.')
11+
param cosmosEndpointSuffix string = 'cosmos.azure.com'
12+
13+
var location = resourceGroup().location
14+
var primaryAccountName = '${replace(replace(baseName, '-', ''), '_', '')}prim'
15+
16+
var customCosmosRoleName = 'Azure Cosmos DB SDK role for Table Data Plane'
17+
18+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2018-09-01-preview' = {
19+
name: guid('tableDataContributorRoleId', resourceGroup().id)
20+
properties: {
21+
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3')
22+
principalId: testApplicationOid
23+
}
24+
}
25+
26+
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
27+
name: primaryAccountName
28+
location: location
29+
sku: {
30+
name: 'Standard_RAGRS'
31+
}
32+
kind: 'StorageV2'
33+
properties: {
34+
networkAcls: {
35+
bypass: 'AzureServices'
36+
virtualNetworkRules: []
37+
ipRules: []
38+
defaultAction: 'Allow'
39+
}
40+
supportsHttpsTrafficOnly: true
41+
encryption: {
42+
services: {
43+
file: {
44+
enabled: true
45+
}
46+
blob: {
47+
enabled: true
48+
}
49+
}
50+
keySource: 'Microsoft.Storage'
51+
}
52+
accessTier: 'Cool'
53+
minimumTlsVersion: 'TLS1_2'
54+
}
55+
}
56+
57+
resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2020-04-01' = {
58+
name: primaryAccountName
59+
location: location
60+
tags: {
61+
defaultExperience: 'Azure Table'
62+
CosmosAccountType: 'Non-Production'
63+
}
64+
kind: 'GlobalDocumentDB'
65+
properties: {
66+
enableAutomaticFailover: false
67+
enableMultipleWriteLocations: false
68+
isVirtualNetworkFilterEnabled: false
69+
virtualNetworkRules: []
70+
disableKeyBasedMetadataWriteAccess: false
71+
enableFreeTier: false
72+
enableAnalyticalStorage: false
73+
databaseAccountOfferType: 'Standard'
74+
consistencyPolicy: {
75+
defaultConsistencyLevel: 'BoundedStaleness'
76+
maxIntervalInSeconds: 86400
77+
maxStalenessPrefix: 1000000
78+
}
79+
locations: [
80+
{
81+
locationName: location
82+
failoverPriority: 0
83+
isZoneRedundant: false
84+
}
85+
]
86+
capabilities: [
87+
{
88+
name: 'EnableTable'
89+
}
90+
]
91+
ipRules: []
92+
}
93+
}
94+
95+
resource cosmosRoleDef 'Microsoft.DocumentDB/databaseAccounts/tableRoleDefinitions@2024-12-01-preview' = {
96+
name: guid(customCosmosRoleName, 'roleDefinitionId')
97+
parent: cosmosAccount
98+
properties: {
99+
roleName: customCosmosRoleName
100+
permissions: [
101+
{
102+
dataActions: [
103+
'Microsoft.DocumentDB/databaseAccounts/readMetadata'
104+
'Microsoft.DocumentDB/databaseAccounts/tables/*'
105+
'Microsoft.DocumentDB/databaseAccounts/tables/containers/*'
106+
'Microsoft.DocumentDB/databaseAccounts/tables/containers/entities/*'
107+
'Microsoft.DocumentDB/databaseAccounts/throughputSettings/read'
108+
]
109+
}
110+
]
111+
assignableScopes: [
112+
cosmosAccount.id
113+
]
114+
}
115+
}
116+
117+
resource cosmosRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/tableRoleAssignments@2024-12-01-preview' = {
118+
name: guid(customCosmosRoleName, 'roleAssignmentId')
119+
parent: cosmosAccount
120+
properties: {
121+
scope: cosmosAccount.id
122+
roleDefinitionId: cosmosRoleDef.id
123+
principalId: testApplicationOid
124+
}
125+
}
126+
127+
output TABLES_STORAGE_ENDPOINT_SUFFIX string = storageEndpointSuffix
128+
output TABLES_STORAGE_ACCOUNT_NAME string = primaryAccountName
129+
output TABLES_PRIMARY_STORAGE_ACCOUNT_KEY string = storageAccount.listKeys().keys[0].value
130+
output TABLES_COSMOS_ENDPOINT_SUFFIX string = cosmosEndpointSuffix
131+
output TABLES_COSMOS_ACCOUNT_NAME string = primaryAccountName
132+
output TABLES_PRIMARY_COSMOS_ACCOUNT_KEY string = cosmosAccount.listKeys().primaryMasterKey

0 commit comments

Comments
 (0)