Skip to content

Commit b797ada

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#7220 from rupalivohra/delegation
Adding subnet delegation cmdlets
2 parents 28d3928 + 284ef53 commit b797ada

File tree

39 files changed

+3989
-60
lines changed

39 files changed

+3989
-60
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<Compile Include="Properties\AssemblyInfo.cs" />
6868
<Compile Include="NetworkResourcesController.cs" />
6969
<Compile Include="ScenarioTests\ApplicationGatewayTests.cs" />
70+
<Compile Include="ScenarioTests\AvailableDelegationsTests.cs" />
7071
<Compile Include="ScenarioTests\CortexTests.cs" />
7172
<Compile Include="ScenarioTests\AzureFirewallTests.cs" />
7273
<Compile Include="ScenarioTests\DdosProtectionPlanTests.cs" />
@@ -104,6 +105,9 @@
104105
<None Include="ScenarioTests\ApplicationGatewayTests.ps1">
105106
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
106107
</None>
108+
<None Include="ScenarioTests\AvailableDelegationsTests.ps1">
109+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
110+
</None>
107111
<None Include="ScenarioTests\DdosProtectionPlanTests.ps1">
108112
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
109113
</None>
@@ -245,6 +249,9 @@
245249
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.AvailableEndpointServicesTests\TestAvailableEndpointServicesList.json">
246250
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
247251
</None>
252+
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.AvailableDelegationsTests\TestAvailableDelegationsList.json">
253+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
254+
</None>
248255
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.AzureFirewallTests\TestAzureFirewallAllocateAndDeallocate.json">
249256
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
250257
</None>
@@ -642,6 +649,9 @@
642649
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestResourceNavigationLinksOnSubnetCRUD.json">
643650
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
644651
</None>
652+
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestVirtualNetworkSubnetDelegationCRUD.json">
653+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
654+
</None>
645655
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestVirtualNetworkCRUD.json">
646656
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
647657
</None>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.ServiceManagemenet.Common.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
20+
namespace Commands.Network.Test.ScenarioTests
21+
{
22+
public class AvailableDelegationsTests : Microsoft.WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
23+
{
24+
public XunitTracingInterceptor _logger;
25+
26+
public AvailableDelegationsTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
_logger = new XunitTracingInterceptor(output);
29+
XunitTracingInterceptor.AddToContext(_logger);
30+
}
31+
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
[Trait(Category.Owner, Category.sdnnrp)]
35+
public void TestAvailableDelegationsList()
36+
{
37+
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-GetAvailableDelegationsList");
38+
}
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 checking API to list available delegations.
18+
#>
19+
function Test-GetAvailableDelegationsList
20+
{
21+
$location = Get-ProviderLocation ResourceManagement
22+
$location = $location -replace " ",""
23+
try
24+
{
25+
$results = Get-AzureRmAvailableServiceDelegation -Location $location;
26+
Assert-NotNull $results;
27+
}
28+
finally
29+
{
30+
# Cleanup
31+
Clean-ResourceGroup $rgname
32+
}
33+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public void TestVirtualNetworkSubnetCRUD()
5454
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-subnetCRUD");
5555
}
5656

57+
[Fact]
58+
[Trait(Category.AcceptanceType, Category.CheckIn)]
59+
[Trait(Category.Owner, Category.sdnnrp)]
60+
public void TestVirtualNetworkSubnetDelegationCRUD()
61+
{
62+
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-subnetDelegationCRUD");
63+
}
64+
5765
[Fact]
5866
[Trait(Category.AcceptanceType, Category.CheckIn)]
5967
[Trait(Category.Owner, Category.sdnnrp)]

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,96 @@ function Test-subnetCRUD
187187
}
188188
}
189189

