Skip to content

Commit

Permalink
updating Compute and Gallery API version to 2019-03-01 and adding pro…
Browse files Browse the repository at this point in the history
…ximity placement group APIs. (Azure#5897)
  • Loading branch information
hyonholee authored and dsgouda committed Apr 22, 2019
1 parent b5a2d9b commit 5153627
Show file tree
Hide file tree
Showing 106 changed files with 28,363 additions and 20,385 deletions.
2 changes: 2 additions & 0 deletions src/SDKs/Compute/Compute.Tests/Helpers/ApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public const string
Providers = "providers",
VirtualMachines = "virtualMachines",
AvailabilitySets = "availabilitySets",
ProximityPlacementGroups = "proximityPlacementGroups",
VMScaleSets = "virtualMachineScaleSets",
ResourceProviderNamespace = "Microsoft.Compute";
}

Expand Down
10 changes: 10 additions & 0 deletions src/SDKs/Compute/Compute.Tests/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ public static string GetAvailabilitySetRef(string subId, string resourceGrpName,
return GetEntityReferenceId(subId, resourceGrpName, ApiConstants.AvailabilitySets, availabilitySetName);
}

public static string GetProximityPlacementGroupRef(string subId, string resourceGrpName, string proximityPlacementGroupName)
{
return GetEntityReferenceId(subId, resourceGrpName, ApiConstants.ProximityPlacementGroups, proximityPlacementGroupName);
}

public static string GetVMReferenceId(string subId, string resourceGrpName, string vmName)
{
return GetEntityReferenceId(subId, resourceGrpName, ApiConstants.VirtualMachines, vmName);
}

public static string GetVMScaleSetReferenceId(string subId, string resourceGrpName, string vmssName)
{
return GetEntityReferenceId(subId, resourceGrpName, ApiConstants.VMScaleSets, vmssName);
}

