Exemplo n.º 1
0
 internal VirtualMachineScaleSetVmData(ResourceIdentifier id, string name, ResourceType type, IDictionary <string, string> tags, AzureLocation location, string instanceId, Models.Sku sku, Models.Plan plan, IReadOnlyList <VirtualMachineExtensionData> resources, IReadOnlyList <string> zones, bool?latestModelApplied, string vmId, VirtualMachineScaleSetVMInstanceView instanceView, HardwareProfile hardwareProfile, StorageProfile storageProfile, AdditionalCapabilities additionalCapabilities, OSProfile osProfile, SecurityProfile securityProfile, NetworkProfile networkProfile, VirtualMachineScaleSetVMNetworkProfileConfiguration networkProfileConfiguration, DiagnosticsProfile diagnosticsProfile, WritableSubResource availabilitySet, string provisioningState, string licenseType, string modelDefinitionApplied, VirtualMachineScaleSetVMProtectionPolicy protectionPolicy, string userData) : base(id, name, type, tags, location)
 {
     InstanceId                  = instanceId;
     Sku                         = sku;
     Plan                        = plan;
     Resources                   = resources;
     Zones                       = zones;
     LatestModelApplied          = latestModelApplied;
     VmId                        = vmId;
     InstanceView                = instanceView;
     HardwareProfile             = hardwareProfile;
     StorageProfile              = storageProfile;
     AdditionalCapabilities      = additionalCapabilities;
     OsProfile                   = osProfile;
     SecurityProfile             = securityProfile;
     NetworkProfile              = networkProfile;
     NetworkProfileConfiguration = networkProfileConfiguration;
     DiagnosticsProfile          = diagnosticsProfile;
     AvailabilitySet             = availabilitySet;
     ProvisioningState           = provisioningState;
     LicenseType                 = licenseType;
     ModelDefinitionApplied      = modelDefinitionApplied;
     ProtectionPolicy            = protectionPolicy;
     UserData                    = userData;
 }
Exemplo n.º 2
0
        protected void ValidateVMScaleSetVMInstanceView(VirtualMachineScaleSetVMInstanceView vmScaleSetVMInstanceView)
        {
            Assert.NotNull(vmScaleSetVMInstanceView);
            Assert.True(vmScaleSetVMInstanceView.Statuses.Any(s => !string.IsNullOrEmpty(s.Code)));

            var instanceView = vmScaleSetVMInstanceView;

            Assert.NotNull(instanceView.Disks);
            Assert.True(instanceView.Disks.Any());

            DiskInstanceView diskInstanceView = instanceView.Disks.First();

            Assert.NotNull(diskInstanceView);
            Assert.NotNull(diskInstanceView.Statuses[0].DisplayStatus);
            Assert.NotNull(diskInstanceView.Statuses[0].Code);
            Assert.NotNull(diskInstanceView.Statuses[0].Level);
        }
        protected void ValidateVMScaleSetVMInstanceView(VirtualMachineScaleSetVMInstanceView vmScaleSetVMInstanceView, bool hasManagedDisks = false)
        {
            Assert.NotNull(vmScaleSetVMInstanceView);
            //Assert.Contains(vmScaleSetVMInstanceView.Statuses, s => !string.IsNullOrEmpty(s.Code));

            if (!hasManagedDisks)
            {
                var instanceView = vmScaleSetVMInstanceView;
                Assert.NotNull(instanceView.Disks);
                Assert.True(instanceView.Disks.Any());

                DiskInstanceView diskInstanceView = instanceView.Disks.First();
                Assert.NotNull(diskInstanceView);
                Assert.NotNull(diskInstanceView.Statuses[0].DisplayStatus);
                Assert.NotNull(diskInstanceView.Statuses[0].Code);
                Assert.NotNull(diskInstanceView.Statuses[0].Level);
            }
        }
        /// <summary>
        /// Validate if encryption settings are populated in DiskInstanceView as part of VM instance view
        /// </summary>
        protected void ValidateEncryptionSettingsInVMScaleSetVMInstanceView(
            VirtualMachineScaleSetVMInstanceView vmScaleSetVMInstanceView,
            bool hasManagedDisks)
        {
            Assert.True(hasManagedDisks); // VMSS disk encryption is supported only with managed disks
            Assert.NotNull(vmScaleSetVMInstanceView);
            Assert.NotNull(vmScaleSetVMInstanceView.Disks);
            Assert.True(vmScaleSetVMInstanceView.Disks.Any());

            DiskInstanceView diskInstanceView = vmScaleSetVMInstanceView.Disks.First();

            Assert.NotNull(diskInstanceView.EncryptionSettings);
            Assert.True(diskInstanceView.EncryptionSettings.Any());

            DiskEncryptionSettings encryptionSettings = diskInstanceView.EncryptionSettings.First();

            Assert.NotNull(encryptionSettings.Enabled);
        }
