Skip to content

Adding subnet delegation cmdlets #7220

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 11 commits into from
Sep 14, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NetworkResourcesController.cs" />
<Compile Include="ScenarioTests\ApplicationGatewayTests.cs" />
<Compile Include="ScenarioTests\AvailableDelegationsTests.cs" />
<Compile Include="ScenarioTests\CortexTests.cs" />
<Compile Include="ScenarioTests\AzureFirewallTests.cs" />
<Compile Include="ScenarioTests\DdosProtectionPlanTests.cs" />
Expand Down Expand Up @@ -104,6 +105,9 @@
<None Include="ScenarioTests\ApplicationGatewayTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\AvailableDelegationsTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\DdosProtectionPlanTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -245,6 +249,9 @@
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.AvailableEndpointServicesTests\TestAvailableEndpointServicesList.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.AvailableDelegationsTests\TestAvailableDelegationsList.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.AzureFirewallTests\TestAzureFirewallAllocateAndDeallocate.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -642,6 +649,9 @@
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestResourceNavigationLinksOnSubnetCRUD.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestVirtualNetworkSubnetDelegationCRUD.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Commands.Network.Test.ScenarioTests.VirtualNetworkTests\TestVirtualNetworkCRUD.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------------
//
// 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.ServiceManagemenet.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Commands.Network.Test.ScenarioTests
{
public class AvailableDelegationsTests : Microsoft.WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
{
public XunitTracingInterceptor _logger;

public AvailableDelegationsTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, Category.sdnnrp)]
public void TestAvailableDelegationsList()
{
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-GetAvailableDelegationsList");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ----------------------------------------------------------------------------------
#
# 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
Tests checking API to list available delegations.
#>
function Test-GetAvailableDelegationsList
{
$location = Get-ProviderLocation ResourceManagement
$location = $location -replace " ",""
try
{
$results = Get-AzureRmAvailableServiceDelegation -Location $location;
Assert-NotNull $results;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public void TestVirtualNetworkSubnetCRUD()
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-subnetCRUD");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, Category.sdnnrp)]
public void TestVirtualNetworkSubnetDelegationCRUD()
{
NetworkResourcesController.NewInstance.RunPsTest(_logger, "Test-subnetDelegationCRUD");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, Category.sdnnrp)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,96 @@ function Test-subnetCRUD
}
}

<#
.SYNOPSIS
Tests creating new virtualNetwork w/ delegated subnets.
.DESCRIPTION
SmokeTest
#>
function Test-subnetDelegationCRUD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add the test recodings for the tests to both git and the project. Example here and here](https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/Network/Commands.Network.Test/Commands.Network.Test.csproj#L321).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static analysis errors should be fixed in the latest build.
Running a local build to re-run tests before I add the recordings. Should be there soon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these cmdlets to the exception, but I'm still experiencing build failures :(

{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$subnetName = Get-ResourceName
$subnet2Name = Get-ResourceName
$domainNameLabel = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworks"
$location = Get-ProviderLocation $resourceTypeParent

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

# Create a delegation
$delegation = New-AzureRmDelegation -Name "sqlDelegation" -ServiceName "Microsoft.Sql/servers"

# Create the Virtual Network
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 -delegation $delegation
New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgname

# Add a subnet
$vnet | Add-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -AddressPrefix 10.0.2.0/24

# Set VirtualNetwork
$vnet | Set-AzureRmVirtualNetwork

# Get VirtualNetwork
$vnetExpected = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname

Assert-AreEqual 2 @($vnetExpected.Subnets).Count
Assert-AreEqual 1 @($vnetExpected.Subnets[0].Delegations).Count
Assert-AreEqual 0 @($vnetExpected.Subnets[1].Delegations).Count

# Edit a subnet
$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Set-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -AddressPrefix 10.0.2.0/24

# Add a delegation to the subnet
Get-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -VirtualNetwork $vnet | Add-AzureRmDelegation -Name "bareMetalDelegation" -ServiceName "Microsoft.Netapp/volumes"
Set-AzureRmVirtualNetwork -VirtualNetwork $vnet

$vnetExpected = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
Assert-AreEqual 2 @($vnetExpected.Subnets).Count
Assert-AreEqual 1 @($vnetExpected.Subnets[0].Delegations).Count
Assert-AreEqual "Microsoft.Sql/servers" $vnetExpected.Subnets[0].Delegations[0].ServiceName
Assert-AreEqual 1 @($vnetExpected.Subnets[1].Delegations).Count
Assert-AreEqual "Microsoft.Netapp/volumes" $vnetExpected.Subnets[1].Delegations[0].ServiceName

# Get subnet
$subnet2 = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Get-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name
Assert-AreEqual 1 @($subnet2.Delegations).Count
$subnetAll = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Get-AzureRmVirtualNetworkSubnetConfig

Assert-AreEqual 2 @($subnetAll).Count

# Get delegations from the subnets
Foreach ($sub in $subnetAll)
{
$del = Get-AzureRmDelegation -Subnet $sub
Assert-NotNull $del
}

# Remove a delegation
$vnetToEdit = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$subnetWithoutDelegation = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnet2Name -VirtualNetwork $vnet | Remove-AzureRmDelegation -Name "bareMetalDelegation"
$vnetToEdit.Subnets[1] = $subnetWithoutDelegation
$vnet = Set-AzureRmVirtualNetwork -VirtualNetwork $vnetToEdit

$vnetExpected = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
Assert-AreEqual 2 @($vnetExpected.Subnets).Count
Assert-AreEqual 1 @($vnetExpected.Subnets[0].Delegations).Count
Assert-AreEqual 0 @($vnetExpected.Subnets[1].Delegations).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests creating new simple virtualNetwork and subnets.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/e05dbbce-79c2-45a2-a7ef-f1058856feb3/providers/Microsoft.Network/locations/westcentralus/availableDelegations?api-version=2018-08-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZTA1ZGJiY2UtNzljMi00NWEyLWE3ZWYtZjEwNTg4NTZmZWIzL3Byb3ZpZGVycy9NaWNyb3NvZnQuTmV0d29yay9sb2NhdGlvbnMvd2VzdGNlbnRyYWx1cy9hdmFpbGFibGVEZWxlZ2F0aW9ucz9hcGktdmVyc2lvbj0yMDE4LTA4LTAx",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"c10de067-a942-4b31-af27-c70299eee8de"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.7.3163.0",
"OSName/Windows10Enterprise",
"OSVersion/6.3.17134",
"Microsoft.Azure.Management.Network.NetworkManagementClient/19.4.0.0"
]
},
"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}",
"ResponseHeaders": {
"Content-Length": [
"2596"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Pragma": [
"no-cache"
],
"x-ms-request-id": [
"584c08d1-9b2e-44c6-968c-322bdb48e783"
],
"x-ms-correlation-request-id": [
"3ca1d79c-8ba7-469e-82a8-89b5d8d0e840"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"11999"
],
"Cache-Control": [
"no-cache"
],
"Server": [
"Microsoft-HTTPAPI/2.0",
"Microsoft-HTTPAPI/2.0"
],
"x-ms-routing-request-id": [
"WESTUS2:20180913T191723Z:3ca1d79c-8ba7-469e-82a8-89b5d8d0e840"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Thu, 13 Sep 2018 19:17:22 GMT"
]
},
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "e05dbbce-79c2-45a2-a7ef-f1058856feb3"
}
}
Loading