private static string GetEntityReferenceId(string subId, string resourceGrpName, string controllerName, string entityName)
{
return string.Format("/{0}/{1}/{2}/{3}/{4}/{5}/{6}/{7}",
Expand Down
6 changes: 5 additions & 1 deletion src/SDKs/Compute/Compute.Tests/ScenarioTests/GalleryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public void GalleryImageVersion_CRUD_Tests()
ValidateGalleryImageVersion(inputImageVersion, imageVersionFromGet);
imageVersionFromGet = m_CrpClient.GalleryImageVersions.Get(rgName, galleryName, galleryImageName,
galleryImageVersionName, ReplicationStatusTypes.ReplicationStatus);
Assert.Equal(StorageAccountType.StandardLRS, imageVersionFromGet.PublishingProfile.StorageAccountType);
Assert.Equal(StorageAccountType.StandardLRS,
imageVersionFromGet.PublishingProfile.TargetRegions.First().StorageAccountType);
Assert.NotNull(imageVersionFromGet.ReplicationStatus);
Assert.NotNull(imageVersionFromGet.ReplicationStatus.Summary);

Expand Down Expand Up @@ -316,8 +319,9 @@ private GalleryImageVersion GetTestInputGalleryImageVersion(string sourceImageId
ManagedImage = new ManagedArtifact { Id = sourceImageId }
},
ReplicaCount = 1,
StorageAccountType = StorageAccountType.StandardLRS,
TargetRegions = new List<TargetRegion> {
new TargetRegion { Name = galleryHomeLocation, RegionalReplicaCount = 1 }
new TargetRegion { Name = galleryHomeLocation, RegionalReplicaCount = 1, StorageAccountType = StorageAccountType.StandardLRS }
},
EndOfLifeDate = DateTime.Today.AddDays(10).Date
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Compute.Tests
{
public class VMIdentityTests : VMTestBase
{
[Fact]
[Fact(Skip = "Need to re-record after creating identity")]
public void TestVMIdentitySystemAssignedUserAssigned()
{
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void TestVMOperations()

VirtualMachine ephemeralVM;
string as2Name = as1Name + "_ephemeral";
CreateVM(rg1Name, as2Name, storageAccountName, imageRef, out ephemeralVM, hasManagedDisks: true, hasDiffDisks: true, vmSize: VirtualMachineSizeTypes.StandardDS1V2,
CreateVM(rg1Name, as2Name, storageAccountName, imageRef, out ephemeralVM, hasManagedDisks: true, hasDiffDisks: true, vmSize: VirtualMachineSizeTypes.StandardDS5V2,
osDiskStorageAccountType: StorageAccountTypes.StandardLRS, dataDiskStorageAccountType: StorageAccountTypes.StandardLRS);
m_CrpClient.VirtualMachines.Reimage(rg1Name, ephemeralVM.Name, tempDisk: true);
var captureParams = new VirtualMachineCaptureParameters
Expand Down Expand Up @@ -217,6 +217,56 @@ public void TestVMOperations_Redeploy()
}
}

/// <summary>
/// Covers following Operations:
/// Create RG
/// Create Storage Account
/// Create VM
/// Start VM
/// Shutdown VM with skipShutdown = true
/// Delete RG
/// </summary>
[Fact]
public void TestVMOperations_PowerOffWithSkipShutdown()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
EnsureClientsInitialized(context);

ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);

// Create resource group
string rg1Name = TestUtilities.GenerateName(TestPrefix) + 1;
string asName = TestUtilities.GenerateName("as");
string storageAccountName = TestUtilities.GenerateName(TestPrefix);
VirtualMachine inputVM1;

bool passed = false;
try
{
// Create Storage Account for this VM
var storageAccountOutput = CreateStorageAccount(rg1Name, storageAccountName);

VirtualMachine vm1 = CreateVM(rg1Name, asName, storageAccountOutput, imageRef,
out inputVM1);

m_CrpClient.VirtualMachines.Start(rg1Name, vm1.Name);
// Shutdown VM with SkipShutdown = true
m_CrpClient.VirtualMachines.PowerOff(rg1Name, vm1.Name, true);

passed = true;
}
finally
{
// Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
// of the test to cover deletion. CSM does persistent retrying over all RG resources.
var deleteRg1Response = m_ResourcesClient.ResourceGroups.BeginDeleteWithHttpMessagesAsync(rg1Name);
}

Assert.True(passed);
}
}

/// <summary>
/// Covers following Operations:
/// Create RG
Expand Down
45 changes: 42 additions & 3 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/VMScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,28 @@ public void TestVMScenarioOperations_ManagedDisks_UltraSSD()
}
}

/// <summary>
/// To record this test case, you need to run it in zone supported regions like eastus2euap.
/// </summary>
[Fact]
[Trait("Name", "TestVMScenarioOperations_PpgScenario")]
public void TestVMScenarioOperations_PpgScenario()
{
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
try
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap");
TestVMScenarioOperationsInternal("TestVMScenarioOperations_PpgScenario", hasManagedDisks: true, isPpgScenario: true);
}
finally
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
}
}

