Skip to content

Commit

Permalink
Adding new property to Virtual Network FlowTimeoutInMinutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Satya-anshu committed Mar 31, 2021
1 parent 589d177 commit d34a5ab
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Network/Network.Test/Network.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.4.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="3.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Insights" Version="0.16.0-preview" />
Expand Down
8 changes: 8 additions & 0 deletions src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,13 @@ public void TestVirtualNetworkSubnetServiceEndpointPolicies()
{
TestRunner.RunTestScript("Test-VirtualNetworkSubnetServiceEndpointPolicies");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.sdnnrp)]
public void TestVirtualNetworkCRUDFlowTimeout()
{
TestRunner.RunTestScript("Test-VirtualNetworkCRUD-FlowTimeout");
}
}
}
53 changes: 53 additions & 0 deletions src/Network/Network.Test/ScenarioTests/VirtualNetworkTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,56 @@ function Test-VirtualNetworkSubnetServiceEndpointPolicies
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests creating new virtual network with flow timeout.
#>
function Test-VirtualNetworkCRUD-FlowTimeout
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create virtual network
$actual = New-AzVirtualNetwork -ResourceGroupName $rgname -name $rname -location $location -FlowTimeoutInMinutes 15 -AddressPrefix 10.0.0.0/16
$expected = Get-AzVirtualNetwork -ResourceGroupName $rgname -name $rname
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual $expected.Location $actual.Location
Assert-NotNull $expected.ResourceGuid
Assert-AreEqual "Succeeded" $expected.ProvisioningState
Assert-AreEqual 15 $expected.FlowTimeoutInMinutes

# Set virtual network
$actual.FlowTimeoutInMinutes = 30
$actual = Set-AzVirtualNetwork -VirtualNetwork $actual
$expected = Get-AzVirtualNetwork -ResourceGroupName $rgname -name $rname
Assert-AreEqual 30 $expected.FlowTimeoutInMinutes

# delete
$job = Remove-AzVirtualNetwork -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force -AsJob
$job | Wait-Job
$delete = $job | Receive-Job
Assert-AreEqual true $delete

$list = Get-AzVirtualNetwork -ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual 0 @($list).Count

# test error handling
Assert-ThrowsContains { Set-AzVirtualNetwork -VirtualNetwork $actual } "not found";
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
8 changes: 8 additions & 0 deletions src/Network/Network/Models/PSVirtualNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class PSVirtualNetwork : PSTopLevelResource, IResourceReference, IVirtual

public PSDhcpOptions DhcpOptions { get; set; }

public int? FlowTimeoutInMinutes { get; set; }

public List<PSSubnet> Subnets { get; set; }

public PSVirtualNetworkBgpCommunities BgpCommunities { get; set; }
Expand Down Expand Up @@ -54,6 +56,12 @@ public string DhcpOptionsText
get { return JsonConvert.SerializeObject(DhcpOptions, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string FlowTimeoutInMinutesText
{
get { return JsonConvert.SerializeObject(FlowTimeoutInMinutes, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string SubnetsText
{
Expand Down
4 changes: 2 additions & 2 deletions src/Network/Network/Network.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>Network</PsModuleName>
Expand All @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.2.2" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.4.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="323.1255.27827" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Network/Network/Network.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
<Label>DhcpOptions</Label>
<PropertyName>DhcpOptionsText</PropertyName>
</ListItem>
<ListItem>
<Label>FlowTimeoutInMinutes</Label>
<PropertyName>FlowTimeoutInMinutesText</PropertyName>
</ListItem>
<ListItem>
<Label>Subnets</Label>
<PropertyName>SubnetsText</PropertyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public class NewAzureVirtualNetworkCommand : VirtualNetworkBaseCmdlet
HelpMessage = "The list of Dns Servers")]
public string[] DnsServer { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "FlowTimeoutInMinutes")]
public int? FlowTimeoutInMinutes { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
Expand Down Expand Up @@ -140,6 +146,11 @@ private PSVirtualNetwork CreateVirtualNetwork()
{
vnet.DhcpOptions = new PSDhcpOptions {DnsServers = DnsServer?.ToList()};
}

if (this.FlowTimeoutInMinutes > 0)
{
vnet.FlowTimeoutInMinutes = this.FlowTimeoutInMinutes;
}

vnet.Subnets = this.Subnet?.ToList();
vnet.EnableDdosProtection = EnableDdosProtection;
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit d34a5ab

Please sign in to comment.