private async Task TestVMScaleSetExtensionsImpl()
        {
            // Create resource group
            string rgName             = Recording.GenerateAssetName(TestPrefix) + 1;
            var    vmssName           = Recording.GenerateAssetName("vmss");
            string storageAccountName = Recording.GenerateAssetName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;
            bool passed = false;

            ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true);

            var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName,
                vmssName,
                storageAccountOutput,
                imageRef);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Response;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Input;
            VirtualMachineScaleSetExtension vmssExtension = GetTestVMSSVMExtension();

            vmssExtension.ForceUpdateTag = "RerunExtension";
            var response = await WaitForCompletionAsync(await VirtualMachineScaleSetExtensionsOperations.StartCreateOrUpdateAsync(rgName, vmssName, vmssExtension.Name, vmssExtension));

            ValidateVmssExtension(vmssExtension, response.Value);

            // Perform a Get operation on the extension
            var getVmssExtResponse = await VirtualMachineScaleSetExtensionsOperations.GetAsync(rgName, vmssName, vmssExtension.Name);

            ValidateVmssExtension(vmssExtension, getVmssExtResponse);

            // Validate the extension instance view in the VMSS instance-view
            var getVmssWithInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName);

            ValidateVmssExtensionInstanceView(getVmssWithInstanceViewResponse.Value.Extensions.FirstOrDefault());

            // Update an extension in the VMSS
            vmssExtension.Settings = string.Empty;
            var patchVmssExtsResponse = await WaitForCompletionAsync(await VirtualMachineScaleSetExtensionsOperations.StartCreateOrUpdateAsync(rgName, vmssName, vmssExtension.Name, vmssExtension));

            ValidateVmssExtension(vmssExtension, patchVmssExtsResponse.Value);

            // Perform a List operation on vmss extensions
            var listVmssExts         = VirtualMachineScaleSetExtensionsOperations.ListAsync(rgName, vmssName);
            var listVmssExtsResponse = await listVmssExts.ToEnumerableAsync();

            ValidateVmssExtension(vmssExtension, listVmssExtsResponse.FirstOrDefault(c => c.ForceUpdateTag == "RerunExtension"));

            // Validate the extension delete API
            await WaitForCompletionAsync(await VirtualMachineScaleSetExtensionsOperations.StartDeleteAsync(rgName, vmssName, vmssExtension.Name));

            passed = true;
            Assert.True(passed);
        }
Exemplo n.º 2
0
        //[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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        //[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));
        }
Exemplo n.º 5
0
        //[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));
        }
        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));
        }