private void TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList<string> zones = null, string vmSize = "Standard_A0",
string osDiskStorageAccountType = "Standard_LRS", string dataDiskStorageAccountType = "Standard_LRS", bool? writeAcceleratorEnabled = null,
bool hasDiffDisks = false, bool callUpdateVM = false)
bool hasDiffDisks = false, bool callUpdateVM = false, bool isPpgScenario = false)
{
using (MockContext context = MockContext.Start(this.GetType().FullName, methodName))
{
Expand All @@ -161,6 +180,15 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged
var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
string asName = ComputeManagementTestUtilities.GenerateName("as");
string ppgName = null;
string expectedPpgReferenceId = null;

if (isPpgScenario)
{
ppgName = ComputeManagementTestUtilities.GenerateName("ppgtest");
expectedPpgReferenceId = Helpers.GetProximityPlacementGroupRef(m_subId, rgName, ppgName);
}

VirtualMachine inputVM;
try
{
Expand All @@ -170,7 +198,7 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged
}

CreateVM(rgName, asName, storageAccountName, imageRef, out inputVM, hasManagedDisks: hasManagedDisks,hasDiffDisks: hasDiffDisks, vmSize: vmSize, osDiskStorageAccountType: osDiskStorageAccountType,
dataDiskStorageAccountType: dataDiskStorageAccountType, writeAcceleratorEnabled: writeAcceleratorEnabled, zones: zones);
dataDiskStorageAccountType: dataDiskStorageAccountType, writeAcceleratorEnabled: writeAcceleratorEnabled, zones: zones, ppgName: ppgName);

// Instance view is not completely populated just after VM is provisioned. So we wait here for a few minutes to
// allow GA blob to populate.
Expand All @@ -186,16 +214,27 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged

bool hasUserDefinedAS = zones == null;

string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name);
var listResponse = m_CrpClient.VirtualMachines.List(rgName);
ValidateVM(inputVM, listResponse.FirstOrDefault(x => x.Name == inputVM.Name),
Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name), hasManagedDisks, hasUserDefinedAS, writeAcceleratorEnabled, hasDiffDisks);
expectedVMReferenceId, hasManagedDisks, hasUserDefinedAS, writeAcceleratorEnabled, hasDiffDisks, expectedPpgReferenceId: expectedPpgReferenceId);

var listVMSizesResponse = m_CrpClient.VirtualMachines.ListAvailableSizes(rgName, inputVM.Name);
Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks);

listVMSizesResponse = m_CrpClient.AvailabilitySets.ListAvailableSizes(rgName, asName);
Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks);

if(isPpgScenario)
{
ProximityPlacementGroup outProximityPlacementGroup = m_CrpClient.ProximityPlacementGroups.Get(rgName, ppgName);
string expectedAvSetReferenceId = Helpers.GetAvailabilitySetRef(m_subId, rgName, asName);
Assert.Equal(1, outProximityPlacementGroup.VirtualMachines.Count);
Assert.Equal(1, outProximityPlacementGroup.AvailabilitySets.Count);
Assert.Equal(expectedVMReferenceId, outProximityPlacementGroup.VirtualMachines.First().Id, StringComparer.OrdinalIgnoreCase);
Assert.Equal(expectedAvSetReferenceId, outProximityPlacementGroup.AvailabilitySets.First().Id, StringComparer.OrdinalIgnoreCase);
}

if (callUpdateVM)
{
VirtualMachineUpdate updateParams = new VirtualMachineUpdate()
Expand Down
57 changes: 52 additions & 5 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/VMTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ protected VirtualMachine CreateVM(
string osDiskStorageAccountType = "Standard_LRS",
string dataDiskStorageAccountType = "Standard_LRS",
bool? writeAcceleratorEnabled = null,
IList<string> zones = null)
IList<string> zones = null,
string ppgName = null)
{
try
{
Expand All @@ -241,7 +242,9 @@ protected VirtualMachine CreateVM(
subnetResponse,
getPublicIpAddressResponse != null ? getPublicIpAddressResponse.IpAddress : null);

string asetId = CreateAvailabilitySet(rgName, asName, hasManagedDisks);
string ppgId = ((ppgName != null) ? CreateProximityPlacementGroup(rgName, ppgName): null);

string asetId = CreateAvailabilitySet(rgName, asName, hasManagedDisks, ppgId: ppgId);

inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId, nicResponse.Id, hasManagedDisks, vmSize, osDiskStorageAccountType,
dataDiskStorageAccountType, writeAcceleratorEnabled);
Expand Down Expand Up @@ -300,7 +303,7 @@ protected VirtualMachine CreateVM(

// The intent here is to validate that the GET response is as expected.
var getResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name);
ValidateVM(inputVM, getResponse, expectedVMReferenceId, hasManagedDisks, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks, hasUserDefinedAS: zones == null);
ValidateVM(inputVM, getResponse, expectedVMReferenceId, hasManagedDisks, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks, hasUserDefinedAS: zones == null, expectedPpgReferenceId: ppgId);

return getResponse;
}
Expand Down Expand Up @@ -733,7 +736,7 @@ protected LoadBalancer CreatePublicLoadBalancerWithProbe(string rgName, PublicIP
return getLBResponse;
}

