Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
fix-cli-flatten-parameter-construct-bug (#749)
Browse files Browse the repository at this point in the history
* fix-cli-flatten-parameter-construct-bug

* remove debug info

* add test
  • Loading branch information
qiaozha authored Feb 18, 2021
1 parent cb7ee69 commit b13482e
Show file tree
Hide file tree
Showing 25 changed files with 284 additions and 261 deletions.
8 changes: 8 additions & 0 deletions src/generate/renders/generated/CliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
} else {
originalParameterStack.pop();
originalParameterNameStack.pop();
// if this parameter was popped out because of last flattened parameter has just finished construction,
// then we need to run construction logic for this parameter one more time.
if (
originalParameterStack.length > 0 &&
model.MethodParameter['originalParameter'] === originalParameterStack.last
) {
skip = true;
}
}
}
} while (skip || model.SelectNextMethodParameter(true));
Expand Down
5 changes: 5 additions & 0 deletions test/scenarios/kusto/configuration/readme.az.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ cli:
param: 'clusterName'
set:
extensionMode: 'experimental'
- where:
group: '*'
op: '*'
param: 'sku'
cli-flatten: true

```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ az extension add --name kusto
#### kusto cluster ####
##### Create #####
```
az kusto cluster create --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true \
--sku name="Standard_L8s" capacity=2 tier="Standard" --resource-group "kustorptest"
az kusto cluster create --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true --name "Standard_L8s" \
--capacity 2 --tier "Standard" --resource-group "kustorptest"
az kusto cluster wait --created --name "{myCluster}" --resource-group "{rg}"
az kusto cluster wait --created --cluster-name "{myCluster}" --resource-group "{rg}"
```
##### Show #####
```
Expand All @@ -27,8 +27,8 @@ az kusto cluster list --resource-group "kustorptest"
```
##### Update #####
```
az kusto cluster update --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" --enable-purge true \
--enable-streaming-ingest true \
az kusto cluster update --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-purge true --enable-streaming-ingest true \
--key-vault-properties key-name="keyName" key-vault-uri="https://dummy.keyvault.com" key-version="keyVersion" \
--resource-group "kustorptest"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@
type: command
short-summary: "Create a Kusto cluster."
parameters:
- name: --sku
short-summary: "The SKU of the cluster."
long-summary: |
Usage: --sku name=XX capacity=XX tier=XX
name: Required. SKU name.
capacity: The number of instances of the cluster.
tier: Required. SKU tier.
- name: --trusted-external-tenants
short-summary: "The cluster's external tenants."
long-summary: |
Expand Down Expand Up @@ -87,23 +79,15 @@
examples:
- name: KustoClustersCreateOrUpdate
text: |-
az kusto cluster create --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true --sku name="Standard_L8s" \
capacity=2 tier="Standard" --resource-group "kustorptest"
az kusto cluster create --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location \
"westus" --enable-double-encryption false --enable-purge true --enable-streaming-ingest true --name "Standard_L8s" \
--capacity 2 --tier "Standard" --resource-group "kustorptest"
"""

helps['kusto cluster update'] = """
type: command
short-summary: "Update a Kusto cluster."
parameters:
- name: --sku
short-summary: "The SKU of the cluster."
long-summary: |
Usage: --sku name=XX capacity=XX tier=XX
name: Required. SKU name.
capacity: The number of instances of the cluster.
tier: Required. SKU tier.
- name: --trusted-external-tenants
short-summary: "The cluster's external tenants."
long-summary: |
Expand Down Expand Up @@ -140,8 +124,8 @@
examples:
- name: KustoClustersUpdate
text: |-
az kusto cluster update --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-purge true --enable-streaming-ingest true --key-vault-properties key-name="keyName" \
az kusto cluster update --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location \
"westus" --enable-purge true --enable-streaming-ingest true --key-vault-properties key-name="keyName" \
key-vault-uri="https://dummy.keyvault.com" key-version="keyVersion" --resource-group "kustorptest"
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
validate_file_or_dict
)
from azext_kusto.action import (
AddSku,
AddTrustedExternalTenants,
AddOptimizedAutoscale,
AddVirtualNetworkConfiguration,
Expand All @@ -46,12 +45,21 @@ def load_arguments(self, _):

with self.argument_context('kusto cluster create') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('cluster_name', options_list=['--name', '-n', '--cluster-name'], type=str, help='The name of the '
'Kusto cluster.')
c.argument('cluster_name', type=str, help='The name of the Kusto cluster.')
c.argument('tags', tags_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False,
validator=get_default_location_from_resource_group)
c.argument('sku', action=AddSku, nargs='+', help='The SKU of the cluster.')
c.argument('name', arg_type=get_enum_type(['Standard_DS13_v2+1TB_PS', 'Standard_DS13_v2+2TB_PS',
'Standard_DS14_v2+3TB_PS', 'Standard_DS14_v2+4TB_PS',
'Standard_D13_v2', 'Standard_D14_v2', 'Standard_L8s',
'Standard_L16s', 'Standard_D11_v2', 'Standard_D12_v2',
'Standard_L4s', 'Dev(No SLA)_Standard_D11_v2', 'Standard_E2a_v4',
'Standard_E4a_v4', 'Standard_E8a_v4', 'Standard_E16a_v4',
'Standard_E8as_v4+1TB_PS', 'Standard_E8as_v4+2TB_PS',
'Standard_E16as_v4+3TB_PS', 'Standard_E16as_v4+4TB_PS', 'Dev(No '
'SLA)_Standard_E2a_v4']), help='SKU name.')
c.argument('capacity', type=int, help='The number of instances of the cluster.')
c.argument('tier', arg_type=get_enum_type(['Basic', 'Standard']), help='SKU tier.')
c.argument('zones', nargs='+', help='The availability zones of the cluster.')
c.argument('trusted_external_tenants', action=AddTrustedExternalTenants, nargs='+', help='The cluster\'s '
'external tenants.')
Expand Down Expand Up @@ -79,12 +87,21 @@ def load_arguments(self, _):

with self.argument_context('kusto cluster update') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('cluster_name', options_list=['--name', '-n', '--cluster-name'], type=str, help='The name of the '
'Kusto cluster.', id_part='name')
c.argument('cluster_name', type=str, help='The name of the Kusto cluster.', id_part='name')
c.argument('tags', tags_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=False,
validator=get_default_location_from_resource_group)
c.argument('sku', action=AddSku, nargs='+', help='The SKU of the cluster.')
c.argument('name', arg_type=get_enum_type(['Standard_DS13_v2+1TB_PS', 'Standard_DS13_v2+2TB_PS',
'Standard_DS14_v2+3TB_PS', 'Standard_DS14_v2+4TB_PS',
'Standard_D13_v2', 'Standard_D14_v2', 'Standard_L8s',
'Standard_L16s', 'Standard_D11_v2', 'Standard_D12_v2',
'Standard_L4s', 'Dev(No SLA)_Standard_D11_v2', 'Standard_E2a_v4',
'Standard_E4a_v4', 'Standard_E8a_v4', 'Standard_E16a_v4',
'Standard_E8as_v4+1TB_PS', 'Standard_E8as_v4+2TB_PS',
'Standard_E16as_v4+3TB_PS', 'Standard_E16as_v4+4TB_PS', 'Dev(No '
'SLA)_Standard_E2a_v4']), help='SKU name.')
c.argument('capacity', type=int, help='The number of instances of the cluster.')
c.argument('tier', arg_type=get_enum_type(['Basic', 'Standard']), help='SKU tier.')
c.argument('trusted_external_tenants', action=AddTrustedExternalTenants, nargs='+', help='The cluster\'s '
'external tenants.')
c.argument('optimized_autoscale', action=AddOptimizedAutoscale, nargs='+', help='Optimized auto scale '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,6 @@
from knack.util import CLIError


class AddSku(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.sku = action

def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'name':
d['name'] = v[0]
elif kl == 'capacity':
d['capacity'] = v[0]
elif kl == 'tier':
d['tier'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: name, '
'capacity, tier'.format(k))
return d


class AddTrustedExternalTenants(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def kusto_cluster_create(client,
resource_group_name,
cluster_name,
location,
sku,
name,
tier,
tags=None,
capacity=None,
zones=None,
trusted_external_tenants=None,
optimized_autoscale=None,
Expand All @@ -55,7 +57,10 @@ def kusto_cluster_create(client,
parameters = {}
parameters['tags'] = tags
parameters['location'] = location
parameters['sku'] = sku
parameters['sku'] = {}
parameters['sku']['name'] = name
parameters['sku']['capacity'] = capacity
parameters['sku']['tier'] = tier
parameters['zones'] = zones
parameters['trusted_external_tenants'] = trusted_external_tenants
parameters['optimized_autoscale'] = optimized_autoscale
Expand All @@ -80,7 +85,9 @@ def kusto_cluster_update(client,
cluster_name,
tags=None,
location=None,
sku=None,
name=None,
capacity=None,
tier=None,
trusted_external_tenants=None,
optimized_autoscale=None,
enable_disk_encryption=None,
Expand All @@ -101,7 +108,10 @@ def kusto_cluster_update(client,
parameters = {}
parameters['tags'] = tags
parameters['location'] = location
parameters['sku'] = sku
parameters['sku'] = {}
parameters['sku']['name'] = name
parameters['sku']['capacity'] = capacity
parameters['sku']['tier'] = tier
parameters['trusted_external_tenants'] = trusted_external_tenants
parameters['optimized_autoscale'] = optimized_autoscale
parameters['enable_disk_encryption'] = enable_disk_encryption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ def step_cluster_create(test, rg, checks=None):
if checks is None:
checks = []
test.cmd('az kusto cluster create '
'--name "{myCluster}" '
'--cluster-name "{myCluster}" '
'--type "SystemAssigned" '
'--location "westus" '
'--enable-double-encryption false '
'--enable-purge true '
'--enable-streaming-ingest true '
'--sku name="Standard_L8s" capacity=2 tier="Standard" '
'--name "Standard_L8s" '
'--capacity 2 '
'--tier "Standard" '
'--resource-group "{rg}"',
checks=[])
test.cmd('az kusto cluster wait --created '
'--name "{myCluster}" '
'--cluster-name "{myCluster}" '
'--resource-group "{rg}"',
checks=checks)

Expand Down Expand Up @@ -135,7 +137,7 @@ def step_cluster_update(test, rg, checks=None):
if checks is None:
checks = []
test.cmd('az kusto cluster update '
'--name "{myCluster}" '
'--cluster-name "{myCluster}" '
'--type "SystemAssigned" '
'--location "westus" '
'--enable-purge true '
Expand Down
20 changes: 12 additions & 8 deletions test/scenarios/kusto/output/ext_default_folder/src/kusto/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,20 @@ az kusto cluster show --name "kustoclusterrptest4" --resource-group "kustorptest

##### <a name="ExamplesClustersCreateOrUpdate#Create">Example</a>
```
az kusto cluster create --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true --sku name="Standard_L8s" \
capacity=2 tier="Standard" --resource-group "kustorptest"
az kusto cluster create --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true --name "Standard_L8s" --capacity 2 \
--tier "Standard" --resource-group "kustorptest"
```
##### <a name="ParametersClustersCreateOrUpdate#Create">Parameters</a>
|Option|Type|Description|Path (SDK)|Swagger name|
|------|----|-----------|----------|------------|
|**--resource-group-name**|string|The name of the resource group containing the Kusto cluster.|resource_group_name|resourceGroupName|
|**--cluster-name**|string|The name of the Kusto cluster.|cluster_name|clusterName|
|**--location**|string|The geo-location where the resource lives|location|location|
|**--sku**|object|The SKU of the cluster.|sku|sku|
|**--name**|choice|SKU name.|name|name|
|**--tier**|choice|SKU tier.|tier|tier|
|**--tags**|dictionary|Resource tags.|tags|tags|
|**--capacity**|integer|The number of instances of the cluster.|capacity|capacity|
|**--zones**|array|The availability zones of the cluster.|zones|zones|
|**--trusted-external-tenants**|array|The cluster's external tenants.|trusted_external_tenants|trustedExternalTenants|
|**--optimized-autoscale**|object|Optimized auto scale definition.|optimized_autoscale|optimizedAutoscale|
Expand All @@ -234,9 +236,9 @@ capacity=2 tier="Standard" --resource-group "kustorptest"

##### <a name="ExamplesClustersUpdate">Example</a>
```
az kusto cluster update --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" --enable-purge true \
--enable-streaming-ingest true --key-vault-properties key-name="keyName" key-vault-uri="https://dummy.keyvault.com" \
key-version="keyVersion" --resource-group "kustorptest"
az kusto cluster update --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-purge true --enable-streaming-ingest true --key-vault-properties key-name="keyName" \
key-vault-uri="https://dummy.keyvault.com" key-version="keyVersion" --resource-group "kustorptest"
```
##### <a name="ParametersClustersUpdate">Parameters</a>
|Option|Type|Description|Path (SDK)|Swagger name|
Expand All @@ -245,7 +247,9 @@ key-version="keyVersion" --resource-group "kustorptest"
|**--cluster-name**|string|The name of the Kusto cluster.|cluster_name|clusterName|
|**--tags**|dictionary|Resource tags.|tags|tags|
|**--location**|string|Resource location.|location|location|
|**--sku**|object|The SKU of the cluster.|sku|sku|
|**--name**|choice|SKU name.|name|name|
|**--capacity**|integer|The number of instances of the cluster.|capacity|capacity|
|**--tier**|choice|SKU tier.|tier|tier|
|**--trusted-external-tenants**|array|The cluster's external tenants.|trusted_external_tenants|trustedExternalTenants|
|**--optimized-autoscale**|object|Optimized auto scale definition.|optimized_autoscale|optimizedAutoscale|
|**--enable-disk-encryption**|boolean|A boolean value that indicates if the cluster's disks are encrypted.|enable_disk_encryption|enableDiskEncryption|
Expand Down
12 changes: 6 additions & 6 deletions test/scenarios/kusto/output/extflatten/src/kusto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ az extension add --name kusto
#### kusto cluster ####
##### Create #####
```
az kusto cluster create --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true \
--sku name="Standard_L8s" capacity=2 tier="Standard" --resource-group "kustorptest"
az kusto cluster create --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-double-encryption false --enable-purge true --enable-streaming-ingest true --name "Standard_L8s" \
--capacity 2 --tier "Standard" --resource-group "kustorptest"
az kusto cluster wait --created --name "{myCluster}" --resource-group "{rg}"
az kusto cluster wait --created --cluster-name "{myCluster}" --resource-group "{rg}"
```
##### Show #####
```
Expand All @@ -27,8 +27,8 @@ az kusto cluster list --resource-group "kustorptest"
```
##### Update #####
```
az kusto cluster update --name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" --enable-purge true \
--enable-streaming-ingest true \
az kusto cluster update --cluster-name "kustoclusterrptest4" --type "SystemAssigned" --location "westus" \
--enable-purge true --enable-streaming-ingest true \
--key-vault-properties key-name="keyName" key-vault-uri="https://dummy.keyvault.com" key-version="keyVersion" \
--resource-group "kustorptest"
```
Expand Down
Loading

0 comments on commit b13482e

Please sign in to comment.