Skip to content

Commit 1ab38fb

Browse files
authored
Merge pull request #10195 from yanfa317/master
Create Managed Network Powershell
2 parents 8440e75 + 9a87384 commit 1ab38fb

File tree

65 files changed

+8754
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+8754
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PsModuleName>ManagedNetwork</PsModuleName>
5+
</PropertyGroup>
6+
7+
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
8+
9+
<PropertyGroup>
10+
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)$(AzTestAssemblySuffix).ScenarioTests</RootNamespace>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.Management.ManagedNetwork" Version="1.0.1-preview" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
using System.Reflection;
16+
using System.Runtime.InteropServices;
17+
using Xunit;
18+
19+
// General Information about an assembly is controlled through the following
20+
// set of attributes. Change these attribute values to modify the information
21+
// associated with an assembly.
22+
[assembly: AssemblyTitle("Microsoft.Azure.Commands.ManagedNetwork.Test")]
23+
[assembly: AssemblyDescription("")]
24+
[assembly: AssemblyConfiguration("")]
25+
[assembly: AssemblyCompany("")]
26+
[assembly: AssemblyProduct("Microsoft.Azure.Commands.ManagedNetwork.Test")]
27+
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
28+
[assembly: AssemblyTrademark("")]
29+
[assembly: AssemblyCulture("")]
30+
31+
// Setting ComVisible to false makes the types in this assembly not visible
32+
// to COM components. If you need to access a type in this assembly from
33+
// COM, set the ComVisible attribute to true on that type.
34+
[assembly: ComVisible(false)]
35+
36+
// Version information for an assembly consists of the following four values:
37+
//
38+
// Major Version
39+
// Minor Version
40+
// Build Number
41+
// Revision
42+
//
43+
// You can specify all the values or you can default the Build and Revision Numbers
44+
// by using the '*' as shown below:
45+
[assembly: AssemblyVersion("1.0.0")]
46+
[assembly: AssemblyFileVersion("1.0.0")]
47+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
Gets valid resource group name
18+
#>
19+
function Get-ResourceGroupName
20+
{
21+
return getAssetName
22+
}
23+
24+
<#
25+
.SYNOPSIS
26+
Gets valid resource name
27+
#>
28+
function Get-ResourceName
29+
{
30+
return getAssetName
31+
}
32+
33+
<#
34+
.SYNOPSIS
35+
Gets the default location for a provider
36+
#>
37+
function Get-ProviderLocation($provider)
38+
{
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
40+
{
41+
$namespace = $provider.Split("/")[0]
42+
if($provider.Contains("/"))
43+
{
44+
$type = $provider.Substring($namespace.Length + 1)
45+
$location = Get-AzResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
46+
47+
if ($location -eq $null)
48+
{
49+
return "West US"
50+
} else
51+
{
52+
return $location.Locations[0]
53+
}
54+
}
55+
56+
return "West US"
57+
}
58+
59+
return "WestUS"
60+
}
61+
62+
<#
63+
.SYNOPSIS
64+
Creates a resource group to use in tests
65+
#>
66+
function TestSetup-CreateResourceGroup
67+
{
68+
$resourceGroupName = getAssetName
69+
$rglocation = Get-ProviderLocation "North Europe"
70+
$resourceGroup = New-AzResourceGroup -Name $resourceGroupName -location $rglocation -Force
71+
return $resourceGroup
72+
}
73+
74+
<#
75+
.SYNOPSIS
76+
Asserts if two tags are equal
77+
#>
78+
function Assert-Tags($tags1, $tags2)
79+
{
80+
if($tags1.count -ne $tags2.count)
81+
{
82+
throw "Tag size not equal. Tag1: $tags1.count Tag2: $tags2.count"
83+
}
84+
85+
foreach($key in $tags1.Keys)
86+
{
87+
if($tags1[$key] -ne $tags2[$key])
88+
{
89+
throw "Tag content not equal. Key:$key Tags1:" + $tags1[$key] + "Tags2:" + $tags2[$key]
90+
}
91+
}
92+
}
93+
94+
<#
95+
.SYNOPSIS
96+
Asserts if two compression types are equal
97+
#>
98+
function Assert-CompressionTypes($types1, $types2)
99+
{
100+
if($types1.Count -ne $types1.Count)
101+
{
102+
throw "Array size not equal. Types1: $types1.count Types2: $types2.count"
103+
}
104+
105+
foreach($value1 in $types1)
106+
{
107+
$found = $false
108+
foreach($value2 in $types2)
109+
{
110+
if($value1.CompareTo($value2) -eq 0)
111+
{
112+
$found = $true
113+
break
114+
}
115+
}
116+
if(-Not($found))
117+
{
118+
throw "Compression content not equal. " + $value1 + " cannot be found in second array"
119+
}
120+
}
121+
}
122+
123+
<#
124+
.SYNOPSIS
125+
Sleep in record mode only
126+
#>
127+
function SleepInRecordMode ([int]$SleepIntervalInSec)
128+
{
129+
$mode = $env:AZURE_TEST_MODE
130+
if ( $mode -ne $null -and $mode.ToUpperInvariant() -eq "RECORD")
131+
{
132+
Wait-Seconds $SleepIntervalInSec
133+
}
134+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
using Microsoft.Azure.Commands.ManagedNetwork.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.ManagedNetwork.Test.ScenarioTests.ScenarioTests
21+
{
22+
public class ManagedNetworkGroupTests
23+
{
24+
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
25+
26+
public ManagedNetworkGroupTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
29+
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
30+
}
31+
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void TestGetSetManagedNetworkGroup()
35+
{
36+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetSetManagedNetworkGroup");
37+
}
38+
}
39+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
Gets or sets origin with the running endpoint
18+
#>
19+
function Test-GetSetManagedNetworkGroup
20+
{
21+
$resourceGroup = "MNCRG"
22+
$managedNetworkName = "PowershellTestMNforGroup"
23+
$managedNetworkName2 = "PowershellTestMNforGroup_2"
24+
$name = "TestGroup"
25+
$location = "West US 2"
26+
27+
28+
[System.Collections.Generic.List[String]]$virtualNetworkList = @()
29+
30+
$vnet1 = "subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh1"
31+
$vnet2 = "subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh2"
32+
$vnet3 = "subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh3"
33+
$virtualNetworkList.Add($vnet1)
34+
$virtualNetworkList.Add($vnet2)
35+
$virtualNetworkList.Add($vnet3)
36+
37+
[System.String[]]$virtualNetworkArray = $virtualNetworkList
38+
$scope = New-AzManagedNetworkScope -VirtualNetworkIdList $virtualNetworkArray
39+
40+
New-AzManagedNetwork -ResourceGroupName $resourceGroup -Name $managedNetworkName -scope $scope -Location $location -Force
41+
New-AzManagedNetwork -ResourceGroupName $resourceGroup -Name $managedNetworkName2 -scope $scope -Location $location -Force
42+
43+
44+
$managedNetwork = Get-AzManagedNetwork -ResourceGroupName $resourceGroup -Name $managedNetworkName2
45+
46+
[System.Collections.Generic.List[String]]$virtualNetworkGroupList = @()
47+
$virtualNetworkGroupList.Add($vnet1)
48+
$virtualNetworkGroupList.Add($vnet2)
49+
[System.String[]]$virtualNetworkGroupArray = $virtualNetworkGroupList
50+
51+
New-AzManagedNetworkGroup -ResourceGroupName $resourceGroup -ManagedNetworkName $managedNetworkName -Name $name -Location $location -VirtualNetworkIdList $virtualNetworkGroupArray -Force
52+
$managedNetworkGroupResult = Get-AzManagedNetworkGroup -ResourceGroupName $resourceGroup -ManagedNetworkName $managedNetworkName -Name $name
53+
Assert-AreEqual $name $managedNetworkGroupResult.Name
54+
Assert-AreEqual $location $managedNetworkGroupResult.Location
55+
56+
[System.Collections.Generic.List[String]]$virtualNetworkGroupList2 = @()
57+
$virtualNetworkGroupList2.Add($vnet1)
58+
[System.String[]]$virtualNetworkGroupArray2 = $virtualNetworkGroupList2
59+
60+
New-AzManagedNetworkGroup -ManagedNetworkObject $managedNetwork -Name $name -Location $location -VirtualNetworkIdList $virtualNetworkGroupArray2 -Force
61+
$managedNetworkGroupResult2 = Get-AzManagedNetworkGroup -ResourceGroupName $resourceGroup -ManagedNetworkName $managedNetworkName2 -Name $name
62+
Assert-AreEqual $name $managedNetworkGroupResult2.Name
63+
Assert-AreEqual $location $managedNetworkGroupResult2.Location
64+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
using Microsoft.Azure.Commands.ManagedNetwork.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.ManagedNetwork.Test.ScenarioTests.ScenarioTests
21+
{
22+
public class ManagedNetworkPolicyTests
23+
{
24+
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
25+
26+
public ManagedNetworkPolicyTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
29+
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
30+
}
31+
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void TestGetSetManagedNetworkPolicy()
35+
{
36+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetSetManagedNetworkPolicy");
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)