public async Task TestVMScaleSetVMOperations_Put() { bool passed = false; EnsureClientsInitialized("westus2"); InitializeCommon(); instanceId = "0"; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, createWithManagedDisks : true, machineSizeType : VirtualMachineSizeTypes.StandardA1V2.ToString()); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; VirtualMachineScaleSetVM vmssVM = await VirtualMachineScaleSetVMsOperations.GetAsync(rgName, vmScaleSet.Name, instanceId); VirtualMachineScaleSetVM vmScaleSetVMModel = GenerateVMScaleSetVMModel(vmScaleSet, instanceId, hasManagedDisks: true); ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, vmssVM, hasManagedDisks: true); await AttachDataDiskToVMScaleSetVM(vmssVM, vmScaleSetVMModel, 2); VirtualMachineScaleSetVM vmssVMReturned = (await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartUpdateAsync(rgName, vmScaleSet.Name, vmssVM.InstanceId, vmssVM))).Value; ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, vmssVMReturned, hasManagedDisks: true); passed = true; Assert.True(passed); }
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 TestVMScaleSetVMOperationsInternal(bool hasManagedDisks = false) { InitializeCommon(); instanceId = "0"; bool passed = false; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, createWithManagedDisks : hasManagedDisks); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var getResponse = (await VirtualMachineScaleSetVMsOperations.GetAsync(rgName, vmScaleSet.Name, instanceId)).Value; var imageReference = getResponse.StorageProfile.ImageReference; Assert.NotNull(imageReference?.ExactVersion); Assert.AreEqual(imageReference.Version, imageReference.ExactVersion); VirtualMachineScaleSetVM vmScaleSetVMModel = GenerateVMScaleSetVMModel(vmScaleSet, instanceId, hasManagedDisks); ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, getResponse, hasManagedDisks); var getInstanceViewResponse = await VirtualMachineScaleSetVMsOperations.GetInstanceViewAsync(rgName, vmScaleSet.Name, instanceId); Assert.True(getInstanceViewResponse != null, "VMScaleSetVM not returned."); ValidateVMScaleSetVMInstanceView(getInstanceViewResponse, hasManagedDisks); //var query = new Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM>(); //query.SetFilter(vm => vm.LatestModelApplied == true); var query = "properties/latestModelApplied eq true"; var listResponse = await(VirtualMachineScaleSetVMsOperations.ListAsync(rgName, vmssName, query)).ToEnumerableAsync(); Assert.False(listResponse == null, "VMScaleSetVMs not returned"); Assert.True(listResponse.Count() == inputVMScaleSet.Sku.Capacity); query = null; //query.Filter = null; //query.Expand = "instanceView"; listResponse = await(VirtualMachineScaleSetVMsOperations.ListAsync(rgName, vmssName, query, null, "instanceView")).ToEnumerableAsync(); Assert.False(listResponse == null, "VMScaleSetVMs not returned"); Assert.True(listResponse.Count() == inputVMScaleSet.Sku.Capacity); await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartStartAsync(rgName, vmScaleSet.Name, instanceId)); await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartReimageAsync(rgName, vmScaleSet.Name, instanceId)); if (hasManagedDisks) { await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartReimageAllAsync(rgName, vmScaleSet.Name, instanceId)); } await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartRestartAsync(rgName, vmScaleSet.Name, instanceId)); await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartPowerOffAsync(rgName, vmScaleSet.Name, instanceId)); await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartDeallocateAsync(rgName, vmScaleSet.Name, instanceId)); await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartDeleteAsync(rgName, vmScaleSet.Name, instanceId)); passed = true; Assert.True(passed); }