public async Task TestVMScaleSetMarketplace() { EnsureClientsInitialized(DefaultLocation); ImageReference dummyImageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var img = await GetMarketplaceImage(); Action <VirtualMachineScaleSet> useVMMImage = vmss => { vmss.VirtualMachineProfile.StorageProfile.ImageReference = new ImageReference { Publisher = vmmPublisherName, Offer = vmmOfferName, Sku = vmmSku, Version = "latest" }; vmss.Plan = new Plan { Name = img.Plan.Name, Product = img.Plan.Product, PromotionCode = null, Publisher = img.Plan.Publisher }; }; try { VirtualMachineScaleSet inputVMScaleSet; var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, dummyImageRef, vmScaleSetCustomizer : useVMMImage); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Response; inputVMScaleSet = getTwoVirtualMachineScaleSet.Input; // Validate the VMM Plan field ValidateMarketplaceVMScaleSetPlanField(vmScaleSet, img); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName)); } catch (Exception ex) { if (ex.Message.Contains("Legal terms have not been accepted for this item on this subscription.")) { return; } } }
//[Trait("Name", "TestVMScaleSetExtensionUpgradeAPIs")] public async Task TestVMScaleSetExtensionUpgradeAPIs() { EnsureClientsInitialized(LocationEastUs2); string rgName = Recording.GenerateAssetName(TestPrefix); string vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; // Windows VM image ImageReference imageRef = await GetPlatformVMImage(true); imageRef.Version = "latest"; var extension = GetTestVMSSVMExtension(); VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile() { Extensions = { extension, } }; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, extensionProfile, (vmScaleSet) => { vmScaleSet.Overprovision = false; vmScaleSet.UpgradePolicy.Mode = UpgradeMode.Automatic; }, createWithManagedDisks : true, createWithPublicIpAddress : false, createWithHealthProbe : true); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); await WaitForCompletionAsync(await VirtualMachineScaleSetRollingUpgradesOperations.StartStartExtensionUpgradeAsync(rgName, vmssName)); var rollingUpgradeStatus = await VirtualMachineScaleSetRollingUpgradesOperations.GetLatestAsync(rgName, vmssName); Assert.AreEqual(inputVMScaleSet.Sku.Capacity, rollingUpgradeStatus.Value.Progress.SuccessfulInstanceCount); }
//[Trait("Name", "TestVMScaleSetRollingUpgradeHistory")] public async Task TestVMScaleSetRollingUpgradeHistory() { EnsureClientsInitialized(LocationSouthCentralUs); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); imageRef.Version = "latest"; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, null, (vmScaleSet) => { vmScaleSet.Overprovision = false; vmScaleSet.UpgradePolicy.Mode = UpgradeMode.Rolling; }, createWithManagedDisks : true, createWithPublicIpAddress : false, createWithHealthProbe : true); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); WaitSeconds(600); var vmssStatus = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); await WaitForCompletionAsync(await VirtualMachineScaleSetRollingUpgradesOperations.StartStartOSUpgradeAsync(rgName, vmssName)); var rollingUpgrade = VirtualMachineScaleSetsOperations.GetOSUpgradeHistoryAsync(rgName, vmssName); var rollingUpgradeHistory = await rollingUpgrade.ToEnumerableAsync(); Assert.NotNull(rollingUpgradeHistory); Assert.True(rollingUpgradeHistory.Count() == 1); Assert.AreEqual(inputVMScaleSet.Sku.Capacity, rollingUpgradeHistory.First().Properties.Progress.SuccessfulInstanceCount); }
public async Task TestVMScaleSetUpdateOperations() { EnsureClientsInitialized(DefaultLocation); 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; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); inputVMScaleSet.Sku.Name = VirtualMachineSizeTypes.StandardA1.ToString(); VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile() { Extensions = { GetTestVMSSVMExtension(), } }; inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmScaleSet.Name)); }
public async Task TestVMScaleSetScalingOperations() { EnsureClientsInitialized(DefaultLocation); 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; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); // Scale Out VMScaleSet inputVMScaleSet.Sku.Capacity = 3; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); // Scale In VMScaleSet inputVMScaleSet.Sku.Capacity = 1; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmScaleSet.Name)); }
private async Task TestVMScaleSetOperationsInternal(bool hasManagedDisks = false) { ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; 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; // TODO: AutoRest skips the following methods - Start, Restart, PowerOff, Deallocate await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartStartAsync(rgName, vmScaleSet.Name)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartReimageAsync(rgName, vmScaleSet.Name)); if (hasManagedDisks) { await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartReimageAllAsync(rgName, vmScaleSet.Name)); } await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartRestartAsync(rgName, vmScaleSet.Name)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartPowerOffAsync(rgName, vmScaleSet.Name)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeallocateAsync(rgName, vmScaleSet.Name)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmScaleSet.Name)); 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)); }
//[Trait("Name", "TestVMScaleSetScenarioOperations_OrchestrationService")] public async Task TestVMScaleSetScenarioOperations_OrchestrationService() { EnsureClientsInitialized(LocationNorthEurope); 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; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); AutomaticRepairsPolicy automaticRepairsPolicy = new AutomaticRepairsPolicy() { Enabled = true }; var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, null, (vmScaleSet) => { vmScaleSet.Overprovision = false; }, createWithManagedDisks : true, createWithPublicIpAddress : false, createWithHealthProbe : true, automaticRepairsPolicy : automaticRepairsPolicy); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Response; inputVMScaleSet = getTwoVirtualMachineScaleSet.Input; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); var getInstanceViewResponse = (await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName)).Value; Assert.True(getInstanceViewResponse.OrchestrationServices.Count == 1); Assert.AreEqual("Running", getInstanceViewResponse.OrchestrationServices[0].ServiceState.ToString()); Assert.AreEqual("AutomaticRepairs", getInstanceViewResponse.OrchestrationServices[0].ServiceName.ToString()); ////TODO OrchestrationServiceStateInput orchestrationServiceStateInput = new OrchestrationServiceStateInput(OrchestrationServiceNames.AutomaticRepairs, OrchestrationServiceStateAction.Suspend); //OrchestrationServiceStateAction orchestrationServiceStateAction = new OrchestrationServiceStateAction(); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartSetOrchestrationServiceStateAsync(rgName, vmssName, orchestrationServiceStateInput)); getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); Assert.AreEqual(OrchestrationServiceState.Suspended.ToString(), getInstanceViewResponse.OrchestrationServices[0].ServiceState.ToString()); orchestrationServiceStateInput = new OrchestrationServiceStateInput(OrchestrationServiceNames.AutomaticRepairs, OrchestrationServiceStateAction.Resume); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartSetOrchestrationServiceStateAsync(rgName, vmssName, orchestrationServiceStateInput)); getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); Assert.AreEqual(OrchestrationServiceState.Running.ToString(), getInstanceViewResponse.OrchestrationServices[0].ServiceState.ToString()); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName)); }
//[Trait("Name", "TestVMScaleSetScenarioOperations_AutomaticRepairsPolicyTest")] public async Task TestVMScaleSetScenarioOperations_AutomaticRepairsPolicyTest() { EnsureClientsInitialized(LocationEastUs2); 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; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, null, (vmScaleSet) => { vmScaleSet.Overprovision = false; }, createWithManagedDisks : true, createWithPublicIpAddress : false, createWithHealthProbe : true); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Response; inputVMScaleSet = getTwoVirtualMachineScaleSet.Input; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); // Set Automatic Repairs to true inputVMScaleSet.AutomaticRepairsPolicy = new AutomaticRepairsPolicy() { Enabled = true }; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); Assert.NotNull(getResponse.AutomaticRepairsPolicy); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); // Update Automatic Repairs default values inputVMScaleSet.AutomaticRepairsPolicy = new AutomaticRepairsPolicy() { Enabled = true, GracePeriod = "PT35M" }; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); Assert.NotNull(getResponse.AutomaticRepairsPolicy); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); // Set automatic repairs to null inputVMScaleSet.AutomaticRepairsPolicy = null; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); Assert.NotNull(getResponse.AutomaticRepairsPolicy); Assert.True(getResponse.AutomaticRepairsPolicy.Enabled == true); Assert.AreEqual("PT35M", getResponse.AutomaticRepairsPolicy.GracePeriod); // Disable Automatic Repairs inputVMScaleSet.AutomaticRepairsPolicy = new AutomaticRepairsPolicy() { Enabled = false }; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); Assert.NotNull(getResponse.AutomaticRepairsPolicy); Assert.True(getResponse.AutomaticRepairsPolicy.Enabled == false); }
//[Trait("Name", "TestVMScaleSetRollingUpgrade")] public async Task TestVMScaleSetRollingUpgrade() { EnsureClientsInitialized(LocationSouthCentralUs); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile() { Extensions = { GetTestVMSSVMExtension(), } }; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, null, (vmScaleSet) => { vmScaleSet.Overprovision = false; vmScaleSet.UpgradePolicy.Mode = UpgradeMode.Rolling; }, createWithManagedDisks : true, createWithPublicIpAddress : false, createWithHealthProbe : true); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); var getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); Assert.NotNull(getInstanceViewResponse); ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse); var getVMInstanceViewResponse = await VirtualMachineScaleSetVMsOperations.GetInstanceViewAsync(rgName, vmssName, "0"); Assert.NotNull(getVMInstanceViewResponse); Assert.NotNull(getVMInstanceViewResponse.Value.VmHealth); Assert.AreEqual("HealthState/healthy", getVMInstanceViewResponse.Value.VmHealth.Status.Code); // Update the VMSS by adding an extension WaitSeconds(600); var vmssStatus = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); Assert.NotNull(getInstanceViewResponse); ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName)); }
//[Trait("Name", "TestVMScaleSetAutomaticOSUpgradePolicies")] public async Task TestVMScaleSetAutomaticOSUpgradePolicies() { EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); imageRef.Version = "latest"; // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, null, (vmScaleSet) => { vmScaleSet.Overprovision = false; vmScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy = new AutomaticOSUpgradePolicy() { DisableAutomaticRollback = false }; }, createWithManagedDisks : true, createWithPublicIpAddress : false, createWithHealthProbe : true); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); // Set Automatic OS Upgrade inputVMScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy.EnableAutomaticOSUpgrade = true; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); // with automatic OS upgrade policy as null inputVMScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy = null; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); Assert.NotNull(getResponse.UpgradePolicy.AutomaticOSUpgradePolicy); Assert.True(getResponse.UpgradePolicy.AutomaticOSUpgradePolicy.DisableAutomaticRollback == false); Assert.True(getResponse.UpgradePolicy.AutomaticOSUpgradePolicy.EnableAutomaticOSUpgrade == true); // Toggle Disable Auto Rollback inputVMScaleSet.UpgradePolicy.AutomaticOSUpgradePolicy = new AutomaticOSUpgradePolicy() { DisableAutomaticRollback = true, EnableAutomaticOSUpgrade = false }; await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet); getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName); ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true); }
private async Task TestVMScaleSetPriorityOperationsInternal( string priority, BillingProfile billingProfile = null, VirtualMachineEvictionPolicyTypes?evictionPolicy = null, bool hasManagedDisks = false, IList <string> zones = null ) { string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); // Create resource group var rgName = Recording.GenerateAssetName(TestPrefix); var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, null, (vmScaleSet) => { vmScaleSet.Overprovision = true; vmScaleSet.VirtualMachineProfile.Priority = priority; vmScaleSet.VirtualMachineProfile.EvictionPolicy = evictionPolicy; vmScaleSet.VirtualMachineProfile.BillingProfile = billingProfile; vmScaleSet.Sku.Name = VirtualMachineSizeTypes.StandardA1.ToString(); vmScaleSet.Sku.Tier = "Standard"; vmScaleSet.Sku.Capacity = 2; }, createWithManagedDisks : hasManagedDisks, zones : zones); VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Response; inputVMScaleSet = getTwoVirtualMachineScaleSet.Input; ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks); var getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName); Assert.NotNull(getInstanceViewResponse); ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse); var listResponse = await(VirtualMachineScaleSetsOperations.ListAsync(rgName)).ToEnumerableAsync(); ValidateVMScaleSet( inputVMScaleSet, listResponse.FirstOrDefault(x => x.Name == vmssName), hasManagedDisks); var listSkusResp = VirtualMachineScaleSetsOperations.ListSkusAsync(rgName, vmssName); var listSkusResponse = await listSkusResp.ToEnumerableAsync(); Assert.NotNull(listSkusResponse); Assert.False(listSkusResponse.Count() == 0); Assert.AreEqual(inputVMScaleSet.VirtualMachineProfile.Priority.ToString(), priority); //Assert.Same(inputVMScaleSet.VirtualMachineProfile.Priority.ToString(), priority); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName)); }
private async Task TestDiskEncryptionOnScaleSetVMInternal(bool hasManagedDisks = true, bool useVmssExtension = true) { // Get platform image for VMScaleSet create ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix); string vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); var dnsname = Recording.GenerateAssetName("dnsname"); // Create ADE extension to enable disk encryption VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile() { Extensions = new List <VirtualMachineScaleSetExtension>() { GetAzureDiskEncryptionExtension(), } }; bool testSucceeded = false; StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var vnetResponse = await CreateVNETWithSubnets(rgName, 2); var vmssSubnet = vnetResponse.Subnets[1]; var publicipConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration("pip1"); publicipConfiguration.IdleTimeoutInMinutes = 10; publicipConfiguration.DnsSettings = new VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings(dnsname); VirtualMachineScaleSet inputVMScaleSet; var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName, vmssName, storageAccountOutput, imageRef, useVmssExtension?extensionProfile : null, (vmss) => { vmss.Sku.Name = VirtualMachineSizeTypes.StandardA3.ToString(); vmss.Sku.Tier = "Standard"; vmss.VirtualMachineProfile.StorageProfile.OsDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionTypes.FromImage); vmss.VirtualMachineProfile.NetworkProfile .NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration = publicipConfiguration; }, createWithManagedDisks : hasManagedDisks, createWithPublicIpAddress : false, subnet : vmssSubnet); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; VirtualMachineScaleSetVMInstanceView vmInstanceViewResponse = await VirtualMachineScaleSetVMsOperations.GetInstanceViewAsync(rgName, vmScaleSet.Name, "0"); Assert.True(vmInstanceViewResponse != null, "VMScaleSetVM not returned."); ValidateEncryptionSettingsInVMScaleSetVMInstanceView(vmInstanceViewResponse, hasManagedDisks); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName)); testSucceeded = true; Assert.True(testSucceeded); }
public async Task TestVMScaleSetPatchOperations() { EnsureClientsInitialized(DefaultLocation); 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; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist")); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); // Adding an extension to the VMScaleSet. We will use Patch to update this. VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile() { Extensions = { GetTestVMSSVMExtension(), } }; VirtualMachineScaleSetUpdate patchVMScaleSet = new VirtualMachineScaleSetUpdate() { VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile() { ExtensionProfile = extensionProfile, }, }; await PatchVMScaleSet(rgName, vmssName, patchVMScaleSet); // Update the inputVMScaleSet and then compare it with response to verify the result. inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile; getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); // Scaling the VMScaleSet now to 3 instances VirtualMachineScaleSetUpdate patchVMScaleSet2 = new VirtualMachineScaleSetUpdate() { Sku = new Sku() { Capacity = 3, }, }; await PatchVMScaleSet(rgName, vmssName, patchVMScaleSet2); // Validate that ScaleSet Scaled to 3 instances inputVMScaleSet.Sku.Capacity = 3; getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmScaleSet.Name); ValidateVMScaleSet(inputVMScaleSet, getResponse); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmScaleSet.Name)); }