190+
<#
191+
.SYNOPSIS
192+
Tests creating new virtualNetwork w/ delegated subnets.
193+
.DESCRIPTION
194+
SmokeTest
195+
#>
196+
function Test-subnetDelegationCRUD
197+
{
198+
# Setup
199+
$rgname = Get-ResourceGroupName
200+
$vnetName = Get-ResourceName
201+
$subnetName = Get-ResourceName
202+
$subnet2Name = Get-ResourceName
203+
$domainNameLabel = Get-ResourceName
204+
$rglocation = Get-ProviderLocation ResourceManagement
205+
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
206+
$location = Get-ProviderLocation $resourceTypeParent
207+
208+
try
209+
{
210+
# Create the resource group
211+
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
212+
213+
# Create a delegation
214+
$delegation = New-AzureRmDelegation -Name "sqlDelegation" -ServiceName "Microsoft.Sql/servers"
215+
216+
# Create the Virtual Network
217+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 -delegation $delegation
218+
New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
219+
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
220+
221+
# Add a subnet
222+
$vnet | Add-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -AddressPrefix 10.0.2.0/24
223+
224+
# Set VirtualNetwork
225+
$vnet | Set-AzureRmVirtualNetwork
226+
227+
# Get VirtualNetwork
228+
$vnetExpected = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
229+
230+
Assert-AreEqual 2 @($vnetExpected.Subnets).Count
231+
Assert-AreEqual 1 @($vnetExpected.Subnets[0].Delegations).Count
232+
Assert-AreEqual 0 @($vnetExpected.Subnets[1].Delegations).Count
233+
234+
# Edit a subnet
235+
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Set-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -AddressPrefix 10.0.2.0/24
236+
237+
# Add a delegation to the subnet
238+
Get-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -VirtualNetwork $vnet | Add-AzureRmDelegation -Name "bareMetalDelegation" -ServiceName "Microsoft.Netapp/volumes"
239+
Set-AzureRmVirtualNetwork -VirtualNetwork $vnet
240+
241+
$vnetExpected = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
242+
Assert-AreEqual 2 @($vnetExpected.Subnets).Count
243+
Assert-AreEqual 1 @($vnetExpected.Subnets[0].Delegations).Count
244+
Assert-AreEqual "Microsoft.Sql/servers" $vnetExpected.Subnets[0].Delegations[0].ServiceName
245+
Assert-AreEqual 1 @($vnetExpected.Subnets[1].Delegations).Count
246+
Assert-AreEqual "Microsoft.Netapp/volumes" $vnetExpected.Subnets[1].Delegations[0].ServiceName
247+
248+
# Get subnet
249+
$subnet2 = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Get-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name
250+
Assert-AreEqual 1 @($subnet2.Delegations).Count
251+
$subnetAll = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Get-AzureRmVirtualNetworkSubnetConfig
252+
253+
Assert-AreEqual 2 @($subnetAll).Count
254+
255+
# Get delegations from the subnets
256+
Foreach ($sub in $subnetAll)
257+
{
258+
$del = Get-AzureRmDelegation -Subnet $sub
259+
Assert-NotNull $del
260+
}
261+
262+
# Remove a delegation
263+
$vnetToEdit = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
264+
$subnetWithoutDelegation = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -VirtualNetwork $vnet | Remove-AzureRmDelegation -Name "bareMetalDelegation"
265+
$vnetToEdit.Subnets[1] = $subnetWithoutDelegation
266+
$vnet = Set-AzureRmVirtualNetwork -VirtualNetwork $vnetToEdit
267+
268+
$vnetExpected = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
269+
Assert-AreEqual 2 @($vnetExpected.Subnets).Count
270+
Assert-AreEqual 1 @($vnetExpected.Subnets[0].Delegations).Count
271+
Assert-AreEqual 0 @($vnetExpected.Subnets[1].Delegations).Count
272+
}
273+
finally
274+
{
275+
# Cleanup
276+
Clean-ResourceGroup $rgname
277+
}
278+
}
279+
190280
<#
191281
.SYNOPSIS
192282
Tests creating new simple virtualNetwork and subnets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/locations/westcentralus/availableDelegations?api-version=2018-08-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZTA1ZGJiY2UtNzljMi00NWEyLWE3ZWYtZjEwNTg4NTZmZWIzL3Byb3ZpZGVycy9NaWNyb3NvZnQuTmV0d29yay9sb2NhdGlvbnMvd2VzdGNlbnRyYWx1cy9hdmFpbGFibGVEZWxlZ2F0aW9ucz9hcGktdmVyc2lvbj0yMDE4LTA4LTAx",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"c10de067-a942-4b31-af27-c70299eee8de"
11+
],
12+
"accept-language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.7.3163.0",
17+
"OSName/Windows10Enterprise",
18+
"OSVersion/6.3.17134",
19+
"Microsoft.Azure.Management.Network.NetworkManagementClient/19.4.0.0"
20+
]
21+
},
22+
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"name\": \"Microsoft.Web.serverFarms\",\r\n \"id\": \"/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/availableDelegations/Microsoft.Web.serverFarms\",\r\n \"type\": \"Microsoft.Network/availableDelegations\",\r\n \"serviceName\": \"Microsoft.Web/serverFarms\",\r\n \"actions\": [\r\n \"Microsoft.Network/virtualNetworks/subnets/action\"\r\n ]\r\n },\r\n {\r\n \"name\": \"Microsoft.Sql.servers\",\r\n \"id\": \"/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/availableDelegations/Microsoft.Sql.servers\",\r\n \"type\": \"Microsoft.Network/availableDelegations\",\r\n \"serviceName\": \"Microsoft.Sql/servers\",\r\n \"actions\": []\r\n },\r\n {\r\n \"name\": \"Microsoft.ContainerInstance.containerGroups\",\r\n \"id\": \"/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/availableDelegations/Microsoft.ContainerInstance.containerGroups\",\r\n \"type\": \"Microsoft.Network/availableDelegations\",\r\n \"serviceName\": \"Microsoft.ContainerInstance/containerGroups\",\r\n \"actions\": [\r\n \"Microsoft.Network/virtualNetworks/subnets/action\"\r\n ]\r\n },\r\n {\r\n \"name\": \"Microsoft.Netapp.volumes\",\r\n \"id\": \"/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/availableDelegations/Microsoft.Netapp.volumes\",\r\n \"type\": \"Microsoft.Network/availableDelegations\",\r\n \"serviceName\": \"Microsoft.Netapp/volumes\",\r\n \"actions\": [\r\n \"Microsoft.Network/networkinterfaces/*\",\r\n \"Microsoft.Network/virtualNetworks/subnets/join/action\"\r\n ]\r\n },\r\n {\r\n \"name\": \"Microsoft.HardwareSecurityModules.dedicatedHSMs\",\r\n \"id\": \"/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/availableDelegations/Microsoft.HardwareSecurityModules.dedicatedHSMs\",\r\n \"type\": \"Microsoft.Network/availableDelegations\",\r\n \"serviceName\": \"Microsoft.HardwareSecurityModules/dedicatedHSMs\",\r\n \"actions\": [\r\n \"Microsoft.Network/networkinterfaces/*\",\r\n \"Microsoft.Network/virtualNetworks/subnets/join/action\"\r\n ]\r\n },\r\n {\r\n \"name\": \"Microsoft.ServiceFabricMesh.networks\",\r\n \"id\": \"/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/availableDelegations/Microsoft.ServiceFabricMesh.networks\",\r\n \"type\": \"Microsoft.Network/availableDelegations\",\r\n \"serviceName\": \"Microsoft.ServiceFabricMesh/networks\",\r\n \"actions\": [\r\n \"Microsoft.Network/virtualNetworks/subnets/action\"\r\n ]\r\n }\r\n ]\r\n}",
23+
"ResponseHeaders": {
24+
"Content-Length": [
25+
"2596"
26+
],
27+
"Content-Type": [
28+
"application/json; charset=utf-8"
29+
],
30+
"Expires": [
31+
"-1"
32+
],
33+
"Pragma": [
34+
"no-cache"
35+
],
36+
"x-ms-request-id": [
37+
"584c08d1-9b2e-44c6-968c-322bdb48e783"
38+
],
39+
"x-ms-correlation-request-id": [
40+
"3ca1d79c-8ba7-469e-82a8-89b5d8d0e840"
41+
],
42+
"Strict-Transport-Security": [
43+
"max-age=31536000; includeSubDomains"
44+
],
45+
"x-ms-ratelimit-remaining-subscription-reads": [
46+
"11999"
47+
],
48+
"Cache-Control": [
49+
"no-cache"
50+
],
51+
"Server": [
52+
"Microsoft-HTTPAPI/2.0",
53+
"Microsoft-HTTPAPI/2.0"
54+
],
55+
"x-ms-routing-request-id": [
56+
"WESTUS2:20180913T191723Z:3ca1d79c-8ba7-469e-82a8-89b5d8d0e840"
57+
],
58+
"X-Content-Type-Options": [
59+
"nosniff"
60+
],
61+
"Date": [
62+
"Thu, 13 Sep 2018 19:17:22 GMT"
63+
]
64+
},
65+
"StatusCode": 200
66+
}
67+
],
68+
"Names": {},
69+
"Variables": {
70+
"SubscriptionId": "e05dbbce-79c2-45a2-a7ef-f1058856feb3"
71+
}
72+
}

0 commit comments

Comments
 (0)