private async Task VerifyPutPatchGetAndDeleteWithInvalidValues_Failure() { var ProximityPlacementGroupName = Recording.GenerateAssetName("testppg"); var inputProximityPlacementGroup = new ProximityPlacementGroup("") { Tags = { { "RG", "rg" }, { "testTag", "1" }, }, }; // Put and expect failure ProximityPlacementGroup expectedProximityPlacementGroup = null; async void CreateAndExpectFailure() { try { // Create and expect success. expectedProximityPlacementGroup = await ProximityPlacementGroupsOperations.CreateOrUpdateAsync( m_resourceGroup1Name, ProximityPlacementGroupName, inputProximityPlacementGroup); } catch (Exception ex) { Assert.NotNull(ex); //Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest, $"Expecting HttpStatusCode {HttpStatusCode.BadRequest}, while actual HttpStatusCode is {ex.Response.StatusCode}."); } Assert.True(expectedProximityPlacementGroup == null); } //Verify failure when location is invalid CreateAndExpectFailure(); //Verify failure when ProximityPlacementGroupType is invalid inputProximityPlacementGroup.Location = m_location; inputProximityPlacementGroup.ProximityPlacementGroupType = "Invalid"; CreateAndExpectFailure(); //Verify success when ProximityPlacementGroup is valid inputProximityPlacementGroup.ProximityPlacementGroupType = ProximityPlacementGroupType.Standard; expectedProximityPlacementGroup = await ProximityPlacementGroupsOperations.CreateOrUpdateAsync( m_resourceGroup1Name, ProximityPlacementGroupName, inputProximityPlacementGroup); ValidateProximityPlacementGroup(inputProximityPlacementGroup, expectedProximityPlacementGroup, ProximityPlacementGroupName); // Get and expect success. expectedProximityPlacementGroup = await ProximityPlacementGroupsOperations.GetAsync(m_resourceGroup1Name, ProximityPlacementGroupName); ValidateProximityPlacementGroup(inputProximityPlacementGroup, expectedProximityPlacementGroup, ProximityPlacementGroupName); // Clean up await ProximityPlacementGroupsOperations.DeleteAsync(m_resourceGroup1Name, ProximityPlacementGroupName); }
private async void ValidateResults(ProximityPlacementGroup outputProximityPlacementGroup, ProximityPlacementGroup inputProximityPlacementGroup, string resourceGroupName, string inputProximityPlacementGroupName) { string expectedProximityPlacementGroupId = Helpers.GetProximityPlacementGroupRef(m_subId, resourceGroupName, inputProximityPlacementGroupName); Assert.True(outputProximityPlacementGroup.Name == inputProximityPlacementGroupName, "ProximityPlacementGroup.Name mismatch between request and response."); Assert.True(outputProximityPlacementGroup.Location.ToLower() == this.m_location.ToLower() || outputProximityPlacementGroup.Location.ToLower() == inputProximityPlacementGroup.Location.ToLower(), "ProximityPlacementGroup.Location mismatch between request and response."); ValidateProximityPlacementGroup(inputProximityPlacementGroup, outputProximityPlacementGroup, inputProximityPlacementGroupName); // GET ProximityPlacementGroup var getResponse = (await ProximityPlacementGroupsOperations.GetAsync(resourceGroupName, inputProximityPlacementGroupName)).Value; ValidateProximityPlacementGroup(inputProximityPlacementGroup, getResponse, inputProximityPlacementGroupName); }
private async Task 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 isPpgScenario = false, string diskEncryptionSetId = null) { var imageRef = await GetPlatformVMImage(useWindowsImage : true); const string expectedOSName = "Windows Server 2012 R2 Datacenter", expectedOSVersion = "Microsoft Windows NT 6.3.9600.0", expectedComputerName = ComputerName; // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); string storageAccountName = Recording.GenerateAssetName(TestPrefix); string asName = Recording.GenerateAssetName("as"); string ppgName = null; string expectedPpgReferenceId = null; if (isPpgScenario) { ppgName = Recording.GenerateAssetName("ppgtest"); expectedPpgReferenceId = Helpers.GetProximityPlacementGroupRef(m_subId, rgName, ppgName); } VirtualMachine inputVM; if (!hasManagedDisks) { await CreateStorageAccount(rgName, storageAccountName); } var returnTwoVM = await CreateVM(rgName, asName, storageAccountName, imageRef, hasManagedDisks : hasManagedDisks, hasDiffDisks : hasDiffDisks, vmSize : vmSize, osDiskStorageAccountType : osDiskStorageAccountType, dataDiskStorageAccountType : dataDiskStorageAccountType, writeAcceleratorEnabled : writeAcceleratorEnabled, zones : zones, ppgName : ppgName, diskEncryptionSetId : diskEncryptionSetId); //VirtualMachine outVM = returnTwoVM.Item1; inputVM = returnTwoVM.Input; string inputVMName = returnTwoVM.Name; // 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. WaitMinutes(5); var getVMWithInstanceViewResponse = (await VirtualMachinesOperations.GetAsync(rgName, inputVMName)).Value; Assert.True(getVMWithInstanceViewResponse != null, "VM in Get"); if (diskEncryptionSetId != null) { Assert.True(getVMWithInstanceViewResponse.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet != null, "OsDisk.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getVMWithInstanceViewResponse.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "OsDisk.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); Assert.AreEqual(1, getVMWithInstanceViewResponse.StorageProfile.DataDisks.Count); Assert.True(getVMWithInstanceViewResponse.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet != null, ".DataDisks.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getVMWithInstanceViewResponse.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "DataDisks.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); } ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion); var getVMInstanceViewResponse = await VirtualMachinesOperations.InstanceViewAsync(rgName, inputVMName); Assert.True(getVMInstanceViewResponse != null, "VM in InstanceView"); ValidateVMInstanceView(inputVM, getVMInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion); bool hasUserDefinedAS = zones == null; string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVMName); var listResponse = await(VirtualMachinesOperations.ListAsync(rgName)).ToEnumerableAsync(); ValidateVM(inputVM, listResponse.FirstOrDefault(x => x.Name == inputVMName), expectedVMReferenceId, hasManagedDisks, hasUserDefinedAS, writeAcceleratorEnabled, hasDiffDisks, expectedPpgReferenceId: expectedPpgReferenceId); var listVMSizesResponse = await(VirtualMachinesOperations.ListAvailableSizesAsync(rgName, inputVMName)).ToEnumerableAsync(); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); listVMSizesResponse = await(AvailabilitySetsOperations.ListAvailableSizesAsync(rgName, asName)).ToEnumerableAsync(); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); if (isPpgScenario) { ProximityPlacementGroup outProximityPlacementGroup = await ProximityPlacementGroupsOperations.GetAsync(rgName, ppgName); string expectedAvSetReferenceId = Helpers.GetAvailabilitySetRef(m_subId, rgName, asName); Assert.AreEqual(1, outProximityPlacementGroup.VirtualMachines.Count); Assert.AreEqual(1, outProximityPlacementGroup.AvailabilitySets.Count); Assert.AreEqual(expectedVMReferenceId, outProximityPlacementGroup.VirtualMachines.First().Id); Assert.AreEqual(expectedAvSetReferenceId, outProximityPlacementGroup.AvailabilitySets.First().Id); //Assert.Equal(expectedVMReferenceId, outProximityPlacementGroup.VirtualMachines.First().Id, StringComparer.OrdinalIgnoreCase); //Assert.Equal(expectedAvSetReferenceId, outProximityPlacementGroup.AvailabilitySets.First().Id, StringComparer.OrdinalIgnoreCase); } if (callUpdateVM) { VirtualMachineUpdate updateParams = new VirtualMachineUpdate(); updateParams.Tags.InitializeFrom(inputVM.Tags); string updateKey = "UpdateTag"; updateParams.Tags.Add(updateKey, "UpdateTagValue"); VirtualMachine updateResponse = await WaitForCompletionAsync(await VirtualMachinesOperations.StartUpdateAsync(rgName, inputVMName, updateParams)); Assert.True(updateResponse.Tags.ContainsKey(updateKey)); } }
private async Task TestScaleSetOperationsInternal(string vmSize = null, bool hasManagedDisks = false, bool useVmssExtension = true, bool hasDiffDisks = false, IList <string> zones = null, int?osDiskSizeInGB = null, bool isPpgScenario = false, bool?enableUltraSSD = false, Action <VirtualMachineScaleSet> vmScaleSetCustomizer = null, Action <VirtualMachineScaleSet> vmScaleSetValidator = null, string diskEncryptionSetId = null) { ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile() { Extensions = { GetTestVMSSVMExtension(), } }; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); string ppgId = null; string ppgName = null; if (isPpgScenario) { ppgName = Recording.GenerateAssetName("ppgtest"); ppgId = await CreateProximityPlacementGroup(rgName, ppgName); } var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, useVmssExtension?extensionProfile : null, (vmScaleSet) => { vmScaleSet.Overprovision = true; if (!String.IsNullOrEmpty(vmSize)) { vmScaleSet.Sku.Name = vmSize; } vmScaleSetCustomizer?.Invoke(vmScaleSet); }, createWithManagedDisks : hasManagedDisks, hasDiffDisks : hasDiffDisks, zones : zones, osDiskSizeInGB : osDiskSizeInGB, ppgId : ppgId, enableUltraSSD : enableUltraSSD, diskEncryptionSetId : diskEncryptionSetId); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Response; inputVMScaleSet = getTwoVirtualMachineScaleSet.Input; if (diskEncryptionSetId != null) { Assert.True(getResponse.VirtualMachineProfile.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet != null, "OsDisk.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getResponse.VirtualMachineProfile.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "OsDisk.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); Assert.AreEqual(1, getResponse.VirtualMachineProfile.StorageProfile.DataDisks.Count); Assert.True(getResponse.VirtualMachineProfile.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet != null, ".DataDisks.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getResponse.VirtualMachineProfile.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "DataDisks.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); } ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks, ppgId: ppgId); var getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); Assert.NotNull(getInstanceViewResponse); ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse); if (isPpgScenario) { ProximityPlacementGroup outProximityPlacementGroup = await ProximityPlacementGroupsOperations.GetAsync(rgName, ppgName); Assert.AreEqual(1, outProximityPlacementGroup.VirtualMachineScaleSets.Count); string expectedVmssReferenceId = Helpers.GetVMScaleSetReferenceId(m_subId, rgName, vmssName); Assert.AreEqual(expectedVmssReferenceId.ToLower(), outProximityPlacementGroup.VirtualMachineScaleSets.First().Id.ToLower()); } var listResponse = await(VirtualMachineScaleSetsOperations.ListAsync(rgName)).ToEnumerableAsync(); ValidateVMScaleSet(inputVMScaleSet, listResponse.FirstOrDefault(x => x.Name == vmssName), hasManagedDisks); var listSkusResponse = await(VirtualMachineScaleSetsOperations.ListSkusAsync(rgName, vmssName)).ToEnumerableAsync(); Assert.NotNull(listSkusResponse); Assert.False(listSkusResponse.Count() == 0); if (zones != null) { var query = "properties/latestModelApplied eq true"; var listVMsResponse = await(VirtualMachineScaleSetVMsOperations.ListAsync(rgName, vmssName, query)).ToEnumerableAsync(); Assert.False(listVMsResponse == null, "VMScaleSetVMs not returned"); Assert.True(listVMsResponse.Count() == inputVMScaleSet.Sku.Capacity); foreach (var vmScaleSetVM in listVMsResponse) { string instanceId = vmScaleSetVM.InstanceId; var getVMResponse = await VirtualMachineScaleSetVMsOperations.GetAsync(rgName, vmssName, instanceId); ValidateVMScaleSetVM(inputVMScaleSet, instanceId, getVMResponse, hasManagedDisks); } } vmScaleSetValidator?.Invoke(getResponse); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName)); }
private async Task VerifyProximityPlacementGroupColocationStatusView() { var ppgName = Recording.GenerateAssetName("testppg"); string asName = Recording.GenerateAssetName("testas"); string vmssName = Recording.GenerateAssetName("testvmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); var inputProximityPlacementGroup = new ProximityPlacementGroup(m_location) { Tags = { { "RG", "rg" }, { "testTag", "1" }, }, ProximityPlacementGroupType = ProximityPlacementGroupType.Standard }; var expectedProximityPlacementGroup = new ProximityPlacementGroup(m_location) { Tags = { { "RG", "rg" }, { "testTag", "1" }, }, ProximityPlacementGroupType = ProximityPlacementGroupType.Standard }; // Create and expect success. ProximityPlacementGroup outProximityPlacementGroup = await ProximityPlacementGroupsOperations.CreateOrUpdateAsync(m_resourceGroup1Name, ppgName, inputProximityPlacementGroup); ValidateProximityPlacementGroup(expectedProximityPlacementGroup, outProximityPlacementGroup, ppgName); VirtualMachine inputVM; var returnTwoVM = await CreateVM(m_resourceGroup1Name, asName, storageAccountName, imageRef, hasManagedDisks : true, hasDiffDisks : false, vmSize : "Standard_A0", osDiskStorageAccountType : "Standard_LRS", dataDiskStorageAccountType : "Standard_LRS", writeAcceleratorEnabled : false, zones : null, ppgName : ppgName, diskEncryptionSetId : null); VirtualMachine outVM = returnTwoVM.Item1; inputVM = returnTwoVM.Item2; // Get and expect success. outProximityPlacementGroup = await ProximityPlacementGroupsOperations.GetAsync(m_resourceGroup1Name, ppgName, includeColocationStatus : "true"); InstanceViewStatus expectedInstanceViewStatus = new InstanceViewStatus { Code = "ColocationStatus/Aligned", Level = StatusLevelTypes.Info, DisplayStatus = "Aligned", Message = "All resources in the proximity placement group are aligned." }; expectedProximityPlacementGroup = new ProximityPlacementGroup(null, null, null, m_location, new Dictionary <string, string>() { { "RG", "rg" }, { "testTag", "1" }, }, ProximityPlacementGroupType.Standard, new List <SubResourceWithColocationStatus> { new SubResourceWithColocationStatus(outVM.Id, null) }, null, new List <SubResourceWithColocationStatus> { new SubResourceWithColocationStatus(outVM.AvailabilitySet.Id, null) }, null ); ValidateProximityPlacementGroup(expectedProximityPlacementGroup, outProximityPlacementGroup, ppgName); ValidateColocationStatus(expectedInstanceViewStatus, outProximityPlacementGroup.ColocationStatus); }
private async void VerifyPutPatchGetAndDeleteOperations_Scenarios(ProximityPlacementGroup inputProximityPlacementGroup, ProximityPlacementGroup expectedProximityPlacementGroup) { var proximityPlacementGroupName = Recording.GenerateAssetName("testppg"); // Create and expect success. ProximityPlacementGroup outProximityPlacementGroup = await ProximityPlacementGroupsOperations.CreateOrUpdateAsync(m_resourceGroup1Name, proximityPlacementGroupName, inputProximityPlacementGroup); ValidateProximityPlacementGroup(expectedProximityPlacementGroup, outProximityPlacementGroup, proximityPlacementGroupName); // Update and expect success. inputProximityPlacementGroup.Tags.Add("UpdateTag1", "updateValue1"); outProximityPlacementGroup = await ProximityPlacementGroupsOperations.CreateOrUpdateAsync(m_resourceGroup1Name, proximityPlacementGroupName, inputProximityPlacementGroup); ValidateProximityPlacementGroup(expectedProximityPlacementGroup, outProximityPlacementGroup, proximityPlacementGroupName); // Get and expect success. outProximityPlacementGroup = await ProximityPlacementGroupsOperations.GetAsync(m_resourceGroup1Name, proximityPlacementGroupName); ValidateProximityPlacementGroup(expectedProximityPlacementGroup, outProximityPlacementGroup, proximityPlacementGroupName); // Put and expect failure try { //Updating ProximityPlacementGroupType in inputProximityPlacementGroup for a Update call. if (expectedProximityPlacementGroup.ProximityPlacementGroupType == ProximityPlacementGroupType.Standard) { inputProximityPlacementGroup.ProximityPlacementGroupType = ProximityPlacementGroupType.Ultra; } else { inputProximityPlacementGroup.ProximityPlacementGroupType = ProximityPlacementGroupType.Standard; } outProximityPlacementGroup = null; outProximityPlacementGroup = await ProximityPlacementGroupsOperations.CreateOrUpdateAsync(m_resourceGroup1Name, proximityPlacementGroupName, inputProximityPlacementGroup); } catch (Exception ex) { //if (ex.StatusCode == HttpStatusCode.Conflict) //{ // Assert.AreEqual("Changing property 'proximityPlacementGroup.properties.proximityPlacementGroupType' is not allowed.", ex.Message ); //} //else if (ex.Response.StatusCode == HttpStatusCode.BadRequest) //{ // Assert.Equal("The subscription is not registered for private preview of Ultra Proximity Placement Groups.", ex.Message, StringComparer.OrdinalIgnoreCase); //} //else //{ // Console.WriteLine($"Expecting HttpStatusCode { HttpStatusCode.Conflict} or { HttpStatusCode.BadRequest}, while actual HttpStatusCode is { ex.Response.StatusCode}."); // throw; //} Console.WriteLine($"Expecting HttpStatusCode { HttpStatusCode.Conflict} or { HttpStatusCode.BadRequest}, while actual HttpStatusCode is { ex.Message}."); throw; } Assert.True(outProximityPlacementGroup == null, "ProximityPlacementGroup in response should be null."); //Patch and expect success UpdateResource proximityPlacementGroupUpdate = new UpdateResource(); proximityPlacementGroupUpdate.Tags.InitializeFrom(inputProximityPlacementGroup.Tags); //Note: Same Tags object is referred in proximityPlacementGroupUpdate and expectedProximityPlacementGroup, //hence this will also update tags in expectedProximityPlacementGroup. proximityPlacementGroupUpdate.Tags.Add("UpdateTag2", "updateValue2"); outProximityPlacementGroup = await ProximityPlacementGroupsOperations.UpdateAsync(m_resourceGroup1Name, proximityPlacementGroupName, proximityPlacementGroupUpdate); ValidateProximityPlacementGroup(expectedProximityPlacementGroup, outProximityPlacementGroup, proximityPlacementGroupName); // Clean up await ProximityPlacementGroupsOperations.DeleteAsync(m_resourceGroup1Name, proximityPlacementGroupName); }