Exemplo n.º 5
0
        protected void ValidateVMScaleSetVMInstanceView(VirtualMachineScaleSetVMInstanceView vmScaleSetVMInstanceView, bool hasManagedDisks = false,
                                                        string dedicatedHostReferenceId = null)
        {
            Assert.NotNull(vmScaleSetVMInstanceView);
            Assert.Contains(vmScaleSetVMInstanceView.Statuses, s => !string.IsNullOrEmpty(s.Code));

            if (!hasManagedDisks)
            {
                var instanceView = vmScaleSetVMInstanceView;
                Assert.NotNull(instanceView.Disks);
                Assert.True(instanceView.Disks.Any());

                DiskInstanceView diskInstanceView = instanceView.Disks.First();
                Assert.NotNull(diskInstanceView);
                Assert.NotNull(diskInstanceView.Statuses[0].DisplayStatus);
                Assert.NotNull(diskInstanceView.Statuses[0].Code);
                Assert.NotNull(diskInstanceView.Statuses[0].Level);
            }

            if (dedicatedHostReferenceId != null)
            {
                Assert.Equal(dedicatedHostReferenceId, vmScaleSetVMInstanceView.AssignedHost, StringComparer.OrdinalIgnoreCase);
            }
        }
Exemplo n.º 6
0
        internal static VirtualMachineScaleSetVMData DeserializeVirtualMachineScaleSetVMData(JsonElement element)
        {
            Optional <string>     instanceId = default;
            Optional <Models.Sku> sku        = default;
            Optional <Plan>       plan       = default;
            Optional <IReadOnlyList <VirtualMachineExtensionData> > resources = default;
            Optional <IReadOnlyList <string> > zones = default;
            IDictionary <string, string>       tags  = default;
            AzureLocation      location           = default;
            ResourceIdentifier id                 = default;
            string             name               = default;
            ResourceType       type               = default;
            Optional <bool>    latestModelApplied = default;
            Optional <string>  vmId               = default;
            Optional <VirtualMachineScaleSetVMInstanceView> instanceView = default;
            Optional <HardwareProfile>        hardwareProfile            = default;
            Optional <StorageProfile>         storageProfile             = default;
            Optional <AdditionalCapabilities> additionalCapabilities     = default;
            Optional <OSProfile>       osProfile       = default;
            Optional <SecurityProfile> securityProfile = default;
            Optional <NetworkProfile>  networkProfile  = default;
            Optional <VirtualMachineScaleSetVMNetworkProfileConfiguration> networkProfileConfiguration = default;
            Optional <DiagnosticsProfile>  diagnosticsProfile = default;
            Optional <WritableSubResource> availabilitySet    = default;
            Optional <string> provisioningState      = default;
            Optional <string> licenseType            = default;
            Optional <string> modelDefinitionApplied = default;
            Optional <VirtualMachineScaleSetVMProtectionPolicy> protectionPolicy = default;
            Optional <string> userData = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("instanceId"))
                {
                    instanceId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("sku"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    sku = Models.Sku.DeserializeSku(property.Value);
                    continue;
                }
                if (property.NameEquals("plan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    plan = Plan.DeserializePlan(property.Value);
                    continue;
                }
                if (property.NameEquals("resources"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <VirtualMachineExtensionData> array = new List <VirtualMachineExtensionData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(VirtualMachineExtensionData.DeserializeVirtualMachineExtensionData(item));
                    }
                    resources = array;
                    continue;
                }
                if (property.NameEquals("zones"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    zones = array;
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("latestModelApplied"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            latestModelApplied = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("vmId"))
                        {
                            vmId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("instanceView"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            instanceView = VirtualMachineScaleSetVMInstanceView.DeserializeVirtualMachineScaleSetVMInstanceView(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("hardwareProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            hardwareProfile = HardwareProfile.DeserializeHardwareProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("storageProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            storageProfile = StorageProfile.DeserializeStorageProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("additionalCapabilities"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            additionalCapabilities = AdditionalCapabilities.DeserializeAdditionalCapabilities(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("osProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            osProfile = OSProfile.DeserializeOSProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("securityProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            securityProfile = SecurityProfile.DeserializeSecurityProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("networkProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkProfile = NetworkProfile.DeserializeNetworkProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("networkProfileConfiguration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkProfileConfiguration = VirtualMachineScaleSetVMNetworkProfileConfiguration.DeserializeVirtualMachineScaleSetVMNetworkProfileConfiguration(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("diagnosticsProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            diagnosticsProfile = DiagnosticsProfile.DeserializeDiagnosticsProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("availabilitySet"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            availabilitySet = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString());
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            provisioningState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("licenseType"))
                        {
                            licenseType = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("modelDefinitionApplied"))
                        {
                            modelDefinitionApplied = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("protectionPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            protectionPolicy = VirtualMachineScaleSetVMProtectionPolicy.DeserializeVirtualMachineScaleSetVMProtectionPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("userData"))
                        {
                            userData = property0.Value.GetString();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new VirtualMachineScaleSetVMData(id, name, type, tags, location, instanceId.Value, sku.Value, plan.Value, Optional.ToList(resources), Optional.ToList(zones), Optional.ToNullable(latestModelApplied), vmId.Value, instanceView.Value, hardwareProfile.Value, storageProfile.Value, additionalCapabilities.Value, osProfile.Value, securityProfile.Value, networkProfile.Value, networkProfileConfiguration.Value, diagnosticsProfile.Value, availabilitySet, provisioningState.Value, licenseType.Value, modelDefinitionApplied.Value, protectionPolicy.Value, userData.Value));
        }
Exemplo n.º 7
0
        private void TestDiskEncryptionOnScaleSetVMInternal(MockContext context, bool hasManagedDisks = true, bool useVmssExtension = true)
        {
            EnsureClientsInitialized(context);

            // Get platform image for VMScaleSet create
            ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);

            // Create resource group
            string rgName             = TestUtilities.GenerateName(TestPrefix);
            string vmssName           = TestUtilities.GenerateName("vmss");
            string storageAccountName = TestUtilities.GenerateName(TestPrefix);
            var    dnsname            = TestUtilities.GenerateName("dnsname");

            // Create ADE extension to enable disk encryption
            VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile()
            {
                Extensions = new List <VirtualMachineScaleSetExtension>()
                {
                    GetAzureDiskEncryptionExtension(),
                }
            };

            bool testSucceeded = false;

            try
            {
                StorageAccount storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

                var vnetResponse = CreateVNETWithSubnets(rgName, 2);
                var vmssSubnet   = vnetResponse.Subnets[1];

                var publicipConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration();
                publicipConfiguration.Name = "pip1";
                publicipConfiguration.IdleTimeoutInMinutes        = 10;
                publicipConfiguration.DnsSettings                 = new VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings();
                publicipConfiguration.DnsSettings.DomainNameLabel = dnsname;

                VirtualMachineScaleSet inputVMScaleSet;
                VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking(
                    rgName,
                    vmssName,
                    storageAccountOutput,
                    imageRef,
                    out inputVMScaleSet,
                    useVmssExtension ? extensionProfile : null,
                    (vmss) =>
                {
                    vmss.Sku.Name = VirtualMachineSizeTypes.StandardA3;
                    vmss.Sku.Tier = "Standard";
                    vmss.VirtualMachineProfile.StorageProfile.OsDisk = new VirtualMachineScaleSetOSDisk()
                    {
                        CreateOption = DiskCreateOptionTypes.FromImage,
                    };
                    vmss.VirtualMachineProfile.NetworkProfile
                    .NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration = publicipConfiguration;
                },
                    createWithManagedDisks: hasManagedDisks,
                    createWithPublicIpAddress: false,
                    subnet: vmssSubnet);

                VirtualMachineScaleSetVMInstanceView vmInstanceViewResponse =
                    m_CrpClient.VirtualMachineScaleSetVMs.GetInstanceView(rgName, vmScaleSet.Name, "0");
                Assert.True(vmInstanceViewResponse != null, "VMScaleSetVM not returned.");

                ValidateEncryptionSettingsInVMScaleSetVMInstanceView(vmInstanceViewResponse, hasManagedDisks);

                m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmssName);
                testSucceeded = true;
            }
            finally
            {
                //Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
                //of the test to cover deletion. CSM does persistent retrying over all RG resources.
                m_ResourcesClient.ResourceGroups.Delete(rgName);
            }

            Assert.True(testSucceeded);
        }
        private PSVmssDiskEncryptionStatusContext GetVmssDiskStatus(string rgName, string vmssName)
        {
            VirtualMachineScaleSetExtension           ext;
            VirtualMachineScaleSetVMExtensionsSummary extSummary;
            PSVmssDiskEncryptionStatusContext         psResult = new PSVmssDiskEncryptionStatusContext
            {
                ResourceGroupName            = rgName,
                VmScaleSetName               = vmssName,
                EncryptionEnabled            = false,
                EncryptionExtensionInstalled = false
            };

            var vmssResult = this.VirtualMachineScaleSetClient.Get(rgName, vmssName);

            if (vmssResult.VirtualMachineProfile == null ||
                vmssResult.VirtualMachineProfile.ExtensionProfile == null ||
                vmssResult.VirtualMachineProfile.ExtensionProfile.Extensions == null ||
                vmssResult.VirtualMachineProfile.ExtensionProfile.Extensions.Count == 0)
            {
                return(psResult);
            }

            // retrieve installation status of the extension
            SetOSType(vmssResult.VirtualMachineProfile);
            try
            {
                if (string.IsNullOrWhiteSpace(this.ExtensionName))
                {
                    if (this.CurrentOSType == OperatingSystemTypes.Windows)
                    {
                        this.ExtensionName = AzureVmssDiskEncryptionExtensionContext.ExtensionDefaultName;
                    }
                    else
                    {
                        this.ExtensionName = AzureVmssDiskEncryptionExtensionContext.LinuxExtensionDefaultName;
                    }
                }

                ext = vmssResult.VirtualMachineProfile.ExtensionProfile.Extensions.First(
                    e => e.Type.Equals(this.ExtensionName));
            }
            catch (InvalidOperationException)
            {
                return(psResult);
            }
            psResult.EncryptionExtensionInstalled = true;

            // retrieve public configuration settings for the extension
            psResult.EncryptionSettings = JsonConvert.DeserializeObject <AzureVmssDiskEncryptionExtensionPublicSettings>(
                ext.Settings.ToString());

            // retrieve any status summary for the extension
            var vmssInstanceView = this.VirtualMachineScaleSetClient.GetInstanceView(rgName, vmssName);

            if (vmssInstanceView.Extensions == null ||
                vmssInstanceView.Extensions.Count == 0)
            {
                return(psResult);
            }
            try
            {
                extSummary = vmssInstanceView.Extensions.First(e => e.Name.Equals(this.ExtensionName));
            }
            catch (InvalidOperationException)
            {
                return(psResult);
            }
            psResult.EncryptionSummary = extSummary.StatusesSummary;

            // check if encryption is enabled on any disk in the scale set
            // stop evaluation at the first occurrence of an encrypted disk
            var page = this.VirtualMachineScaleSetVMsClient.List(rgName, vmssName);

            while (!psResult.EncryptionEnabled && page != null)
            {
                foreach (var pageItem in page)
                {
                    if (psResult.EncryptionEnabled)
                    {
                        break;
                    }
                    VirtualMachineScaleSetVMInstanceView vmiv = this.VirtualMachineScaleSetVMsClient.GetInstanceView(rgName, vmssName, pageItem.InstanceId);
                    if (vmiv != null && vmiv.Disks != null)
                    {
                        foreach (DiskInstanceView div in vmiv.Disks)
                        {
                            List <InstanceViewStatus> perDiskEncryptionStatuses = new List <InstanceViewStatus>();
                            bool isEncrypted = false;
                            foreach (InstanceViewStatus ivs in div.Statuses)
                            {
                                if (ivs != null && ivs.Code != null && ivs.Code.StartsWith("EncryptionState"))
                                {
                                    if (!psResult.EncryptionEnabled)
                                    {
                                        isEncrypted = ivs.Code.Equals("EncryptionState/encrypted");
                                    }
                                }
                            }
                            if (isEncrypted)
                            {
                                psResult.EncryptionEnabled = true;
                                break;
                            }
                        }
                    }
                }
                // advance to the next page as needed
                page = (page.NextPageLink != null) ? VirtualMachineScaleSetVMsClient.ListNext(page.NextPageLink) : null;
            }

            return(psResult);
        }
        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);
        }
        private void TestScaleSetOperationsInternal(MockContext context, 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,
                                                    bool?encryptionAtHostEnabled  = null, bool isAutomaticPlacementOnDedicatedHostGroupScenario = false,
                                                    int?faultDomainCount          = null, int?capacity = null, bool shouldOverProvision = true, bool validateVmssVMInstanceView = false,
                                                    ImageReference imageReference = null, bool validateListSku = true, bool deleteAsPartOfTest = true)
        {
            EnsureClientsInitialized(context);

            ImageReference imageRef = imageReference ?? GetPlatformVMImage(useWindowsImage: true);
            // Create resource group
            var    rgName             = TestUtilities.GenerateName(TestPrefix);
            var    vmssName           = TestUtilities.GenerateName("vmss");
            string storageAccountName = TestUtilities.GenerateName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;

            VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile()
            {
                Extensions = new List <VirtualMachineScaleSetExtension>()
                {
                    GetTestVMSSVMExtension(autoUpdateMinorVersion: false),
                }
            };

            try
            {
                var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

                m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

                string ppgId   = null;
                string ppgName = null;
                if (isPpgScenario)
                {
                    ppgName = ComputeManagementTestUtilities.GenerateName("ppgtest");
                    ppgId   = CreateProximityPlacementGroup(rgName, ppgName);
                }

                string dedicatedHostGroupName = null, dedicatedHostName = null, dedicatedHostGroupReferenceId = null, dedicatedHostReferenceId = null;
                if (isAutomaticPlacementOnDedicatedHostGroupScenario)
                {
                    dedicatedHostGroupName        = ComputeManagementTestUtilities.GenerateName("dhgtest");
                    dedicatedHostName             = ComputeManagementTestUtilities.GenerateName("dhtest");
                    dedicatedHostGroupReferenceId = Helpers.GetDedicatedHostGroupRef(m_subId, rgName, dedicatedHostGroupName);
                    dedicatedHostReferenceId      = Helpers.GetDedicatedHostRef(m_subId, rgName, dedicatedHostGroupName, dedicatedHostName);
                }

                VirtualMachineScaleSet getResponse = CreateVMScaleSet_NoAsyncTracking(
                    rgName,
                    vmssName,
                    storageAccountOutput,
                    imageRef,
                    out inputVMScaleSet,
                    useVmssExtension ? extensionProfile : null,
                    (vmScaleSet) => {
                    vmScaleSet.Overprovision = shouldOverProvision;
                    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,
                    encryptionAtHostEnabled: encryptionAtHostEnabled,
                    faultDomainCount: faultDomainCount,
                    capacity: capacity,
                    dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId,
                    dedicatedHostGroupName: dedicatedHostGroupName,
                    dedicatedHostName: dedicatedHostName);

                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.Equal(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");
                }

                if (encryptionAtHostEnabled != null)
                {
                    Assert.True(getResponse.VirtualMachineProfile.SecurityProfile.EncryptionAtHost == encryptionAtHostEnabled.Value,
                                "SecurityProfile.EncryptionAtHost is not same as expected");
                }

                ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks, ppgId: ppgId, dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId);

                var getInstanceViewResponse = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName);
                Assert.NotNull(getInstanceViewResponse);
                ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse);

                if (isPpgScenario)
                {
                    ProximityPlacementGroup outProximityPlacementGroup = m_CrpClient.ProximityPlacementGroups.Get(rgName, ppgName);
                    Assert.Equal(1, outProximityPlacementGroup.VirtualMachineScaleSets.Count);
                    string expectedVmssReferenceId = Helpers.GetVMScaleSetReferenceId(m_subId, rgName, vmssName);
                    Assert.Equal(expectedVmssReferenceId, outProximityPlacementGroup.VirtualMachineScaleSets.First().Id, StringComparer.OrdinalIgnoreCase);
                }

                var listResponse = m_CrpClient.VirtualMachineScaleSets.List(rgName);
                ValidateVMScaleSet(inputVMScaleSet, listResponse.FirstOrDefault(x => x.Name == vmssName), hasManagedDisks);

                if (validateListSku)
                {
                    var listSkusResponse = m_CrpClient.VirtualMachineScaleSets.ListSkus(rgName, vmssName);
                    Assert.NotNull(listSkusResponse);
                    Assert.False(listSkusResponse.Count() == 0);
                }

                if (zones != null)
                {
                    var query = new Microsoft.Rest.Azure.OData.ODataQuery <VirtualMachineScaleSetVM>();
                    query.SetFilter(vm => vm.LatestModelApplied == true);
                    var listVMsResponse = m_CrpClient.VirtualMachineScaleSetVMs.List(rgName, vmssName, query);
                    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 = m_CrpClient.VirtualMachineScaleSetVMs.Get(rgName, vmssName, instanceId);
                        ValidateVMScaleSetVM(inputVMScaleSet, instanceId, getVMResponse, hasManagedDisks);
                    }
                }

                if (validateVmssVMInstanceView)
                {
                    VirtualMachineScaleSetVMInstanceView vmssVMInstanceView = m_CrpClient.VirtualMachineScaleSetVMs.GetInstanceView(rgName, vmssName, "0");
                    ValidateVMScaleSetVMInstanceView(vmssVMInstanceView, hasManagedDisks, dedicatedHostReferenceId);
                }

                vmScaleSetValidator?.Invoke(getResponse);

                if (deleteAsPartOfTest)
                {
                    m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmssName);
                }
            }
            finally
            {
                if (deleteAsPartOfTest)
                {
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
                else
                {
                    // Fire and forget. No need to wait for RG deletion completion
                    m_ResourcesClient.ResourceGroups.BeginDelete(rgName);
                }
            }
        }