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

[do not merge before 4118] Adding changes to support Private DNS Public Preview #4109

Merged
merged 17 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions src/SDKs/Dns/AzSdk.RP.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--This file and it's contents are updated at build time moving or editing might result in build failure. Take due deligence while editing this file-->
<PropertyGroup>
<AzureApiTag>Network_2018-03-01-preview;</AzureApiTag>
<PackageTags>$(PackageTags);$(CommonTags);$(AzureApiTag);</PackageTags>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions src/SDKs/Dns/Dns.Tests/Dns.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Network" Version="14.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
</ItemGroup>

<ItemGroup>
<!--<PackageReference Include="Microsoft.Azure.Management.Dns" Version="1.8.0-preview" />-->
<ProjectReference Include="..\Management.Dns\Microsoft.Azure.Management.Dns.csproj" />
</ItemGroup>

Copy link
Member

Choose a reason for hiding this comment

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

@muwaqar remove empty lines

<ItemGroup>
<None Update="SessionRecords\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
114 changes: 91 additions & 23 deletions src/SDKs/Dns/Dns.Tests/Helpers/ResourceGroupHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Management.Dns.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Azure.Test;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;
using Microsoft.Azure.Management.Dns.Models;
using SubResource = Microsoft.Azure.Management.Dns.Models.SubResource;
Copy link
Member

Choose a reason for hiding this comment

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

@muwaqar sort and remove unused usings (if applicable)


namespace Microsoft.Azure.Management.Dns.Testing
{
using Rest.ClientRuntime.Azure.TestFramework;

public static class ResourceGroupHelper
{
// DNS resources are in location "global" but resource groups cannot be in that same location
private const string ResourceLocation = "Central US";

private static readonly Random RandomGenerator = new Random();

/// <summary>
/// Default constructor for management clients, using the TestSupport Infrastructure
/// </summary>
Expand All @@ -25,8 +33,7 @@ public static ResourceManagementClient GetResourcesClient(
RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = context.GetServiceClient<ResourceManagementClient>(
handlers: handler);
var client = context.GetServiceClient<ResourceManagementClient>(handlers: handler);
return client;
}

Expand All @@ -35,15 +42,28 @@ public static ResourceManagementClient GetResourcesClient(
/// using the TestSupport Infrastructure
/// </summary>
/// <param name="handler"></param>
/// <returns>A resource management client, created from the current context
/// (environment variables)</returns>
/// <returns>A resource management client, created from the current context (environment variables)</returns>
public static DnsManagementClient GetDnsClient(
MockContext context,
RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = context.GetServiceClient<DnsManagementClient>(
handlers: handler);
var client = context.GetServiceClient<DnsManagementClient>(handlers: handler);
return client;
}

/// <summary>
/// Default constructor for network clients,
/// using the TestSupport Infrastructure
/// </summary>
/// <param name="handler"></param>
/// <returns>A netowrk management client, created from the current context (environment variables)</returns>
public static NetworkManagementClient GetNetworkClient(
MockContext context,
RecordedDelegatingHandler handler)
{
handler.IsPassThrough = true;
var client = context.GetServiceClient<NetworkManagementClient>(handlers: handler);
return client;
}

Expand All @@ -68,8 +88,7 @@ public static string GetResourceLocation(
parts[1],
StringComparison.OrdinalIgnoreCase))
{
location = resource.Locations.FirstOrDefault(
loca => !string.IsNullOrEmpty(loca));
location = resource.Locations.FirstOrDefault(loca => !string.IsNullOrEmpty(loca));
}
}

Expand All @@ -79,22 +98,13 @@ public static string GetResourceLocation(
public static ResourceGroup CreateResourceGroup(
ResourceManagementClient resourcesClient)
{
string resourceGroupName =
TestUtilities.GenerateName("hydratestdnsrg");

// DNS resources are in location "global" but resource groups
// can't be in that same location
string location = "Central US";

Assert.False(
string.IsNullOrEmpty(location),
"CSM did not return any valid locations for DNS resources");
string resourceGroupName = TestUtilities.GenerateName("hydratestdnsrg");

var response = resourcesClient.ResourceGroups.CreateOrUpdate(
resourceGroupName,
new ResourceGroup
{
Location = location
Location = ResourceLocation
});

return response;
Expand All @@ -109,13 +119,71 @@ public static Zone CreateZone(
return dnsClient.Zones.CreateOrUpdate(
resourceGroup.Name,
zoneName,
new Microsoft.Azure.Management.Dns.Models.Zone
new Zone
{
ZoneType = ZoneType.Public,
Location = location,
Etag = null
},
null,
null);
}

public static Zone CreatePrivateZone(
DnsManagementClient dnsClient,
string zoneName,
string location,
IList<SubResource> registrationVnets,
IList<SubResource> resolutionVnets,
ResourceGroup resourceGroup)
{
return dnsClient.Zones.CreateOrUpdate(
resourceGroup.Name,
zoneName,
new Zone
{
ZoneType = ZoneType.Private,
Location = location,
Etag = null,
RegistrationVirtualNetworks = registrationVnets,
ResolutionVirtualNetworks = resolutionVnets,
},
null,
null);
}

public static VirtualNetwork CreateVirtualNetwork(
string resourceGroupName,
NetworkManagementClient networkClient)
{
var virtualNetworkName = TestUtilities.GenerateName("hydratestdnsvn");
var subnetName = TestUtilities.GenerateName("hydratestdnssubnet");

var vnet = new VirtualNetwork
{
AddressSpace = new AddressSpace
{
AddressPrefixes = new List<string>
{
"10.0.0.0/16"
}
},
Subnets = new List<Subnet>
{
new Subnet
{
Name = subnetName,
AddressPrefix = "10.0." + RandomGenerator.Next(0, 255) + ".0/24"
}
},
Location = ResourceLocation
};

var putVnetResponse = networkClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, virtualNetworkName, vnet);
Assert.Equal("Succeeded", putVnetResponse.ProvisioningState);

var getVnetResponse = networkClient.VirtualNetworks.Get(resourceGroupName, virtualNetworkName);
return getVnetResponse;
}
}
}
Loading