-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[DdoS]Add DDoS custom policy cmdlets, LB integration, tests, and help #29300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
venkatasaimaram7
wants to merge
1
commit into
Azure:main
Choose a base branch
from
venkatasaimaram7:feature/ddos-custom-policy-powershell
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Network/Network.Test/ScenarioTests/DdosCustomPolicyTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| using Microsoft.Azure.Commands.Network.Test.ScenarioTests; | ||
| using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
| using Xunit; | ||
|
|
||
| namespace Commands.Network.Test.ScenarioTests | ||
| { | ||
| public class DdosCustomPolicyTests : NetworkTestRunner | ||
| { | ||
| public DdosCustomPolicyTests(Xunit.Abstractions.ITestOutputHelper output) | ||
| : base(output) | ||
| { | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| [Trait(Category.Owner, NrpTeamAlias.ddos)] | ||
| public void TestDdosCustomPolicyCrud() | ||
| { | ||
| TestRunner.RunTestScript(string.Format("Test-DdosCustomPolicyCRUD")); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| [Trait(Category.Owner, NrpTeamAlias.ddos)] | ||
| public void TestDdosCustomPolicyCrudWithTags() | ||
| { | ||
| TestRunner.RunTestScript(string.Format("Test-DdosCustomPolicyCRUDWithTags")); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| [Trait(Category.Owner, NrpTeamAlias.ddos)] | ||
| public void TestLoadBalancerFrontendWithDdosCustomPolicy() | ||
| { | ||
| TestRunner.RunTestScript(string.Format("Test-LoadBalancerFrontendWithDdosCustomPolicy")); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| [Trait(Category.Owner, NrpTeamAlias.ddos)] | ||
| public void TestAddLoadBalancerFrontendWithDdosCustomPolicy() | ||
| { | ||
| TestRunner.RunTestScript(string.Format("Test-AddLoadBalancerFrontendWithDdosCustomPolicy")); | ||
| } | ||
| } | ||
| } |
253 changes: 253 additions & 0 deletions
253
src/Network/Network.Test/ScenarioTests/DdosCustomPolicyTests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,253 @@ | ||
| # ---------------------------------------------------------------------------------- | ||
| # Copyright Microsoft Corporation | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ---------------------------------------------------------------------------------- | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| DDoS custom policy management operations | ||
| #> | ||
| function Test-DdosCustomPolicyCRUD | ||
| { | ||
| $rgLocation = Get-ProviderLocation ResourceManagement | ||
| $resourceTypeParent = "Microsoft.Network/DdosCustomPolicies" | ||
| $location = Get-ProviderLocation $resourceTypeParent | ||
|
|
||
| $rgName = Get-ResourceGroupName | ||
| $ddosCustomPolicyName = Get-ResourceName | ||
|
|
||
| try | ||
| { | ||
| # Create the resource group | ||
| New-AzResourceGroup -Name $rgName -Location $location -Tags @{ testtag = "ddosCustomPolicy tag" } | ||
|
|
||
| # Create the DDoS custom policy | ||
| $job = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $rgLocation -TrafficType Tcp -PacketsPerSecond 1000000 -AsJob | ||
| $job | Wait-Job | ||
| $ddosCustomPolicyNew = $job | Receive-Job | ||
|
|
||
| Assert-AreEqual $rgName $ddosCustomPolicyNew.ResourceGroupName | ||
| Assert-AreEqual $ddosCustomPolicyName $ddosCustomPolicyNew.Name | ||
| Assert-NotNull $ddosCustomPolicyNew.Location | ||
| Assert-NotNull $ddosCustomPolicyNew.Etag | ||
| Assert-NotNull $ddosCustomPolicyNew.ProvisioningState | ||
|
|
||
| # Get the DDoS custom policy | ||
| $ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName | ||
| Assert-AreEqual $rgName $ddosCustomPolicyGet.ResourceGroupName | ||
| Assert-AreEqual $ddosCustomPolicyName $ddosCustomPolicyGet.Name | ||
| Assert-NotNull $ddosCustomPolicyGet.Location | ||
| Assert-NotNull $ddosCustomPolicyGet.Etag | ||
|
|
||
| # Remove the DDoS custom policy | ||
| $ddosCustomPolicyDelete = Remove-AzDdosCustomPolicy -Name $ddosCustomPolicyName -ResourceGroupName $rgName -PassThru | ||
| Assert-AreEqual $true $ddosCustomPolicyDelete | ||
| } | ||
| finally | ||
| { | ||
| # Cleanup | ||
| Clean-ResourceGroup $rgName | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| DDoS custom policy creation with tags | ||
| #> | ||
| function Test-DdosCustomPolicyCRUDWithTags | ||
| { | ||
| $rgLocation = Get-ProviderLocation ResourceManagement | ||
| $resourceTypeParent = "Microsoft.Network/DdosCustomPolicies" | ||
| $location = Get-ProviderLocation $resourceTypeParent | ||
|
|
||
| $rgName = Get-ResourceGroupName | ||
| $ddosCustomPolicyName = Get-ResourceName | ||
| $tags = @{ Environment = "Test"; Project = "DdosCustomPolicy" } | ||
|
|
||
| try | ||
| { | ||
| # Create the resource group | ||
| New-AzResourceGroup -Name $rgName -Location $location -Tags @{ testtag = "ddosCustomPolicy tag" } | ||
|
|
||
| # Create the DDoS custom policy with tags | ||
| $ddosCustomPolicy = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $rgLocation -TrafficType Tcp -PacketsPerSecond 1000000 -Tag $tags | ||
|
|
||
| Assert-AreEqual $rgName $ddosCustomPolicy.ResourceGroupName | ||
| Assert-AreEqual $ddosCustomPolicyName $ddosCustomPolicy.Name | ||
| Assert-NotNull $ddosCustomPolicy.Tag | ||
| Assert-AreEqual "Test" $ddosCustomPolicy.Tag["Environment"] | ||
| Assert-AreEqual "DdosCustomPolicy" $ddosCustomPolicy.Tag["Project"] | ||
|
|
||
| # Get and verify tags | ||
| $ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName | ||
| Assert-AreEqual "Test" $ddosCustomPolicyGet.Tag["Environment"] | ||
|
|
||
| # Remove the DDoS custom policy | ||
| Remove-AzDdosCustomPolicy -Name $ddosCustomPolicyName -ResourceGroupName $rgName | ||
| } | ||
| finally | ||
| { | ||
| # Cleanup | ||
| Clean-ResourceGroup $rgName | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Test DDoS custom policy linkage with Load Balancer Frontend IP Config | ||
| #> | ||
| function Test-LoadBalancerFrontendWithDdosCustomPolicy | ||
| { | ||
| $resourceTypeParent = "Microsoft.Network/loadBalancers" | ||
| $location = Get-ProviderLocation $resourceTypeParent | ||
|
|
||
| $rgName = Get-ResourceGroupName | ||
| $lbName = Get-ResourceName | ||
| $pipName = Get-ResourceName | ||
| $frontendName = Get-ResourceName | ||
| $ddosCustomPolicyName = Get-ResourceName | ||
|
|
||
| try | ||
| { | ||
| # Create the resource group | ||
| New-AzResourceGroup -Name $rgName -Location $location | ||
|
|
||
| # Create DDoS custom policy | ||
| $ddosCustomPolicy = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $location -TrafficType Tcp -PacketsPerSecond 1000000 | ||
|
|
||
| # Create Public IP Address | ||
| $publicIp = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $pipName -Location $location -AllocationMethod Static | ||
|
|
||
| # Create frontend IP config with DDoS custom policy | ||
| $frontendIpConfig = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $publicIp -DdosCustomPolicyId $ddosCustomPolicy.Id | ||
|
|
||
| Assert-NotNull $frontendIpConfig | ||
| Assert-AreEqual $frontendName $frontendIpConfig.Name | ||
|
|
||
| # Create Load Balancer backend pool | ||
| $backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "BackendPool" | ||
|
|
||
| # Create Load Balancer with frontend config | ||
| $loadBalancer = New-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Location $location ` | ||
| -FrontendIpConfiguration $frontendIpConfig -BackendAddressPool $backendPool | ||
|
|
||
| Assert-NotNull $loadBalancer | ||
| Assert-AreEqual $lbName $loadBalancer.Name | ||
|
|
||
| # Verify frontend has DDoS custom policy | ||
| $frontendFromLb = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancer -Name $frontendName | ||
| Assert-NotNull $frontendFromLb | ||
| Assert-NotNull $frontendFromLb.DdosSettings | ||
| Assert-NotNull $frontendFromLb.DdosSettings.DdosCustomPolicy | ||
| Assert-AreEqual $ddosCustomPolicy.Id $frontendFromLb.DdosSettings.DdosCustomPolicy.Id | ||
|
|
||
| $ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName | ||
| Assert-NotNull $ddosCustomPolicyGet.FrontEndIPConfiguration | ||
| Assert-AreEqual 1 $ddosCustomPolicyGet.FrontEndIPConfiguration.Count | ||
| Assert-AreEqual $frontendFromLb.Id $ddosCustomPolicyGet.FrontEndIPConfiguration[0].Id | ||
|
|
||
| # Test Set-AzLoadBalancerFrontendIpConfig with new DDoS policy | ||
| $ddosCustomPolicy2Name = Get-ResourceName | ||
| $ddosCustomPolicy2 = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicy2Name -Location $location -TrafficType Tcp -PacketsPerSecond 1000000 | ||
|
|
||
| $loadBalancer = Set-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancer -Name $frontendName ` | ||
| -PublicIpAddress $publicIp -DdosCustomPolicyId $ddosCustomPolicy2.Id | ||
|
|
||
| Set-AzLoadBalancer -LoadBalancer $loadBalancer | Out-Null | ||
| $loadBalancerUpdated = Get-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName | ||
| $frontendIpConfig2 = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancerUpdated -Name $frontendName | ||
|
|
||
| Assert-NotNull $frontendIpConfig2.DdosSettings | ||
| Assert-AreEqual $ddosCustomPolicy2.Id $frontendIpConfig2.DdosSettings.DdosCustomPolicy.Id | ||
|
|
||
| # Cleanup | ||
| Remove-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Force | ||
| Remove-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName | ||
| Remove-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicy2Name | ||
| } | ||
| finally | ||
| { | ||
| # Cleanup | ||
| Clean-ResourceGroup $rgName | ||
| } | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Test Add-AzLoadBalancerFrontendIpConfig with DDoS custom policy | ||
| #> | ||
| function Test-AddLoadBalancerFrontendWithDdosCustomPolicy | ||
| { | ||
| $resourceTypeParent = "Microsoft.Network/loadBalancers" | ||
| $location = Get-ProviderLocation $resourceTypeParent | ||
|
|
||
| $rgName = Get-ResourceGroupName | ||
| $lbName = Get-ResourceName | ||
| $pipName1 = Get-ResourceName | ||
| $pipName2 = Get-ResourceName | ||
| $frontendName1 = Get-ResourceName | ||
| $frontendName2 = Get-ResourceName | ||
| $ddosCustomPolicyName = Get-ResourceName | ||
|
|
||
| try | ||
| { | ||
| # Create the resource group | ||
| New-AzResourceGroup -Name $rgName -Location $location | ||
|
|
||
| # Create DDoS custom policy | ||
| $ddosCustomPolicy = New-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName -Location $location -TrafficType Tcp -PacketsPerSecond 1000000 | ||
|
|
||
| # Create first Public IP Address | ||
| $publicIp1 = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $pipName1 -Location $location -AllocationMethod Static | ||
|
|
||
| # Create first frontend IP config | ||
| $frontendIpConfig1 = New-AzLoadBalancerFrontendIpConfig -Name $frontendName1 -PublicIpAddress $publicIp1 | ||
|
|
||
| # Create Load Balancer backend pool | ||
| $backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "BackendPool" | ||
|
|
||
| # Create Load Balancer with first frontend config | ||
| $loadBalancer = New-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Location $location ` | ||
| -FrontendIpConfiguration $frontendIpConfig1 -BackendAddressPool $backendPool | ||
|
|
||
| # Create second Public IP Address | ||
| $publicIp2 = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $pipName2 -Location $location -AllocationMethod Static | ||
|
|
||
| # Add second frontend with DDoS custom policy | ||
| Add-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancer -Name $frontendName2 ` | ||
| -PublicIpAddress $publicIp2 -DdosCustomPolicyId $ddosCustomPolicy.Id | ||
|
|
||
| $loadBalancer | Set-AzLoadBalancer | ||
|
|
||
| # Verify the LoadBalancer now has two frontends | ||
| $loadBalancerUpdated = Get-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName | ||
| Assert-AreEqual 2 $loadBalancerUpdated.FrontendIpConfigurations.Count | ||
|
|
||
| # Verify second frontend has DDoS custom policy | ||
| $frontendFromLb = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $loadBalancerUpdated -Name $frontendName2 | ||
| Assert-NotNull $frontendFromLb.DdosSettings | ||
| Assert-AreEqual $ddosCustomPolicy.Id $frontendFromLb.DdosSettings.DdosCustomPolicy.Id | ||
|
|
||
| $ddosCustomPolicyGet = Get-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName | ||
| Assert-NotNull $ddosCustomPolicyGet.FrontEndIPConfiguration | ||
| Assert-AreEqual 1 $ddosCustomPolicyGet.FrontEndIPConfiguration.Count | ||
| Assert-AreEqual $frontendFromLb.Id $ddosCustomPolicyGet.FrontEndIPConfiguration[0].Id | ||
|
|
||
| # Cleanup | ||
| Remove-AzLoadBalancer -ResourceGroupName $rgName -Name $lbName -Force | ||
| Remove-AzDdosCustomPolicy -ResourceGroupName $rgName -Name $ddosCustomPolicyName | ||
| } | ||
| finally | ||
| { | ||
| # Cleanup | ||
| Clean-ResourceGroup $rgName | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did the casing change here? Is the auto-generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GET response returns a collection, so the wire mapping needs to be plural: frontendIpConfigurations.