Skip to content

Commit c1eb249

Browse files
author
Maddie Clayton
authored
Merge pull request #7193 from neaggarwMS/Vtap
Add cmdlets for VirtualNetworkTap feature added in Networking
2 parents 7839f53 + 0b0d684 commit c1eb249

34 files changed

+9228
-23
lines changed

src/ResourceManager/Network/Commands.Network.Test/Commands.Network.Test.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Redis.3.1.1-preview\lib\net45\Microsoft.Azure.Management.Redis.dll</HintPath>
6363
<Private>True</Private>
6464
</Reference>
65+
<Reference Include="System.Runtime" />
6566
</ItemGroup>
6667
<ItemGroup>
6768
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -89,6 +90,7 @@
8990
<Compile Include="ScenarioTests\Generated\RouteTableTestsGenerated.cs" />
9091
<Compile Include="ScenarioTests\TestDnsAvailabilityTest.cs" />
9192
<Compile Include="ScenarioTests\UsageTests.cs" />
93+
<Compile Include="ScenarioTests\VirtualNetworkTapTests.cs" />
9294
<Compile Include="ScenarioTests\VirtualNetworkTests.cs" />
9395
<Compile Include="ScenarioTests\PublicIpAddressTests.cs" />
9496
<Compile Include="ScenarioTests\VirtualNetworkGatewayTests.cs" />
@@ -186,6 +188,9 @@
186188
<None Include="ScenarioTests\UsageTests.ps1">
187189
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
188190
</None>
191+
<None Include="ScenarioTests\VirtualNetworkTapTests.ps1">
192+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
193+
</None>
189194
<None Include="ScenarioTests\VirtualNetworkTests.ps1">
190195
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
191196
</None>
@@ -352,6 +357,9 @@
352357
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.NetworkCloudExceptionTests\TestNotFound.json">
353358
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
354359
</None>
360+
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.NetworkInterfaceTests\TestNetworkInterfaceTapConfigurationCRUD.json">
361+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
362+
</None>
355363
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.NetworkSecurityGroupTests\TestNetworkSecurityGroupMultiValuedRules.json">
356364
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
357365
</None>
@@ -646,6 +654,9 @@
646654
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests\VirtualNetworkGatewayVpnCustomIpsecPolicySetTest.json">
647655
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
648656
</None>
657+
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTapTests\TestVirtualNetworkTapCRUDUsingIpConfig.json">
658+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
659+
</None>
649660
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestResourceNavigationLinksOnSubnetCRUD.json">
650661
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
651662
</None>

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/NetworkInterfaceTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,13 @@ public void TestNetworkInterfaceWithAcceleratedNetworking()
116116
{
117117
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-NetworkInterfaceWithAcceleratedNetworking");
118118
}
119+
120+
[Fact]
121+
[Trait(Category.AcceptanceType, Category.CheckIn)]
122+
[Trait(Category.Owner, Category.sdnnrp)]
123+
public void TestNetworkInterfaceTapConfigurationCRUD()
124+
{
125+
NetworkResourcesController.NewInstance.RunPsTest(_logger, string.Format("Test-NetworkInterfaceTapConfigurationCRUD"));
126+
}
119127
}
120128
}

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/NetworkInterfaceTests.ps1

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,98 @@ function Test-NetworkInterfaceWithAcceleratedNetworking
887887
Clean-ResourceGroup $rgname
888888
}
889889
}
890+
891+
<#
892+
.SYNOPSIS
893+
Test creating new NetworkInterfaceTapConfiguration using minimal set of parameters
894+
#>
895+
function Test-NetworkInterfaceTapConfigurationCRUD
896+
{
897+
# Setup
898+
# Setup
899+
$rgname = Get-ResourceGroupName
900+
$vnetName = Get-ResourceName
901+
$subnetName = Get-ResourceName
902+
$publicIpName = Get-ResourceName
903+
$nicName = Get-ResourceName
904+
$domainNameLabel = Get-ResourceName
905+
$rglocation = Get-ProviderLocation ResourceManagement
906+
$resourceTypeParent = "Microsoft.Network/networkInterfaces"
907+
$location = Get-ProviderLocation $resourceTypeParent
908+
$rname = Get-ResourceName
909+
$vtapName = Get-ResourceName
910+
$vtapName2 = Get-ResourceName
911+
$sourceIpConfigName = Get-ResourceName
912+
$sourceNicName = Get-ResourceName
913+
914+
try
915+
{
916+
# Create the resource group
917+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
918+
919+
# Create the Virtual Network
920+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
921+
$vnet = New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
922+
923+
# Create the publicip
924+
$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
925+
926+
# Create NetworkInterface
927+
$job = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgname -Location $location -Subnet $vnet.Subnets[0] -PublicIpAddress $publicip -AsJob
928+
$job | Wait-Job
929+
$expectedNic = Get-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgname
930+
931+
# Create required dependencies (Vtap)
932+
$DestinationEndpoint = $expectedNic.IpConfigurations[0]
933+
$actualVtap = New-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $vtapName -Location $location -DestinationNetworkInterfaceIPConfiguration $DestinationEndpoint -Force
934+
$vVirtualNetworkTap = Get-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $vtapName;
935+
936+
# Create source Nic which is getting tapped
937+
$sourceIpConfig = New-AzureRmNetworkInterfaceIpConfig -Name $sourceIpConfigName -Subnet $vnet.Subnets[0]
938+
$sourceNic = New-AzureRmNetworkInterface -Name $sourceNicName -ResourceGroupName $rgname -Location $location -IpConfiguration $sourceIpConfig -Tag @{ testtag = "testval" }
939+
940+
# Add tap configuration
941+
Add-AzureRmNetworkInterfaceTapConfig -NetworkInterface $sourceNic -VirtualNetworkTap $vVirtualNetworkTap -Name $rname
942+
943+
#get tap configuration
944+
$tapConfig = Get-AzureRmNetworkInterfaceTapConfig -ResourceGroupName $rgname -NetworkInterfaceName $sourceNicName -Name $rname
945+
Assert-NotNull $tapConfig
946+
Assert-AreEqual $tapConfig.ResourceGroupName $rgname
947+
Assert-AreEqual $tapConfig.NetworkInterfaceName $sourceNicName
948+
Assert-AreEqual $tapConfig.Name $rname
949+
950+
# get nic and check back reference
951+
$sourceNic = Get-AzureRmNetworkInterface -Name $sourceNicName -ResourceGroupName $rgname
952+
Assert-NotNull $sourceNic.TapConfigurations
953+
Assert-NotNull $sourceNic.TapConfigurations[0]
954+
Assert-AreEqual $sourceNic.TapConfigurations[0].Id $tapConfig.Id
955+
956+
# get vtap and check back reference
957+
$vVirtualNetworkTap = Get-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $vtapName;
958+
Assert-NotNull $vVirtualNetworkTap.NetworkInterfaceTapConfigurations
959+
Assert-NotNull $vVirtualNetworkTap.NetworkInterfaceTapConfigurations[0]
960+
Assert-AreEqual $vVirtualNetworkTap.NetworkInterfaceTapConfigurations[0].Id $tapConfig.Id
961+
962+
963+
# Remove NetworkInterfaceTapConfiguration
964+
$removeNetworkInterfaceTapConfiguration = Remove-AzureRmNetworkInterfaceTapConfig -ResourceGroupName $rgname -NetworkInterfaceName $sourceNicName -Name $rname -PassThru -Force;
965+
Assert-AreEqual $true $removeNetworkInterfaceTapConfiguration;
966+
967+
$sourceNic = Get-AzureRmNetworkInterface -Name $sourceNicName -ResourceGroupName $rgname
968+
Assert-NotNull $sourceNic.TapConfigurations
969+
Assert-Null $sourceNic.TapConfigurations[0]
970+
971+
# get vtap and check back reference
972+
$vVirtualNetworkTap = Get-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $vtapName;
973+
Assert-NotNull $vVirtualNetworkTap.NetworkInterfaceTapConfigurations
974+
Assert-Null $vVirtualNetworkTap.NetworkInterfaceTapConfigurations[0]
975+
976+
# Get NetworkInterfaceTapConfiguration should fail
977+
Assert-ThrowsContains { Get-AzureRmNetworkInterfaceTapConfig -ResourceGroupName $rgname -NetworkInterfaceName $sourceNicName -Name $rname } "not found";
978+
}
979+
finally
980+
{
981+
# Cleanup
982+
Clean-ResourceGroup $rgname;
983+
}
984+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// <auto-generated>
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
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+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
//
17+
// Warning: This code was generated by a tool.
18+
//
19+
// Changes to this file may cause incorrect behavior and will be lost if the
20+
// code is regenerated.
21+
//
22+
// For documentation on code generator please visit
23+
// https://aka.ms/nrp-code-generation
24+
// Please contact [email protected] if you need to make changes to this file.
25+
// </auto-generated>
26+
27+
using System;
28+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
29+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
30+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
31+
using Xunit;
32+
using Xunit.Abstractions;
33+
34+
namespace Commands.Network.Test.ScenarioTests
35+
{
36+
public class VirtualNetworkTapTests : RMTestBase
37+
{
38+
public XunitTracingInterceptor _logger;
39+
40+
public VirtualNetworkTapTests(Xunit.Abstractions.ITestOutputHelper output)
41+
{
42+
_logger = new XunitTracingInterceptor(output);
43+
XunitTracingInterceptor.AddToContext(_logger);
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
[Trait(Category.Owner, Category.wanrpdev)]
49+
public void TestVirtualNetworkTapCRUDUsingIpConfig()
50+
{
51+
NetworkResourcesController.NewInstance.RunPsTest(_logger, string.Format("Test-VirtualNetworkTapCRUDUsingIpConfig"));
52+
}
53+
}
54+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
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+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests VirtualNetworkTap using ipendpoints
18+
#>
19+
function Test-VirtualNetworkTapCRUDUsingIpConfig
20+
{
21+
#added temporarily
22+
# Register-AzureRmResourceProvider -ProviderNamespace "Microsoft.Network"
23+
24+
# Setup
25+
$rgname = Get-ResourceGroupName
26+
$vnetName = Get-ResourceName
27+
$subnetName = Get-ResourceName
28+
$publicIpName = Get-ResourceName
29+
$nicName = Get-ResourceName
30+
$domainNameLabel = Get-ResourceName
31+
$rglocation = Get-ProviderLocation ResourceManagement
32+
$resourceTypeParent = "Microsoft.Network/networkInterfaces"
33+
$location = Get-ProviderLocation $resourceTypeParent
34+
$rname = Get-ResourceName
35+
36+
try
37+
{
38+
# Create the resource group
39+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
40+
41+
# Create the Virtual Network
42+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24
43+
$vnet = New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
44+
45+
# Create the publicip
46+
$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
47+
48+
# Create NetworkInterface
49+
$job = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgname -Location $location -Subnet $vnet.Subnets[0] -PublicIpAddress $publicip -AsJob
50+
$job | Wait-Job
51+
$expectedNic = Get-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgname
52+
53+
# Create required dependencies
54+
$DestinationEndpoint = $expectedNic.IpConfigurations[0]
55+
$actualVtap = New-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $rname -Location $location -DestinationNetworkInterfaceIPConfiguration $DestinationEndpoint
56+
57+
$vVirtualNetworkTap = Get-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $rname;
58+
Assert-NotNull $vVirtualNetworkTap;
59+
Assert-AreEqual $vVirtualNetworkTap.ResourceGroupName $actualVtap.ResourceGroupName;
60+
Assert-AreEqual $vVirtualNetworkTap.Name $rname;
61+
Assert-AreEqual $vVirtualNetworkTap.DestinationNetworkInterfaceIPConfiguration.Id $DestinationEndpoint.Id
62+
63+
#update the Vtap resource
64+
$vVirtualNetworkTap.DestinationPort = 8888;
65+
Set-AzureRmVirtualNetworkTap -VirtualNetworkTap $vVirtualNetworkTap
66+
67+
$vVirtualNetworkTap = Get-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $rname;
68+
Assert-NotNull $vVirtualNetworkTap;
69+
Assert-AreEqual $vVirtualNetworkTap.ResourceGroupName $actualVtap.ResourceGroupName;
70+
Assert-AreEqual $vVirtualNetworkTap.Name $rname;
71+
Assert-AreEqual $vVirtualNetworkTap.DestinationNetworkInterfaceIPConfiguration.Id $DestinationEndpoint.Id
72+
Assert-AreEqual $vVirtualNetworkTap.DestinationPort 8888
73+
74+
# Remove VirtualNetworkTap
75+
$removeVirtualNetworkTap = Remove-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $rname -PassThru -Force;
76+
Assert-AreEqual $true $removeVirtualNetworkTap;
77+
78+
# Get VirtualNetworkTap should fail
79+
Assert-ThrowsLike { Get-AzureRmVirtualNetworkTap -ResourceGroupName $rgname -Name $rname } "*${rname}*not found*";
80+
}
81+
finally
82+
{
83+
# Cleanup
84+
Clean-ResourceGroup $rgname
85+
}
86+
}
87+

0 commit comments

Comments
 (0)