Skip to content

Commit d4c38c3

Browse files
authored
Added validation for circuit bandwidth in New/Update collector policy cmdlet for ATC (#24571)
* Modified custom cmdlet * minor fix * Added custom new cmdlet * Added shouldprocess * Add UT * fix * Update * revert * revert * Add UT * Add UT * Address comment * Added UT * test * Testing * Testing * Tests * Tests
1 parent 542ab84 commit d4c38c3

File tree

6 files changed

+254
-13
lines changed

6 files changed

+254
-13
lines changed

src/NetworkFunction/NetworkFunction.Autorest/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ directive:
6363
- where:
6464
verb: Set
6565
hide: true
66+
- where:
67+
verb: New
68+
subject: ^CollectorPolicy(.*)
69+
hide: true
6670
```
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
2+
# ----------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
14+
# is regenerated.
15+
# ----------------------------------------------------------------------------------
16+
17+
<#
18+
.Synopsis
19+
Creates or updates a Collector Policy resource
20+
.Description
21+
Creates or updates a Collector Policy resource
22+
.Example
23+
New-AzNetworkFunctionCollectorPolicy -collectorpolicyname cp1 -azuretrafficcollectorname atc -resourcegroupname rg1 -location eastus | Format-List
24+
25+
.Outputs
26+
Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Models.Api20221101.ICollectorPolicy
27+
.Notes
28+
COMPLEX PARAMETER PROPERTIES
29+
30+
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
31+
32+
EMISSIONPOLICY <IEmissionPoliciesPropertiesFormat[]>: Emission policies.
33+
[EmissionDestination <IEmissionPolicyDestination[]>]: Emission policy destinations.
34+
[DestinationType <DestinationType?>]: Emission destination type.
35+
[EmissionType <EmissionType?>]: Emission format type.
36+
37+
INGESTIONPOLICYINGESTIONSOURCE <IIngestionSourcesPropertiesFormat[]>: Ingestion Sources.
38+
[ResourceId <String>]: Resource ID.
39+
[SourceType <SourceType?>]: Ingestion source type.
40+
.Link
41+
https://learn.microsoft.com/powershell/module/az.networkfunction/new-aznetworkfunctioncollectorpolicy
42+
#>
43+
function New-AzNetworkFunctionCollectorPolicy {
44+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Models.Api20221101.ICollectorPolicy])]
45+
[CmdletBinding(PositionalBinding=$false, SupportsShouldProcess)]
46+
param(
47+
[Parameter(Mandatory)]
48+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Path')]
49+
[System.String]
50+
# Azure Traffic Collector name
51+
${AzureTrafficCollectorName},
52+
53+
[Parameter(Mandatory)]
54+
[Alias('CollectorPolicyName')]
55+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Path')]
56+
[System.String]
57+
# Collector Policy Name
58+
${Name},
59+
60+
[Parameter(Mandatory)]
61+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Path')]
62+
[System.String]
63+
# The name of the resource group.
64+
${ResourceGroupName},
65+
66+
[Parameter()]
67+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Path')]
68+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
69+
[System.String]
70+
# Azure Subscription ID.
71+
${SubscriptionId},
72+
73+
[Parameter(Mandatory)]
74+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Body')]
75+
[System.String]
76+
# Resource location.
77+
${Location},
78+
79+
[Parameter()]
80+
[AllowEmptyCollection()]
81+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Body')]
82+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Models.Api20221101.IEmissionPoliciesPropertiesFormat[]]
83+
# Emission policies.
84+
# To construct, see NOTES section for EMISSIONPOLICY properties and create a hash table.
85+
${EmissionPolicy},
86+
87+
[Parameter()]
88+
[AllowEmptyCollection()]
89+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Body')]
90+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Models.Api20221101.IIngestionSourcesPropertiesFormat[]]
91+
# Ingestion Sources.
92+
# To construct, see NOTES section for INGESTIONPOLICYINGESTIONSOURCE properties and create a hash table.
93+
${IngestionPolicyIngestionSource},
94+
95+
[Parameter()]
96+
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Support.IngestionType])]
97+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Body')]
98+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Support.IngestionType]
99+
# The ingestion type.
100+
${IngestionPolicyIngestionType},
101+
102+
[Parameter()]
103+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Body')]
104+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Models.Api20221101.ITrackedResourceTags]))]
105+
[System.Collections.Hashtable]
106+
# Resource tags.
107+
${Tag},
108+
109+
[Parameter()]
110+
[Alias('AzureRMContext', 'AzureCredential')]
111+
[ValidateNotNull()]
112+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Azure')]
113+
[System.Management.Automation.PSObject]
114+
# The credentials, account, tenant, and subscription used for communication with Azure.
115+
${DefaultProfile},
116+
117+
[Parameter()]
118+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
119+
[System.Management.Automation.SwitchParameter]
120+
# Run the command as a job
121+
${AsJob},
122+
123+
[Parameter(DontShow)]
124+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
125+
[System.Management.Automation.SwitchParameter]
126+
# Wait for .NET debugger to attach
127+
${Break},
128+
129+
[Parameter(DontShow)]
130+
[ValidateNotNull()]
131+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
132+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Runtime.SendAsyncStep[]]
133+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
134+
${HttpPipelineAppend},
135+
136+
[Parameter(DontShow)]
137+
[ValidateNotNull()]
138+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
139+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Runtime.SendAsyncStep[]]
140+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
141+
${HttpPipelinePrepend},
142+
143+
[Parameter()]
144+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
145+
[System.Management.Automation.SwitchParameter]
146+
# Run the command asynchronously
147+
${NoWait},
148+
149+
[Parameter(DontShow)]
150+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
151+
[System.Uri]
152+
# The URI for the proxy server to use
153+
${Proxy},
154+
155+
[Parameter(DontShow)]
156+
[ValidateNotNull()]
157+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
158+
[System.Management.Automation.PSCredential]
159+
# Credentials for a proxy server to use for the remote call
160+
${ProxyCredential},
161+
162+
[Parameter(DontShow)]
163+
[Microsoft.Azure.PowerShell.Cmdlets.NetworkFunction.Category('Runtime')]
164+
[System.Management.Automation.SwitchParameter]
165+
# Use the default credentials for the proxy
166+
${ProxyUseDefaultCredentials}
167+
)
168+
169+
process {
170+
$rg = $PSBoundParameters.ResourceGroupName
171+
172+
# 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."
185+
}
186+
187+
Az.NetworkFunction.internal\New-AzNetworkFunctionCollectorPolicy @PSBoundParameters
188+
}
189+
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,26 @@ process {
173173
$null = $PSBoundParameters.Remove('WhatIf')
174174
$null = $PSBoundParameters.Remove('Confirm')
175175
$null = $PSBoundParameters.Remove('Location')
176+
$rg = $PSBoundParameters.ResourceGroupName
176177

177-
$cp = Get-AzNetworkFunctionCollectorPolicy @PSBoundParameters
178+
# 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+
}
178188

179-
# 2. PUT
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."
191+
}
192+
193+
$cp = Get-AzNetworkFunctionCollectorPolicy @PSBoundParameters
194+
195+
# 3. PUT
180196
$null = $PSBoundParameters.Remove('AzureTrafficCollectorName')
181197
$null = $PSBoundParameters.Remove('ResourceGroupName')
182198
$null = $PSBoundParameters.Remove('Name')

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,33 @@ if(($null -eq $TestName) -or ($TestName -contains 'New-AzNetworkFunctionCollecto
1515
}
1616

1717
Describe 'New-AzNetworkFunctionCollectorPolicy' {
18-
It 'CreateExpanded' -skip {
19-
{ throw [System.NotImplementedException] } | Should -Not -Throw
18+
It 'CreateExpanded' {
19+
{
20+
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Not -Throw
21+
}
2022
}
2123

22-
It 'Create' -skip {
23-
{ throw [System.NotImplementedException] } | Should -Not -Throw
24+
It 'CreateExpanded1' {
25+
{
26+
{ New-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."
27+
}
2428
}
2529

26-
It 'CreateViaIdentityExpanded' -skip {
27-
{ throw [System.NotImplementedException] } | Should -Not -Throw
30+
It 'Create' {
31+
{
32+
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Not -Throw
33+
}
2834
}
2935

30-
It 'CreateViaIdentity' -skip {
31-
{ throw [System.NotImplementedException] } | Should -Not -Throw
36+
It 'CreateViaIdentityExpanded' {
37+
{
38+
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Not -Throw
39+
}
40+
}
41+
42+
It 'CreateViaIdentity' {
43+
{
44+
{ New-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should -Not -Throw
45+
}
3246
}
3347
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ if(($null -eq $TestName) -or ($TestName -contains 'Update-AzNetworkFunctionColle
1515
}
1616

1717
Describe 'Update-AzNetworkFunctionCollectorPolicy' {
18-
It 'UpdateExpanded' -skip {
19-
{ throw [System.NotImplementedException] } | Should -Not -Throw
18+
It 'UpdateExpanded' {
19+
{
20+
{ Update-AzNetworkFunctionCollectorPolicy -collectorpolicyname $env.collectorPolicyName -azuretrafficcollectorname $env.azureTrafficCollectorName -resourcegroupname $env.resourceGroup -location $env.location -IngestionPolicyIngestionSource @{ResourceId = $env.ResourceId1G} -IngestionPolicyIngestionType $env.IngestionType } | Should Not Throw
21+
}
2022
}
21-
}
23+
24+
It 'UpdateExpanded1' {
25+
{
26+
{ 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."
27+
}
28+
}
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"collectorPolicyName": "cp1",
3+
"azureTrafficCollectorName": "UTPSatc",
4+
"resourceGroup": "DO_NOT_DELETE_ATC_PS_Tests",
5+
"location": "eastus",
6+
"SubscriptionId": "05f401ac-885f-4ba4-b2d6-7c5444596230",
7+
"ResourceId1G": "/subscriptions/05f401ac-885f-4ba4-b2d6-7c5444596230/resourceGroups/DO_NOT_DELETE_ATC_PS_Tests/providers/Microsoft.Network/expressRouteCircuits/DO_NOT_DELETE_ATC_PS_Test_Ckt",
8+
"ResourceIdLessThan1G": "/subscriptions/05f401ac-885f-4ba4-b2d6-7c5444596230/resourceGroups/DO_NOT_DELETE_ATC_PS_Tests/providers/Microsoft.Network/expressRouteCircuits/DO_NOT_DELETE_ATC_PS_Test_Ckt_1",
9+
"IngestionType": "IPFIX"
10+
}

0 commit comments

Comments
 (0)