Skip to content
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

Add HubIpConfiguration and HubBgpConnections #12565

Merged
merged 18 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Network/Network.Test/ScenarioTests/HubBgpConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Commands.Network.Test.ScenarioTests
{
public class HubBgpConnectionTests : NetworkTestRunner
{
public HubBgpConnectionTests(Xunit.Abstractions.ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestHubBgpConnectionCRUDMinimalParameters()
{
TestRunner.RunTestScript(string.Format("Test-HubBgpConnectionCRUD"));
}
}
}
80 changes: 80 additions & 0 deletions src/Network/Network.Test/ScenarioTests/HubBgpConnectionTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

function Check-CmdletReturnType
{
param($cmdletName, $cmdletReturn)

$cmdletData = Get-Command $cmdletName
Assert-NotNull $cmdletData
[array]$cmdletReturnTypes = $cmdletData.OutputType.Name | Foreach-Object { return ($_ -replace "Microsoft.Azure.Commands.Network.Models.","") }
[array]$cmdletReturnTypes = $cmdletReturnTypes | Foreach-Object { return ($_ -replace "System.","") }
$realReturnType = $cmdletReturn.GetType().Name -replace "Microsoft.Azure.Commands.Network.Models.",""
return $cmdletReturnTypes -contains $realReturnType
}

<#
.SYNOPSIS
Test creating new HubBgpConnection
#>
function Test-HubBgpConnectionCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement "centraluseuap"
$virtualRouterName = Get-ResourceName
$virtualWanName = Get-ResourceName
$subnetName = Get-ResourceName
$peerName = Get-ResourceName

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

# Create virtual network and subnet
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $rglocation -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$hostedSubnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet

# Create virtual router
$virtualRouter = New-AzVirtualRouter -ResourceGroupName $rgname -location $rglocation -Name $virtualRouterName -HostedSubnet $hostedsubnet.Id
$virtualRouter = Get-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName

# Create hub bgp connection
$actualBgpConnection = Add-AzVirtualRouterPeer -ResourceGroupName $rgname -VirtualRouterName $virtualRouterName -PeerName $peerName -PeerIp "192.168.1.5" -PeerAsn "20000"
$expectedBgpConnection = Get-AzVirtualRouterPeer -ResourceGroupName $rgname -VirtualRouterName $virtualRouterName -PeerName $peerName
Assert-AreEqual $expectedBgpConnection.Peerings.PeerName $actualBgpConnection.PeerName
Assert-AreEqual $expectedBgpConnection.PeerIp "192.168.1.5"
Assert-AreEqual $expectedBgpConnection.PeerAsn "20000"

#delete hub bgp connection
$deleteBgpConnection = Remove-AzVirtualRouterPeer -ResourceGroupName $rgname -VirtualRouterName $virtualRouterName -PeerName $peerName -Force
Assert-AreEqual 0 @($deleteBgpConnection.Peerings).Count

# Delete virtual router
$deleteVirtualRouter = Remove-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName -PassThru -Force
Assert-AreEqual true $deleteVirtualRouter

$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VirtualRouterTests(Xunit.Abstractions.ITestOutputHelper output)
{
}

[Fact(Skip = "Fails with Internal Server Error")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestVirtualRouterCRUDMinimalParameters()
Expand Down
69 changes: 23 additions & 46 deletions src/Network/Network.Test/ScenarioTests/VirtualRouterTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,69 +32,46 @@ function Test-VirtualRouterCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$domainNameLabel = Get-ResourceName
$vnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement "southcentralus"
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
$location = Get-ProviderLocation $resourceTypeParent "southcentralus"
$virtualRouterName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement "centraluseuap"
$virtualRouterName = Get-ResourceName
$subnetName = Get-ResourceName

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



# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $rglocation -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

# Create the publicip
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel

# Create & Get virtualnetworkgateway
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet

$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType ExpressRoute -GatewaySku HighPerformance -VpnType RouteBased -VpnGatewayGeneration None -Force
$expected = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $expected.Name $actual.Name
Assert-AreEqual "ExpressRoute" $expected.GatewayType
Assert-AreEqual "None" $expected.VpnGatewayGeneration

# Create Virtual Router
$actualvr = New-AzVirtualRouter -ResourceGroupName $rgname -location $location -Name $virtualRouterName -HostedGateway $expected
$expectedvr = Get-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName
Assert-AreEqual $expectedvr.ResourceGroupName $actualvr.ResourceGroupName
$hostedSubnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet

# Create Virtual Router
$actualvr = New-AzVirtualRouter -ResourceGroupName $rgname -location $rglocation -Name $virtualRouterName -HostedSubnet $hostedsubnet.Id
$expectedvr = Get-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName
Assert-AreEqual $expectedvr.ResourceGroupName $actualvr.ResourceGroupName
Assert-AreEqual $expectedvr.Name $actualvr.Name

# List Virtual Routers
$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual $expectedvr.Location $actualvr.Location

# List Virtual Routers
$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual 1 @($list).Count
Assert-AreEqual $list[0].ResourceGroupName $actualvr.ResourceGroupName
Assert-AreEqual $list[0].Name $actualvr.Name
Assert-AreEqual $list[0].Location $actualvr.Location

# Delete VR
$deletevR = Remove-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName -PassThru -Force
Assert-AreEqual true $deletevR

# Delete virtualNetworkGateway
$delete = Remove-AzVirtualNetworkGateway -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force
Assert-AreEqual true $delete

$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count

# Delete VR
$deletevr = Remove-AzVirtualRouter -ResourceGroupName $rgname -RouterName $virtualRouterName -PassThru -Force
Assert-AreEqual true $deletevr

$list = Get-AzVirtualRouter -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Loading