Exemplo n.º 1
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));
        }
        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));
        }