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

[Network] Added Cmdlets for Network Virtual Appliance (NVA) and NVA site resources. #12213

Merged
merged 13 commits into from
Jun 24, 2020
Merged
8 changes: 8 additions & 0 deletions src/Network/Network.Test/Network.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.10.0-preview" />
</ItemGroup>

<ItemGroup>
<Resource Include="SessionRecords\Commands.Network.Test.ScenarioTests.NetworkVirtualApplianceTests\TestNetworkVirtualApplianceCRUD.json" />
</ItemGroup>

<ItemGroup>
<None Update="ScenarioTests\Data\*.*" CopyToOutputDirectory="PreserveNewest" />
<None Update="ScenarioTests\Utils\*.*" CopyToOutputDirectory="PreserveNewest" />
Expand All @@ -35,4 +39,8 @@
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="SessionRecords\Commands.Network.Test.ScenarioTests.NetworkVirtualApplianceTests\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ----------------------------------------------------------------------------------
//
// 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 NetworkVirtualApplianceTests : NetworkTestRunner
{
public NetworkVirtualApplianceTests(Xunit.Abstractions.ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestNetworkVirtualApplianceCRUD()
{
TestRunner.RunTestScript(string.Format("Test-NetworkVirtualApplianceCRUD"));
}

[Fact(Skip = "A bug is being fixed by Nfv-Rp team")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestVirtualApplianceSiteCRUD()
{
TestRunner.RunTestScript("Test-VirtualApplianceSiteCRUD");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# ----------------------------------------------------------------------------------
#
# 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 NetworkVirtualAppliance
#>
function Test-NetworkVirtualApplianceCRUD
{
$rgname = Get-ResourceGroupName

# The commands are not supported in all regions yet.
$location = "eastus2"
$nvaname = Get-ResourceName
$wanname = Get-ResourceName
$hubname = Get-ResourceName
$resourceTypeParent = "Microsoft.Network/networkVirtualAppliance"
$vendor = "barracuda sdwan release"
$scaleunit = 1
$version = 'latest'
$newasn = 1271
$asn=1270
$prefix = "10.0.0.0/16"
try{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location
$sku = New-AzVirtualApplianceSkuProperties -VendorName $vendor -BundledScaleUnit $scaleunit -MarketPlaceVersion $version
Assert-NotNull $sku

$wan = New-AzVirtualWan -ResourceGroupName $rgname -Name $wanname -Location $location
$hub = New-AzVirtualHub -ResourceGroupName $rgname -Name $hubname -Location $location -VirtualWan $wan -AddressPrefix $prefix
$nva = New-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname -Location $location -VirtualApplianceAsn $asn -VirtualHubId $hub.Id -Sku $sku -CloudInitConfiguration "echo hi"
Assert-NotNull $nva

$getnva = Get-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname
Assert-NotNull $getnva

## There is a bug in the update call in the nfvrp. The NfvRp team will record the powershell tests once fixed.
# $updatednva = Update-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname -VirtualApplianceAsn $newasn -Force
# Assert-True { $updatednva.VirtualApplianceAsn -eq $newasn}

$rmresult = Remove-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname -Force -PassThru
Assert-True { $true }
}
finally{
# Clean up.
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test creating new VirtualApplianceSite
#>
function Test-VirtualApplianceSiteCRUD
{
$rgname = Get-ResourceGroupName

# The commands are not supported in all regions yet.
$location = "eastus2"
$nvaname = Get-ResourceName
$wanname = Get-ResourceName
$hubname = Get-ResourceName
$sitename = Get-ResourceName
$resourceTypeParent = "Microsoft.Network/networkVirtualAppliance"
$vendor = "barracuda sdwan release"
$scaleunit = 1
$version = 'latest'
$asn = 1270
$prefix = "10.0.0.0/16"
$siteprefix = "10.0.1.0/24"
$newsiteprefix = "10.0.2.0/24"
try{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location
$sku = New-AzVirtualApplianceSkuProperties -VendorName $vendor -BundledScaleUnit $scaleunit -MarketPlaceVersion $version
Assert-NotNull $sku

$wan = New-AzVirtualWan -ResourceGroupName $rgname -Name $wanname -Location $location
$hub = New-AzVirtualHub -ResourceGroupName $rgname -Name $hubname -Location $location -VirtualWan $wan -AddressPrefix $prefix
$nva = New-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname -Location $location -VirtualApplianceAsn $asn -VirtualHubId /subscriptions/5e1e8156-5dec-452a-bfe5-6b6e0947c27a/resourceGroups/sliceTestRG/providers/Microsoft.Network/virtualHubs/sliceHub -Sku $sku -CloudInitConfiguration "echo hi"
$getnva = Get-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname

$o365Policy = New-AzOffice365PolicyProperties -Allow -Optimize
$site = New-AzVirtualApplianceSite -Name $sitename -ResourceGroupName $rgname -AddressPrefix $siteprefix -O365Policy $o365Policy -NetworkVirtualApplianceId $getnva.Id
$getsite = Get-AzVirtualApplianceSite -Name $sitename -ResourceGroupName $rgname -NetworkVirtualApplianceId $getnva.Id
$setsite = Update-AzVirtualApplianceSite -Name $sitename -ResourceGroupName $rgname -NetworkVirtualApplianceId $getnva.Id -AddressPrefix $newsiteprefix -Force
Remove-AzVirtualApplianceSite -Name $sitename -ResourceGroupName $rgname -NetworkVirtualApplianceId $getnva.Id -Force
Remove-AzNetworkVirtualAppliance -ResourceGroupName $rgname -Name $nvaname -Force
}
finally{
# Clean up.
Clean-ResourceGroup $rgname
}
}


Loading