Skip to content

Commit

Permalink
update to use new compute package and no longer depend on old track 2
Browse files Browse the repository at this point in the history
  • Loading branch information
m-nash committed Aug 11, 2021
1 parent 49610d8 commit b46f1ae
Show file tree
Hide file tree
Showing 29 changed files with 297 additions and 357 deletions.
4 changes: 2 additions & 2 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

<!-- Packages intended for Management libraries only -->
<ItemGroup Condition="'$(IsMgmtSubLibrary)' == 'true'">
<PackageReference Update="Azure.ResourceManager" Version="1.0.0-alpha.20210730.2" />
<PackageReference Update="Azure.ResourceManager" Version="1.0.0-alpha.20210804.1" />
</ItemGroup>

<!-- Packages intended for Extensions libraries only -->
Expand Down Expand Up @@ -159,7 +159,7 @@
<PackageReference Update="ApprovalUtilities" Version="3.0.22" />
<PackageReference Update="Azure.Messaging.EventHubs" Version="5.2.0" />
<PackageReference Update="Azure.Messaging.EventGrid" Version="4.0.0" />
<PackageReference Update="Azure.ResourceManager.Compute" Version="1.0.0-preview.2" />
<PackageReference Update="Azure.ResourceManager.Compute" Version="1.0.0-alpha.20210811.6" />
<PackageReference Update="Azure.ResourceManager.Network" Version="1.0.0-preview.2" />
<PackageReference Update="Azure.ResourceManager.Resources" Version="1.0.0-preview.2" />
<PackageReference Update="Azure.ResourceManager.Storage" Version="1.0.0-preview.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.ResourceManager.Resources" />
<PackageReference Include="Azure.ResourceManager.Compute" />
<PackageReference Include="Azure.ResourceManager.Storage" />
<PackageReference Include="Microsoft.Azure.AutoRest.CSharp" VersionOverride="$(MgmtAutorestVersion)" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class NetworkManagementTestUtilities
/// <param name="client">The resource management client</param>
/// <param name="resourceType">The type of resource to create</param>
/// <returns>A location where this resource type is supported for the current subscription</returns>
public static async Task<string> GetResourceLocation(ResourcesManagementClient client, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default)
public static async Task<string> GetResourceLocation(ArmClient client, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default)
{
HashSet<string> supportedLocations = null;

Expand All @@ -39,49 +39,8 @@ public static async Task<string> GetResourceLocation(ResourcesManagementClient c
}
string[] parts = resourceType.Split('/');
string providerName = parts[0];
Response<Resources.Models.Provider> provider = await client.Providers.GetAsync(providerName);
foreach (var resource in provider.Value.ResourceTypes)
{
if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase))
{
return resource.Locations.FirstOrDefault(supportedLocations.Contains);
}
}

return null;
}

