Skip to content

Commit 40f4bab

Browse files
simorenohannatischgahl-levytjprescott
authored
[Cosmos] Infra: use Bicep for resource provisioning (#24198)
* initial commit * Client Constructor (#20310) * Removed some stuff * Looking at constructors * Updated request * Added client close * working client creation Co-authored-by: simorenoh <[email protected]> * read database database read works, but ignored exception is returned: Fatal error on SSL transport NoneType has no attribute 'send' (_loop._proactor.send) RuntimeError: Event loop is closed Unclosed connector/ connection * Update simon_testfile.py * with coroutine Added methods needed to use async with when initializing client, but logs output "Exception ignored... Runtime Error: Event loop is closed" * Update simon_testfile.py * small changes * async with returns no exceptions * async read container * async item read * cleaning up * create item/ database methods * item delete working * docs replace functionality missing upsert and other resources * upsert functionality missing read_all_items and both query methods for container class * missing query methods * CRUD for udf, sproc, triggers * initial query logic + container methods * missing some execution logic and tests * oops * fully working queries * small fix to query_items() also fixed README and added examples_async * Update _cosmos_client_connection_async.py * Update _cosmos_client_connection.py * documentation update * updated MIT dates and get_user_client() description * Update CHANGELOG.md * Delete simon_testfile.py * leftover retry utility * Update README.md * docs and removed six package * changes based on comments still missing discussion resolution on SSL verification and tests for async functionality under test module (apart from samples which are basically end to end tests) * small change in type hints * updated readme * fixes based on conversations * added missing type comments * update changelog for ci pipeline * added typehints, moved params into keywords, added decorators, made _connection_policy private * changes based on sync with central sdk * remove is_system_key from scripts (only used in execute_sproc) is_system_key verifies that an empty partition key is properly dealt with if ['partitionKey']['systemKey'] exists in the container options - however, we do not allow containers to be created with empty partition key values in the python sdk, so the functionality is needless * Revert "remove is_system_key from scripts (only used in execute_sproc)" Reverting last commit, will find way to init is_system_key for now * async script proxy using composition * pylint * capitalized constants * Apply suggestions from code review Clarifying comments for README Co-authored-by: Gahl Levy <[email protected]> * closing python code snippet * last doc updates * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Simon Moreno <[email protected]> * version update * cosmos updates for release * fix connection string comma * Update CHANGELOG.md * fixing extra await keyword in sample * Update CHANGELOG.md * Update CHANGELOG.md * using bicep file to provision test resources * Update tests.yml Co-authored-by: annatisch <[email protected]> Co-authored-by: Gahl Levy <[email protected]> Co-authored-by: Travis Prescott <[email protected]>
1 parent e3442fc commit 40f4bab

File tree

2 files changed

+73
-24
lines changed

2 files changed

+73
-24
lines changed

sdk/cosmos/test-resources.bicep

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
param baseName string
2+
3+
@description('Flag to enable or disable multiple write locations on CosmosDB Account')
4+
param enableMultipleWriteLocations bool
5+
6+
@description('Default Cosmosdb Account level consistency')
7+
param defaultConsistencyLevel string = 'Session'
8+
9+
@description('Enable multiple regions, default value is false')
10+
param enableMultipleRegions bool = false
11+
12+
@description('Location for the Cosmos DB account.')
13+
param location string = resourceGroup().location
14+
15+
@description('The api version to be used by Bicep to create resources')
16+
param apiVersion string = '2020-04-01'
17+
18+
var accountName = toLower(baseName)
19+
var resourceId = cosmosAccount.id
20+
var singleRegionConfiguration = [
21+
{
22+
locationName: 'East US 2'
23+
provisioningState: 'Succeeded'
24+
failoverPriority: 0
25+
isZoneRedundant: false
26+
}
27+
]
28+
var multiRegionConfiguration = [
29+
{
30+
locationName: 'East US 2'
31+
provisioningState: 'Succeeded'
32+
failoverPriority: 0
33+
isZoneRedundant: false
34+
}
35+
{
36+
locationName: 'East US'
37+
provisioningState: 'Succeeded'
38+
failoverPriority: 1
39+
isZoneRedundant: false
40+
}
41+
]
42+
var locationsConfiguration = (enableMultipleRegions ? multiRegionConfiguration : singleRegionConfiguration)
43+
44+
resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2020-04-01' = {
45+
name: toLower(accountName)
46+
location: location
47+
kind: 'GlobalDocumentDB'
48+
properties: {
49+
publicNetworkAccess: 'Enabled'
50+
enableAutomaticFailover: false
51+
enableMultipleWriteLocations: enableMultipleWriteLocations
52+
isVirtualNetworkFilterEnabled: false
53+
disableKeyBasedMetadataWriteAccess: false
54+
enableFreeTier: false
55+
enableAnalyticalStorage: false
56+
databaseAccountOfferType: 'Standard'
57+
consistencyPolicy: {
58+
defaultConsistencyLevel: defaultConsistencyLevel
59+
}
60+
locations: locationsConfiguration
61+
}
62+
}
63+
64+
65+
output ACCOUNT_HOST string = reference(resourceId, apiVersion).documentEndpoint
66+
output ACCOUNT_KEY string = listKeys(resourceId, apiVersion).primaryMasterKey

sdk/cosmos/tests.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,12 @@ trigger: none
33
stages:
44
- template: ../../eng/pipelines/templates/stages/archetype-sdk-tests.yml
55
parameters:
6+
CloudConfig:
7+
Cosmos_Public:
8+
SubscriptionConfigurations:
9+
- $(sub-config-azure-cloud-test-resources)
10+
- $(sub-config-cosmos-azure-cloud-test-resources)
11+
Clouds: 'Cosmos_Public'
612
MaxParallel: 1
13+
BuildTargetingString: azure-cosmos
714
ServiceDirectory: cosmos
8-
TestMarkArgument: not globaldb
9-
EnvVars:
10-
ACCOUNT_KEY: $(python-cosmos-live-account-key)
11-
ACCOUNT_HOST: $(python-cosmos-live-account-host)
12-
13-
# Workaround to ensure deletion of databases from a statically defined
14-
# CosmosDB account.
15-
PreSteps:
16-
- pwsh: |
17-
$testDatabaseId = "Python Test Database " + (New-Guid).ToString()
18-
Write-Host Test Database ID: $testDatabaseId
19-
Write-Host "##vso[task.setvariable variable=COSMOS_TEST_DATABASE_ID]$testDatabaseId"
20-
displayName: Set COSMOS_TEST_DATABASE_ID
21-
PostSteps:
22-
- pwsh: >
23-
az cosmosdb sql database delete
24-
--db-name $env:COSMOS_TEST_DATABASE_ID
25-
--url-connection $(python-cosmos-live-account-host)
26-
--key $(python-cosmos-live-account-key)
27-
ignoreLASTEXITCODE: true
28-
# Always clean up the database (works when a build is canceled)
29-
condition: always()
30-
displayName: Cleanup test database
31-

0 commit comments

Comments
 (0)