Skip to content

Create Managed Network Powershell #10195

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

Merged
merged 18 commits into from
Oct 24, 2019
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
17 changes: 17 additions & 0 deletions src/ManagedNetwork/ManagedNetwork.Test/ManagedNetwork.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>ManagedNetwork</PsModuleName>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />

<PropertyGroup>
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)$(AzTestAssemblySuffix).ScenarioTests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ManagedNetwork" Version="1.0.1-preview" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions src/ManagedNetwork/ManagedNetwork.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Reflection;
using System.Runtime.InteropServices;
using Xunit;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.Azure.Commands.ManagedNetwork.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.Azure.Commands.ManagedNetwork.Test")]
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: CollectionBehavior(DisableTestParallelization = true)]
134 changes: 134 additions & 0 deletions src/ManagedNetwork/ManagedNetwork.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# ----------------------------------------------------------------------------------
#
# 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
Gets valid resource group name
#>
function Get-ResourceGroupName
{
return getAssetName
}

<#
.SYNOPSIS
Gets valid resource name
#>
function Get-ResourceName
{
return getAssetName
}

<#
.SYNOPSIS
Gets the default location for a provider
#>
function Get-ProviderLocation($provider)
{
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
{
$namespace = $provider.Split("/")[0]
if($provider.Contains("/"))
{
$type = $provider.Substring($namespace.Length + 1)
$location = Get-AzResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}

if ($location -eq $null)
{
return "West US"
} else
{
return $location.Locations[0]
}
}

return "West US"
}

return "WestUS"
}

<#
.SYNOPSIS
Creates a resource group to use in tests
#>
function TestSetup-CreateResourceGroup
{
$resourceGroupName = getAssetName
$rglocation = Get-ProviderLocation "North Europe"
$resourceGroup = New-AzResourceGroup -Name $resourceGroupName -location $rglocation -Force
return $resourceGroup
}

<#
.SYNOPSIS
Asserts if two tags are equal
#>
function Assert-Tags($tags1, $tags2)
{
if($tags1.count -ne $tags2.count)
{
throw "Tag size not equal. Tag1: $tags1.count Tag2: $tags2.count"
}

foreach($key in $tags1.Keys)
{
if($tags1[$key] -ne $tags2[$key])
{
throw "Tag content not equal. Key:$key Tags1:" + $tags1[$key] + "Tags2:" + $tags2[$key]
}
}
}

<#
.SYNOPSIS
Asserts if two compression types are equal
#>
function Assert-CompressionTypes($types1, $types2)
{
if($types1.Count -ne $types1.Count)
{
throw "Array size not equal. Types1: $types1.count Types2: $types2.count"
}

foreach($value1 in $types1)
{
$found = $false
foreach($value2 in $types2)
{
if($value1.CompareTo($value2) -eq 0)
{
$found = $true
break
}
}
if(-Not($found))
{
throw "Compression content not equal. " + $value1 + " cannot be found in second array"
}
}
}

<#
.SYNOPSIS
Sleep in record mode only
#>
function SleepInRecordMode ([int]$SleepIntervalInSec)
{
$mode = $env:AZURE_TEST_MODE
if ( $mode -ne $null -and $mode.ToUpperInvariant() -eq "RECORD")
{
Wait-Seconds $SleepIntervalInSec
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ----------------------------------------------------------------------------------
//
// 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.ManagedNetwork.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;

using Xunit;

namespace Microsoft.Azure.Commands.ManagedNetwork.Test.ScenarioTests.ScenarioTests
{
public class ManagedNetworkGroupTests
{
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;

public ManagedNetworkGroupTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetSetManagedNetworkGroup()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetSetManagedNetworkGroup");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ----------------------------------------------------------------------------------
#
# 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
Gets or sets origin with the running endpoint
#>
function Test-GetSetManagedNetworkGroup
{
$resourceGroup = "MNCRG"
$managedNetworkName = "PowershellTestMNforGroup"
$managedNetworkName2 = "PowershellTestMNforGroup_2"
$name = "TestGroup"
$location = "West US 2"


[System.Collections.Generic.List[String]]$virtualNetworkList = @()

$vnet1 = "subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh1"
$vnet2 = "subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh2"
$vnet3 = "subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh3"
$virtualNetworkList.Add($vnet1)
$virtualNetworkList.Add($vnet2)
$virtualNetworkList.Add($vnet3)

[System.String[]]$virtualNetworkArray = $virtualNetworkList
$scope = New-AzManagedNetworkScope -VirtualNetworkIdList $virtualNetworkArray

New-AzManagedNetwork -ResourceGroupName $resourceGroup -Name $managedNetworkName -scope $scope -Location $location -Force
New-AzManagedNetwork -ResourceGroupName $resourceGroup -Name $managedNetworkName2 -scope $scope -Location $location -Force


$managedNetwork = Get-AzManagedNetwork -ResourceGroupName $resourceGroup -Name $managedNetworkName2

[System.Collections.Generic.List[String]]$virtualNetworkGroupList = @()
$virtualNetworkGroupList.Add($vnet1)
$virtualNetworkGroupList.Add($vnet2)
[System.String[]]$virtualNetworkGroupArray = $virtualNetworkGroupList

New-AzManagedNetworkGroup -ResourceGroupName $resourceGroup -ManagedNetworkName $managedNetworkName -Name $name -Location $location -VirtualNetworkIdList $virtualNetworkGroupArray -Force
$managedNetworkGroupResult = Get-AzManagedNetworkGroup -ResourceGroupName $resourceGroup -ManagedNetworkName $managedNetworkName -Name $name
Assert-AreEqual $name $managedNetworkGroupResult.Name
Assert-AreEqual $location $managedNetworkGroupResult.Location

[System.Collections.Generic.List[String]]$virtualNetworkGroupList2 = @()
$virtualNetworkGroupList2.Add($vnet1)
[System.String[]]$virtualNetworkGroupArray2 = $virtualNetworkGroupList2

New-AzManagedNetworkGroup -ManagedNetworkObject $managedNetwork -Name $name -Location $location -VirtualNetworkIdList $virtualNetworkGroupArray2 -Force
$managedNetworkGroupResult2 = Get-AzManagedNetworkGroup -ResourceGroupName $resourceGroup -ManagedNetworkName $managedNetworkName2 -Name $name
Assert-AreEqual $name $managedNetworkGroupResult2.Name
Assert-AreEqual $location $managedNetworkGroupResult2.Location
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ----------------------------------------------------------------------------------
//
// 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.ManagedNetwork.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;

using Xunit;

namespace Microsoft.Azure.Commands.ManagedNetwork.Test.ScenarioTests.ScenarioTests
{
public class ManagedNetworkPolicyTests
{
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;

public ManagedNetworkPolicyTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetSetManagedNetworkPolicy()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetSetManagedNetworkPolicy");
}
}
}
Loading