Skip to content

Commit a3efe99

Browse files
authored
Change parsing logic in ATC custom cmdlet (#24828)
* Change parsing logic in ATC custom cmdlet * Add if check * add if check * Minor change * Add UT
1 parent 5fd5f8a commit a3efe99

File tree

4 files changed

+61
-29
lines changed

4 files changed

+61
-29
lines changed

src/NetworkFunction/NetworkFunction.Autorest/custom/New-AzNetworkFunctionCollectorPolicy.ps1

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,33 @@ param(
167167
)
168168

169169
process {
170-
$rg = $PSBoundParameters.ResourceGroupName
171-
170+
$hasIngestionPolicyIngestionSource = $PSBoundParameters.Remove('IngestionPolicyIngestionSource')
172171
# Ensure exr circuit bandwidth 1G or more
173-
$cktname = $IngestionPolicyIngestionSource.ResourceId | Where {$IngestionPolicyIngestionSource.ResourceId -match "/*subscriptions/(?<subid>.*)/resourceGroups/(?<rgname>.*)/providers/Microsoft.Network/expressRouteCircuits/(?<circuitname>.*)"} | Foreach {$Matches['circuitname']}
174-
Import-Module Az.Network -Force
175-
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $rg
176-
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
177-
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps
178-
179-
if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
180-
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
181-
}
182-
183-
if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
184-
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
172+
if ($hasIngestionPolicyIngestionSource) {
173+
Import-Module Az.Network -Force
174+
$ResourceIdSplit = $IngestionPolicyIngestionSource.ResourceId.Split(' ')
175+
foreach ($ResourceId in $ResourceIdSplit)
176+
{
177+
$Splits = $ResourceId -split "/"
178+
$cktsub = $Splits[2]
179+
$cktrg = $Splits[4]
180+
$cktname = $Splits[8]
181+
Set-AzContext $cktsub -ErrorVariable notPresent -ErrorAction SilentlyContinue
182+
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $cktrg
183+
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
184+
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps
185+
186+
if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
187+
throw "CollectorPolicy can not be created because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
188+
}
189+
190+
if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
191+
throw "CollectorPolicy can not be created because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
192+
}
193+
}
185194
}
186-
195+
Set-AzContext $SubscriptionId -ErrorVariable notPresent -ErrorAction SilentlyContinue
196+
$PSBoundParameters.Add('IngestionPolicyIngestionSource', $IngestionPolicyIngestionSource)
187197
Az.NetworkFunction.internal\New-AzNetworkFunctionCollectorPolicy @PSBoundParameters
188198
}
189199
}

src/NetworkFunction/NetworkFunction.Autorest/custom/Update-AzNetworkFunctionCollectorPolicy.ps1

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,33 @@ process {
173173
$null = $PSBoundParameters.Remove('WhatIf')
174174
$null = $PSBoundParameters.Remove('Confirm')
175175
$null = $PSBoundParameters.Remove('Location')
176-
$rg = $PSBoundParameters.ResourceGroupName
177176

178177
# 2. Ensure exr circuit bandwidth 1G or more
179-
$cktname = $IngestionPolicyIngestionSource.ResourceId | Where {$IngestionPolicyIngestionSource.ResourceId -match "/*subscriptions/(?<subid>.*)/resourceGroups/(?<rgname>.*)/providers/Microsoft.Network/expressRouteCircuits/(?<circuitname>.*)"} | Foreach {$Matches['circuitname']}
180-
Import-Module Az.Network -Force
181-
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $rg
182-
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
183-
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps
184-
185-
if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
186-
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
187-
}
188-
189-
if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
190-
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
178+
if ($hasIngestionPolicyIngestionSource) {
179+
Import-Module Az.Network -Force
180+
# Ensure exr circuit bandwidth 1G or more
181+
$ResourceIdSplit = $IngestionPolicyIngestionSource.ResourceId.Split(' ')
182+
foreach ($ResourceId in $ResourceIdSplit)
183+
{
184+
$Splits = $ResourceId -split "/"
185+
$cktsub = $Splits[2]
186+
$cktrg = $Splits[4]
187+
$cktname = $Splits[8]
188+
Set-AzContext $cktsub -ErrorVariable notPresent -ErrorAction SilentlyContinue
189+
$exrCircuit = Get-AzExpressRouteCircuit -Name $cktname -ResourceGroupName $cktrg
190+
$bandwidthInGbps = $exrCircuit.BandwidthInGbps
191+
$bandwidthInMbps = $exrCircuit.ServiceProviderProperties.BandwidthInMbps
192+
193+
if ($bandwidthInGbps -and ($bandwidthInGbps -lt 1)) {
194+
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
195+
}
196+
197+
if ($bandwidthInMbps -and ($bandwidthInMbps -lt 1000)) {
198+
throw "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
199+
}
200+
}
191201
}
192-
202+
Set-AzContext $SubscriptionId -ErrorVariable notPresent -ErrorAction SilentlyContinue
193203
$cp = Get-AzNetworkFunctionCollectorPolicy @PSBoundParameters
194204

195205
# 3. PUT

src/NetworkFunction/NetworkFunction.Autorest/test/New-AzNetworkFunctionCollectorPolicy.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Describe 'New-AzNetworkFunctionCollectorPolicy' {
2727
}
2828
}
2929

30+
It 'CreateExpanded2' {
31+
{
32+
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceIdLessThan1G}, @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Throw -ExpectedMessage "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
33+
}
34+
}
35+
3036
It 'Create' {
3137
{
3238
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Not -Throw

src/NetworkFunction/NetworkFunction.Autorest/test/Update-AzNetworkFunctionCollectorPolicy.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ Describe 'Update-AzNetworkFunctionCollectorPolicy' {
2626
{ Update-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceIdLessThan1G} -IngestionPolicyIngestionType $env.IngestionType } | Should Throw -ExpectedMessage "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
2727
}
2828
}
29+
30+
It 'UpdateExpanded2' {
31+
{
32+
{ Update-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceIdLessThan1G}, @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should Throw -ExpectedMessage "CollectorPolicy can not be updated because circuit has bandwidth less than 1G. Circuit size with a bandwidth of 1G or more is supported."
33+
}
34+
}
2935
}

0 commit comments

Comments
 (0)