Skip to content

Commit 5190090

Browse files
committed
Fleet contract updated
1 parent 29ec1d2 commit 5190090

File tree

4 files changed

+66
-39
lines changed

4 files changed

+66
-39
lines changed

src/cosmosdb-preview/azext_cosmosdb_preview/_params.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@
201201

202202
FLEETSPACE_PROPERTIES_EXAMPLE = """--body "{
203203
\\"properties\\": {
204+
\\"serviceTier\\": \\"GeneralPurpose\\",
205+
\\"dataRegions\\": [\\"West US 2\\"],
204206
\\"throughputPoolConfiguration\\": {
205207
\\"minThroughput\\": 100000,
206-
\\"maxThroughput\\": 300000,
207-
\\"serviceTier\\": \\"GeneralPurpose\\",
208-
\\"dataRegions\\": [\\"West US 2\\"]
209-
},
208+
\\"maxThroughput\\": 300000
209+
}
210210
}
211211
}"
212212
"""
@@ -854,10 +854,10 @@ def load_arguments(self, _):
854854
c.argument('fleetspace_name', options_list=['--fleetspace-name', '-n'], help='Name of the Fleetspace resource.', required=True)
855855

856856
with self.argument_context('cosmosdb fleetspace create') as c:
857-
c.argument('fleetspace_body', options_list=['--body', '-b'], validator=validate_fleetspace_body, completer=FilesCompleter(), help="Fleetspace body with properties.throughputPoolConfiguration (fields: minThroughput, maxThroughput, serviceTier, dataRegions). You can enter it as a string or as a file, e.g., --body @fleetspace.json or " + FLEETSPACE_PROPERTIES_EXAMPLE)
857+
c.argument('fleetspace_body', options_list=['--body', '-b'], validator=validate_fleetspace_body, completer=FilesCompleter(), help="Fleetspace body with properties.serviceTier (required), properties.dataRegions (required), and properties.throughputPoolConfiguration (fields: minThroughput, maxThroughput). You can enter it as a string or as a file, e.g., --body @fleetspace.json or " + FLEETSPACE_PROPERTIES_EXAMPLE)
858858

859859
with self.argument_context('cosmosdb fleetspace update') as c:
860-
c.argument('fleetspace_body', options_list=['--body', '-b'], validator=validate_fleetspace_body, completer=FilesCompleter(), help="Fleetspace body with properties.throughputPoolConfiguration (fields: minThroughput, maxThroughput, serviceTier, dataRegions). You can enter it as a string or as a file, e.g., --body @fleetspace.json or " + FLEETSPACE_PROPERTIES_EXAMPLE)
860+
c.argument('fleetspace_body', options_list=['--body', '-b'], validator=validate_fleetspace_body, completer=FilesCompleter(), help="Fleetspace body with properties.serviceTier (optional), properties.dataRegions (optional), and properties.throughputPoolConfiguration (fields: minThroughput, maxThroughput). You can enter it as a string or as a file, e.g., --body @fleetspace.json or " + FLEETSPACE_PROPERTIES_EXAMPLE)
861861

862862
# Cosmos DB Fleetspace account
863863
with self.argument_context('cosmosdb fleetspace account') as c:

src/cosmosdb-preview/azext_cosmosdb_preview/_validators.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ def validate_fleetspace_body(cmd, ns):
452452
if not isinstance(tp_config, dict):
453453
raise InvalidArgumentValueError('Missing or invalid "throughputPoolConfiguration" in properties.')
454454

455-
for field in ['minThroughput', 'maxThroughput', 'serviceTier', 'dataRegions']:
455+
# Check for minThroughput and maxThroughput in throughputPoolConfiguration
456+
for field in ['minThroughput', 'maxThroughput']:
456457
if field not in tp_config:
457458
raise InvalidArgumentValueError(f'Missing "{field}" in throughputPoolConfiguration.')
458459

@@ -462,11 +463,14 @@ def validate_fleetspace_body(cmd, ns):
462463
if not isinstance(tp_config['maxThroughput'], int) or tp_config['maxThroughput'] <= 0:
463464
raise InvalidArgumentValueError('"maxThroughput" must be a positive integer.')
464465

465-
if not isinstance(tp_config['serviceTier'], str):
466-
raise InvalidArgumentValueError('"serviceTier" must be a string.')
466+
# Check for serviceTier and dataRegions at base properties level
467+
if 'serviceTier' in props:
468+
if not isinstance(props['serviceTier'], str):
469+
raise InvalidArgumentValueError('"serviceTier" must be a string.')
467470

468-
if not isinstance(tp_config['dataRegions'], list) or not all(isinstance(r, str) for r in tp_config['dataRegions']):
469-
raise InvalidArgumentValueError('"dataRegions" must be a list of strings.')
471+
if 'dataRegions' in props:
472+
if not isinstance(props['dataRegions'], list) or not all(isinstance(r, str) for r in props['dataRegions']):
473+
raise InvalidArgumentValueError('"dataRegions" must be a list of strings.')
470474

471475
ns.fleetspace_body = body
472476