protected string CreateAvailabilitySet(string rgName, string asName, bool hasManagedDisks = false)
protected string CreateAvailabilitySet(string rgName, string asName, bool hasManagedDisks = false, string ppgId = null)
{
// Setup availability set
var inputAvailabilitySet = new AvailabilitySet
Expand All @@ -752,6 +755,11 @@ protected string CreateAvailabilitySet(string rgName, string asName, bool hasMan
}
};

if(ppgId != null)
{
inputAvailabilitySet.ProximityPlacementGroup = new Microsoft.Azure.Management.Compute.Models.SubResource() { Id = ppgId };
}

// Create an Availability Set and then create a VM inside this availability set
var asCreateOrUpdateResponse = m_CrpClient.AvailabilitySets.CreateOrUpdate(
rgName,
Expand All @@ -762,6 +770,35 @@ protected string CreateAvailabilitySet(string rgName, string asName, bool hasMan
return asetId;
}

static string CreateProximityPlacementGroup(string subId, string rgName, string ppgName, ComputeManagementClient client, string location)
{
// Setup ProximityPlacementGroup
var inputProximityPlacementGroup = new ProximityPlacementGroup
{
Location = location,
Tags = new Dictionary<string, string>()
{
{"RG", "rg"},
{"testTag", "1"},
},
ProximityPlacementGroupType = ProximityPlacementGroupType.Standard
};

// Create a ProximityPlacementGroup and then create a VM inside this ProximityPlacementGroup
ProximityPlacementGroup ppgCreateOrUpdateResponse = client.ProximityPlacementGroups.CreateOrUpdate(
rgName,
ppgName,
inputProximityPlacementGroup
);

return Helpers.GetProximityPlacementGroupRef(subId, rgName, ppgCreateOrUpdateResponse.Name);
}

protected string CreateProximityPlacementGroup(string rgName, string ppgName)
{
return CreateProximityPlacementGroup(m_subId, rgName, ppgName, m_CrpClient, m_location);
}

protected VirtualMachine CreateDefaultVMInput(string rgName, string storageAccountName, ImageReference imageRef, string asetId, string nicId, bool hasManagedDisks = false,
string vmSize = "Standard_A0", string osDiskStorageAccountType = "Standard_LRS", string dataDiskStorageAccountType = "Standard_LRS", bool? writeAcceleratorEnabled = null)
{
Expand Down Expand Up @@ -852,7 +889,7 @@ protected VirtualMachine CreateDefaultVMInput(string rgName, string storageAccou
}

protected void ValidateVM(VirtualMachine vm, VirtualMachine vmOut, string expectedVMReferenceId, bool hasManagedDisks = false, bool hasUserDefinedAS = true,
bool? writeAcceleratorEnabled = null, bool hasDiffDisks = false, string expectedLocation = null)
bool? writeAcceleratorEnabled = null, bool hasDiffDisks = false, string expectedLocation = null, string expectedPpgReferenceId = null)
{
Assert.True(vmOut.LicenseType == vm.LicenseType);

Expand Down Expand Up @@ -1026,6 +1063,16 @@ protected void ValidateVM(VirtualMachine vm, VirtualMachine vmOut, string expect

ValidatePlan(vm.Plan, vmOut.Plan);
Assert.NotNull(vmOut.VmId);

if(expectedPpgReferenceId != null)
{
Assert.NotNull(vmOut.ProximityPlacementGroup);
Assert.Equal(expectedPpgReferenceId, vmOut.ProximityPlacementGroup.Id, StringComparer.OrdinalIgnoreCase);
}
else
{
Assert.Null(vmOut.ProximityPlacementGroup);
}
}

protected void ValidateVMInstanceView(VirtualMachine vmIn, VirtualMachine vmOut, bool hasManagedDisks = false,
Expand Down
Loading

0 comments on commit 5153627

Please sign in to comment.