/// <summary>
/// Get default resource location for a given resource type.
/// Once all tests are moved away from depreciated version of Resource Manager, this method should be removed
/// and "using Microsoft.Azure.Management.Resources" should be changed to "using Microsoft.Azure.Management.ResourceManager"
/// </summary>
/// <param name="client">The resource management client</param>
/// <param name="resourceType">The type of resource to create</param>
/// <returns>A location where this resource type is supported for the current subscription</returns>
public static async Task<string> GetResourceLocation(ResourcesManagementClient client, ProvidersOperations providersOperations, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default)
{
HashSet<string> supportedLocations = null;

switch (feature)
{
case FeaturesInfo.Type.Default:
supportedLocations = FeaturesInfo.DefaultLocations;
break;
case FeaturesInfo.Type.All:
supportedLocations = FeaturesInfo.AllFeaturesSupportedLocations;
break;
case FeaturesInfo.Type.Ipv6:
supportedLocations = FeaturesInfo.Ipv6SupportedLocations;
break;
case FeaturesInfo.Type.MultiCA:
supportedLocations = FeaturesInfo.DefaultLocations;
break;
}
string[] parts = resourceType.Split('/');
string providerName = parts[0];
Response<Resources.Models.Provider> provider = await providersOperations.GetAsync(providerName);
foreach (var resource in provider.Value.ResourceTypes)
ProviderInfo provider = await client.GetProviderAsync(providerName);
foreach (var resource in provider.ResourceTypes)
{
if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Azure.ResourceManager.Compute;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
using Azure.ResourceManager.Storage;
//using Azure.ResourceManager.Storage;
using Azure.ResourceManager.Network.Models;
using Azure.ResourceManager.Network.Tests.Tests;
using Azure.ResourceManager.TestFramework;
Expand All @@ -30,9 +30,9 @@ public NetworkServiceClientTestBase(bool isAsync) : base(isAsync)
public static TimeSpan ZeroPollingInterval { get; } = TimeSpan.FromSeconds(0);
public Dictionary<string, string> Tags { get; internal set; }

public ResourcesManagementClient ResourceManagementClient { get; set; }
public StorageManagementClient StorageManagementClient { get; set; }
public ComputeManagementClient ComputeManagementClient { get; set; }
//public ResourcesManagementClient ResourceManagementClient { get; set; }
//public StorageManagementClient StorageManagementClient { get; set; }
//public ComputeManagementClient ComputeManagementClient { get; set; }
public ArmClient ArmClient { get; set; }

public Resources.Subscription Subscription
Expand All @@ -57,50 +57,50 @@ public Resources.ResourceGroup GetResourceGroup(string name)
}

//public NetworkInterfacesOperations NetworkInterfacesOperations { get; set; }
public ProvidersOperations ProvidersOperations { get; set; }
public ResourceGroupsOperations ResourceGroupsOperations { get; set; }
public ResourcesOperations ResourcesOperations { get; set; }
//public ProvidersOperations ProvidersOperations { get; set; }
//public ResourceGroupsOperations ResourceGroupsOperations { get; set; }
//public ResourcesOperations ResourcesOperations { get; set; }
//public NetworkManagementOperations ServiceOperations { get; set; }
//public PrivateLinkServicesOperations PrivateLinkServicesOperations { get; set; }

protected void Initialize()
{
ResourceManagementClient = GetResourceManagementClient();
StorageManagementClient = GetStorageManagementClient();
ComputeManagementClient = GetComputeManagementClient();
//ResourceManagementClient = GetResourceManagementClient();
//StorageManagementClient = GetStorageManagementClient();
//ComputeManagementClient = GetComputeManagementClient();
ArmClient = GetArmClient();

//NetworkInterfacesOperations = NetworkManagementClient.NetworkInterfaces;
ProvidersOperations = ResourceManagementClient.Providers;
ResourceGroupsOperations = ResourceManagementClient.ResourceGroups;
ResourcesOperations = ResourceManagementClient.Resources;
//ProvidersOperations = ResourceManagementClient.Providers;
//ResourceGroupsOperations = ResourceManagementClient.ResourceGroups;
//ResourcesOperations = ResourceManagementClient.Resources;
//ServiceOperations = NetworkManagementClient.NetworkManagement;
//PrivateLinkServicesOperations = NetworkManagementClient.PrivateLinkServices;
}

protected ResourcesManagementClient GetResourceManagementClient()
{
var options = InstrumentClientOptions(new ResourcesManagementClientOptions());
//protected ResourcesManagementClient GetResourceManagementClient()
//{
// var options = InstrumentClientOptions(new ResourcesManagementClientOptions());

return CreateClient<ResourcesManagementClient>(
TestEnvironment.SubscriptionId,
TestEnvironment.Credential,
options);
}
// return CreateClient<ResourcesManagementClient>(
// TestEnvironment.SubscriptionId,
// TestEnvironment.Credential,
// options);
//}

private StorageManagementClient GetStorageManagementClient()
{
return InstrumentClient(new StorageManagementClient(TestEnvironment.SubscriptionId,
TestEnvironment.Credential,
InstrumentClientOptions(new StorageManagementClientOptions())));
}
//private StorageManagementClient GetStorageManagementClient()
//{
// return InstrumentClient(new StorageManagementClient(TestEnvironment.SubscriptionId,
// TestEnvironment.Credential,
// InstrumentClientOptions(new StorageManagementClientOptions())));
//}

private ComputeManagementClient GetComputeManagementClient()
{
return InstrumentClient(new ComputeManagementClient(TestEnvironment.SubscriptionId,
TestEnvironment.Credential,
InstrumentClientOptions(new ComputeManagementClientOptions())));
}
//private ComputeManagementClient GetComputeManagementClient()
//{
// return InstrumentClient(new ComputeManagementClient(TestEnvironment.SubscriptionId,
// TestEnvironment.Credential,
// InstrumentClientOptions(new ComputeManagementClientOptions())));
//}

protected async Task<Response<Resources.ResourceGroup>> CreateResourceGroup(string name)
{
Expand All @@ -111,8 +111,8 @@ private ComputeManagementClient GetComputeManagementClient()
return await Subscription.GetResourceGroups().CreateOrUpdateAsync(name, new ResourceGroupData(location));
}

public async Task CreateVm(
ResourcesManagementClient resourcesClient,
public async Task<VirtualMachine> CreateVm(
//ResourcesManagementClient resourcesClient,
string resourceGroupName,
string location,
string virtualMachineName,
Expand All @@ -123,52 +123,63 @@ public async Task CreateVm(
string deploymentName,
string adminPassword)
{
string deploymentParams = "{" +
"\"resourceGroupName\": {\"value\": \"" + resourceGroupName + "\"}," +
"\"location\": {\"value\": \"" + location + "\"}," +
"\"virtualMachineName\": { \"value\": \"" + virtualMachineName + "\"}," +
"\"virtualMachineSize\": { \"value\": \"Standard_DS1_v2\"}," +
"\"adminUsername\": { \"value\": \"netanalytics32\"}," +
"\"storageAccountName\": { \"value\": \"" + storageAccountName + "\"}," +
"\"routeTableName\": { \"value\": \"" + resourceGroupName + "RT\"}," +
"\"virtualNetworkName\": { \"value\": \"" + resourceGroupName + "-vnet\"}," +
"\"networkInterfaceName\": { \"value\": \"" + networkInterfaceName + "\"}," +
"\"networkSecurityGroupName\": { \"value\": \"" + networkSecurityGroupName + "\"}," +
"\"adminPassword\": { \"value\": \"" + adminPassword + "\"}," +
"\"storageAccountType\": { \"value\": \"Premium_LRS\"}," +
"\"diagnosticsStorageAccountName\": { \"value\": \"" + diagnosticsStorageAccountName + "\"}," +
"\"diagnosticsStorageAccountId\": { \"value\": \"Microsoft.Storage/storageAccounts/" + diagnosticsStorageAccountName + "\"}," +
"\"diagnosticsStorageAccountType\": { \"value\": \"Standard_LRS\"}," +
"\"addressPrefix\": { \"value\": \"10.17.3.0/24\"}," +
"\"subnetName\": { \"value\": \"default\"}, \"subnetPrefix\": { \"value\": \"10.17.3.0/24\"}," +
"\"publicIpAddressName\": { \"value\": \"" + virtualMachineName + "-ip\"}," +
"\"publicIpAddressType\": { \"value\": \"Dynamic\"}" +
"}";
string templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestData", "DeploymentTemplate.json"));

DeploymentProperties deploymentProperties = new DeploymentProperties(DeploymentMode.Incremental)
{
Template = templateString,
Parameters = deploymentParams
};
Deployment deploymentModel = new Deployment(deploymentProperties);

Operation<DeploymentExtended> deploymentWait = await resourcesClient.Deployments.StartCreateOrUpdateAsync(resourceGroupName, deploymentName, deploymentModel);
await deploymentWait.WaitForCompletionAsync();
}

public async Task CreateVmss(ResourcesManagementClient resourcesClient, string resourceGroupName, string deploymentName)
{
string templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestData", "VmssDeploymentTemplate.json"));

DeploymentProperties deploymentProperties = new DeploymentProperties(DeploymentMode.Incremental)
{
Template = templateString
};
Deployment deploymentModel = new Deployment(deploymentProperties);
Operation<DeploymentExtended> deploymentWait = await resourcesClient.Deployments.StartCreateOrUpdateAsync(resourceGroupName, deploymentName, deploymentModel);
await deploymentWait.WaitForCompletionAsync();
}
//string deploymentParams = "{" +
// "\"resourceGroupName\": {\"value\": \"" + resourceGroupName + "\"}," +
// "\"location\": {\"value\": \"" + location + "\"}," +
// "\"virtualMachineName\": { \"value\": \"" + virtualMachineName + "\"}," +
// "\"virtualMachineSize\": { \"value\": \"Standard_DS1_v2\"}," +
// "\"adminUsername\": { \"value\": \"netanalytics32\"}," +
// "\"storageAccountName\": { \"value\": \"" + storageAccountName + "\"}," +
// "\"routeTableName\": { \"value\": \"" + resourceGroupName + "RT\"}," +
// "\"virtualNetworkName\": { \"value\": \"" + resourceGroupName + "-vnet\"}," +
// "\"networkInterfaceName\": { \"value\": \"" + networkInterfaceName + "\"}," +
// "\"networkSecurityGroupName\": { \"value\": \"" + networkSecurityGroupName + "\"}," +
// "\"adminPassword\": { \"value\": \"" + adminPassword + "\"}," +
// "\"storageAccountType\": { \"value\": \"Premium_LRS\"}," +
// "\"diagnosticsStorageAccountName\": { \"value\": \"" + diagnosticsStorageAccountName + "\"}," +
// "\"diagnosticsStorageAccountId\": { \"value\": \"Microsoft.Storage/storageAccounts/" + diagnosticsStorageAccountName + "\"}," +
// "\"diagnosticsStorageAccountType\": { \"value\": \"Standard_LRS\"}," +
// "\"addressPrefix\": { \"value\": \"10.17.3.0/24\"}," +
// "\"subnetName\": { \"value\": \"default\"}, \"subnetPrefix\": { \"value\": \"10.17.3.0/24\"}," +
// "\"publicIpAddressName\": { \"value\": \"" + virtualMachineName + "-ip\"}," +
// "\"publicIpAddressType\": { \"value\": \"Dynamic\"}" +
// "}";
//string templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestData", "DeploymentTemplate.json"));

//DeploymentProperties deploymentProperties = new DeploymentProperties(DeploymentMode.Incremental)
//{
// Template = templateString,
// Parameters = deploymentParams
//};
//Deployment deploymentModel = new Deployment(deploymentProperties);

//Operation<DeploymentExtended> deploymentWait = await resourcesClient.Deployments.StartCreateOrUpdateAsync(resourceGroupName, deploymentName, deploymentModel);
//await deploymentWait.WaitForCompletionAsync();
ResourceGroup rg = await ArmClient.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(resourceGroupName, new ResourceGroupData(location));
NetworkInterface nic = await rg.GetNetworkInterfaces().CreateOrUpdateAsync(networkInterfaceName, new NetworkInterfaceData());
var vnetData = new VirtualNetworkData();
vnetData.AddressSpace = new AddressSpace();
vnetData.AddressSpace.AddressPrefixes.Add("10.0.0.0/24");
VirtualNetwork vnet = await rg.GetVirtualNetworks().CreateOrUpdateAsync("myvnet", vnetData);
var subnetData = new SubnetData();
subnetData.AddressPrefix = "10.0.0.0/28";
Subnet subnet = await vnet.GetSubnets().CreateOrUpdateAsync("default", subnetData);
VirtualMachineData vmData = new VirtualMachineData(location);
return await rg.GetVirtualMachines().CreateOrUpdateAsync(virtualMachineName, vmData);
}

//public async Task CreateVmss(ResourcesManagementClient resourcesClient, string resourceGroupName, string deploymentName)
//{
// string templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestData", "VmssDeploymentTemplate.json"));

// DeploymentProperties deploymentProperties = new DeploymentProperties(DeploymentMode.Incremental)
// {
// Template = templateString
// };
// Deployment deploymentModel = new Deployment(deploymentProperties);
// Operation<DeploymentExtended> deploymentWait = await resourcesClient.Deployments.StartCreateOrUpdateAsync(resourceGroupName, deploymentName, deploymentModel);
// await deploymentWait.WaitForCompletionAsync();
//}

public async Task<ExpressRouteCircuit> CreateDefaultExpressRouteCircuit(Resources.ResourceGroup resourceGroup, string circuitName, string location)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;

Expand All @@ -17,13 +18,13 @@ public static class ResourcesManagementTestUtilities
/// <param name="client">The resource management client</param>
/// <param name="resourceType">The type of resource to create</param>
/// <returns>A location where this resource type is supported for the current subscription</returns>
public static async Task<string> GetResourceLocation(ResourcesManagementClient client, string resourceType)
public static async Task<string> GetResourceLocation(ArmClient client, string resourceType)
{
string location = null;
string[] parts = resourceType.Split('/');
string providerName = parts[0];
Response<ResourceManager.Resources.Models.Provider> provider = await client.Providers.GetAsync(providerName);
foreach (var resource in provider.Value.ResourceTypes)
ProviderInfo provider = await client.GetProviderAsync(providerName);
foreach (var resource in provider.ResourceTypes)
{
if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase))
{
Expand Down
Loading

0 comments on commit b46f1ae

Please sign in to comment.