src/cosmosdb-preview/azext_cosmosdb_preview/custom.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,23 +3305,33 @@ def cli_cosmosdb_fleetspace_create(client,
33053305

33063306
"""Creates an Azure Cosmos DB Fleetspace."""
33073307

3308+
# Extract service_tier and data_regions from base level (mandatory for create)
3309+
service_tier = fleetspace_body['properties'].get('serviceTier')
3310+
data_regions = fleetspace_body['properties'].get('dataRegions')
3311+
3312+
if not service_tier:
3313+
raise CLIError('Missing required field "serviceTier" in properties.')
3314+
3315+
if not data_regions:
3316+
raise CLIError('Missing required field "dataRegions" in properties.')
3317+
33083318
throughput_pool_config = FleetspacePropertiesThroughputPoolConfiguration(
33093319
min_throughput=fleetspace_body['properties']['throughputPoolConfiguration']['minThroughput'],
3310-
max_throughput=fleetspace_body['properties']['throughputPoolConfiguration']['maxThroughput'],
3311-
service_tier=fleetspace_body['properties']['throughputPoolConfiguration']['serviceTier'],
3312-
data_regions=fleetspace_body['properties']['throughputPoolConfiguration']['dataRegions']
3320+
max_throughput=fleetspace_body['properties']['throughputPoolConfiguration']['maxThroughput']
33133321
)
33143322

3315-
fleetspace_body = FleetspaceResource(
3323+
fleetspace_resource = FleetspaceResource(
33163324
fleetspace_api_kind="NoSQL",
3317-
throughput_pool_configuration=throughput_pool_config
3325+
throughput_pool_configuration=throughput_pool_config,
3326+
service_tier=service_tier,
3327+
data_regions=data_regions
33183328
)
33193329

33203330
return client.begin_create(
33213331
resource_group_name=resource_group_name,
33223332
fleet_name=fleet_name,
33233333
fleetspace_name=fleetspace_name,
3324-
body=fleetspace_body
3334+
body=fleetspace_resource
33253335
)
33263336

33273337

@@ -3333,22 +3343,27 @@ def cli_cosmosdb_fleetspace_update(client,
33333343

33343344
"""Updates an existing Azure Cosmos DB Fleetspace."""
33353345

3346+
# Extract service_tier and data_regions from base level (optional for update)
3347+
service_tier = fleetspace_body['properties'].get('serviceTier')
3348+
data_regions = fleetspace_body['properties'].get('dataRegions')
3349+
33363350
throughput_pool_config = FleetspacePropertiesThroughputPoolConfiguration(
33373351
min_throughput=fleetspace_body['properties']['throughputPoolConfiguration']['minThroughput'],
3338-
max_throughput=fleetspace_body['properties']['throughputPoolConfiguration']['maxThroughput'],
3339-
service_tier=fleetspace_body['properties']['throughputPoolConfiguration']['serviceTier']
3352+
max_throughput=fleetspace_body['properties']['throughputPoolConfiguration']['maxThroughput']
33403353
)
33413354

3342-
fleetspace_body = FleetspaceResource(
3355+
fleetspace_resource = FleetspaceResource(
33433356
fleetspace_api_kind="NoSQL",
3344-
throughput_pool_configuration=throughput_pool_config
3357+
throughput_pool_configuration=throughput_pool_config,
3358+
service_tier=service_tier,
3359+
data_regions=data_regions
33453360
)
33463361

33473362
return client.begin_update(
33483363
resource_group_name=resource_group_name,
33493364
fleet_name=fleet_name,
33503365
fleetspace_name=fleetspace_name,
3351-
body=fleetspace_body
3366+
body=fleetspace_resource
33523367
)
33533368

33543369

src/cosmosdb-preview/azext_cosmosdb_preview/tests/latest/test_cosmosdb_fleet_fleetspace_fleetspaceAccount_scenario.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,31 @@ class CosmosdbFleetScenarioTest(ScenarioTest):
1414
@ResourceGroupPreparer(name_prefix='cli_test_cosmosdb_fleet', location='westus2')
1515
def test_cosmosdb_fleet_fleetspace_fleetspaceAccount(self, resource_group):
1616
# Names
17-
fleet_name = 'fleetTest'
18-
fleet_analytics_name = 'fleetAnalyticsTest'
19-
fleetspace_name = 'fleetspaceTest'
17+
fleet_name = self.create_random_name('fleet', 15)
18+
fleet_analytics_name = self.create_random_name('fa', 10)
19+
fleetspace_name = self.create_random_name('fs', 10)
2020
account_name = self.create_random_name('acct', 15)
21+
storage_account_name = account_name + 'st'
2122

2223
# JSON
2324
fleetspace_body = self._write_temp_json({
2425
"properties": {
26+
"serviceTier": "GeneralPurpose",
27+
"dataRegions": ["West US 2"],
2528
"throughputPoolConfiguration": {
2629
"minThroughput": 100000,
27-
"maxThroughput": 400000,
28-
"serviceTier": "GeneralPurpose",
29-
"dataRegions": ["West US 2",]
30+
"maxThroughput": 400000
3031
}
3132
}
3233
})
3334

3435
fleetspace_update_body = self._write_temp_json({
3536
"properties": {
37+
"serviceTier": "GeneralPurpose",
38+
"dataRegions": ["West US 2"],
3639
"throughputPoolConfiguration": {
3740
"minThroughput": 200000,
38-
"maxThroughput": 600000,
39-
"serviceTier": "GeneralPurpose",
40-
"dataRegions": ["West US 2"]
41+
"maxThroughput": 600000
4142
}
4243
}
4344
})
@@ -51,52 +52,59 @@ def test_cosmosdb_fleet_fleetspace_fleetspaceAccount(self, resource_group):
5152
}
5253
})
5354

55+
# Feature being updated with a different contract. Will be enabled in the future.
56+
'''
5457
fleet_analytics_body = self._write_temp_json({
5558
"properties": {
5659
"storageLocationType": "StorageAccount",
57-
"storageLocationUri": f"/subscriptions/{self.get_subscription_id()}/resourceGroups/{resource_group}/providers/Microsoft.Storage/storageAccounts/myStorageAccount",
60+
"storageLocationUri": f"/subscriptions/{self.get_subscription_id()}/resourceGroups/{resource_group}/providers/Microsoft.Storage/storageAccounts/{storage_account_name}",
5861
}
5962
})
63+
'''
6064

6165
self.kwargs.update({
6266
'rg': resource_group,
6367
'acct': account_name,
68+
'storage': storage_account_name,
6469
'fleet': fleet_name,
65-
'fanalytics': fleet_analytics_name,
66-
'fanalyticsbody': fleet_analytics_body,
6770
'fsp': fleetspace_name,
6871
'fspacct': account_name,
6972
'fspbody': fleetspace_body,
7073
'fspupdate': fleetspace_update_body,
7174
'fspacctbody': fleetspace_account_body
7275
})
7376

74-
# Create Cosmos DB account dynamically
75-
self.cmd('az cosmosdb create -g {rg} -n {acct} --locations regionName=westus2 failoverPriority=0 isZoneRedundant=False')
76-
7777
# Fleet
7878
self.cmd('az cosmosdb fleet create -g {rg} -n {fleet} -l westus2')
7979
self.cmd('az cosmosdb fleet show -g {rg} -n {fleet}')
8080
self.cmd('az cosmosdb fleet list -g {rg}')
81+
82+
# Create Storage Account for Fleet Analytics
83+
self.cmd('az storage account create -g {rg} -n {storage} --sku Standard_LRS --location westus2')
8184

85+
# Feature being updated with a different contract. Will be enabled in the future.
86+
'''
8287
# Fleet Analytics
8388
self.cmd('az cosmosdb fleet analytics create -g {rg} --fleet-name {fleet} -n {fanalytics} --body @{fanalyticsbody}')
8489
self.cmd('az cosmosdb fleet analytics show -g {rg} --fleet-name {fleet} -n {fanalytics}')
8590
self.cmd('az cosmosdb fleet analytics list -g {rg} --fleet-name {fleet}')
86-
91+
'''
8792
# Fleetspace
8893
self.cmd('az cosmosdb fleetspace create -g {rg} --fleet-name {fleet} -n {fsp} --body @{fspbody}')
8994
self.cmd('az cosmosdb fleetspace update -g {rg} --fleet-name {fleet} -n {fsp} --body @{fspupdate}')
9095
self.cmd('az cosmosdb fleetspace show -g {rg} --fleet-name {fleet} -n {fsp}')
9196
self.cmd('az cosmosdb fleetspace list -g {rg} --fleet-name {fleet}')
9297

98+
# Create Cosmos DB account dynamically
99+
self.cmd('az cosmosdb create -g {rg} -n {acct} --locations regionName=westus2 failoverPriority=0 isZoneRedundant=False')
100+
93101
# Fleetspace Account
94102
self.cmd('az cosmosdb fleetspace account create -g {rg} --fleet-name {fleet} --fleetspace-name {fsp} --fleetspace-account-name {fspacct} --body @{fspacctbody}')
95103
self.cmd('az cosmosdb fleetspace account show -g {rg} --fleet-name {fleet} --fleetspace-name {fsp} --fleetspace-account-name {fspacct}')
96104
self.cmd('az cosmosdb fleetspace account list -g {rg} --fleet-name {fleet} --fleetspace-name {fsp}')
97105

98106
# Deletes
99-
self.cmd('az cosmosdb fleet analytics delete -g {rg} --fleet-name {fleet} -n {fanalytics} --yes')
107+
# self.cmd('az cosmosdb fleet analytics delete -g {rg} --fleet-name {fleet} -n {fanalytics} --yes')
100108
self.cmd('az cosmosdb fleetspace account delete -g {rg} --fleet-name {fleet} --fleetspace-name {fsp} --fleetspace-account-name {fspacct} --yes')
101109
self.cmd('az cosmosdb fleetspace delete -g {rg} --fleet-name {fleet} -n {fsp} --yes')
102110
self.cmd('az cosmosdb fleet delete -g {rg} -n {fleet} --yes')

0 commit comments

Comments
 (0)