public async Task TestVMScaleSetWithDnsSettings()
        {
            EnsureClientsInitialized(DefaultLocation);

            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 vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet = vnetResponse.Subnets[1];

            var nicDnsSettings = new VirtualMachineScaleSetNetworkConfigurationDnsSettings();

            nicDnsSettings.DnsServers = new List <string>()
            {
                "10.0.0.5", "10.0.0.6"
            };

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile
                .NetworkInterfaceConfigurations[0].DnsSettings = nicDnsSettings,
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.NotNull(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings);
            Assert.NotNull(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers);
            Assert.AreEqual(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers.Count);
            //bool containFive = false;
            //bool containSix = false;
            //foreach (var detail in vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers)
            //{
            //    if(detail.)
            //}
            //Assert.Contains(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers, ip => string.Equals("10.0.0.5", ip));
            //Assert.Contains(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers, ip => string.Equals("10.0.0.6", ip));
            //Assert.Contains(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers, ip => string.Equals("10.0.0.5", ip));
            //Assert.Contains(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].DnsSettings.DnsServers, ip => string.Equals("10.0.0.6", ip));
            passed = true;
            Assert.True(passed);
        }
        public async Task TestVMSSWithMultiCA()
        {
            EnsureClientsInitialized(LocationWestCentralUs);

            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 vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet = vnetResponse.Subnets[1];

            var secondaryCA =
                new VirtualMachineScaleSetIPConfiguration(Recording.GenerateAssetName("vmsstestnetconfig"))
            {
                Subnet = new ApiEntityReference()
                {
                    Id = vmssSubnet.Id
                }
            };

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
            {
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Primary = true;
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Add(secondaryCA);
            },
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.AreEqual(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count);
            Assert.True(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count(ip => ip.Primary == true) == 1);

            passed = true;

            Assert.True(passed);
        }
        public async Task TestVMScaleSetWithnNsg()
        {
            EnsureClientsInitialized(DefaultLocation);

            ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true);

            // Create resource group
            string rgName             = Recording.GenerateAssetName(TestPrefix) + 1;
            var    vmssName           = Recording.GenerateAssetName("vmss");
            var    dnsname            = Recording.GenerateAssetName("dnsname");
            var    nsgname            = Recording.GenerateAssetName("nsg");
            string storageAccountName = Recording.GenerateAssetName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;

            bool passed = false;
            var  storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

            var vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet = vnetResponse.Subnets[1];
            var nsg        = await CreateNsg(rgName, nsgname);

            Azure.ResourceManager.Compute.Models.SubResource nsgId = new Azure.ResourceManager.Compute.Models.SubResource()
            {
                Id = nsg.Id
            };

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile
                .NetworkInterfaceConfigurations[0].NetworkSecurityGroup = nsgId,
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.NotNull(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].NetworkSecurityGroup);
            Assert.AreEqual(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].NetworkSecurityGroup.Id, nsg.Id);

            var getNsgResponse = (await NetworkSecurityGroupsOperations.GetAsync(rgName, nsg.Name)).Value;

            Assert.AreEqual(2, getNsgResponse.NetworkInterfaces.Count);

            passed = true;
            Assert.True(passed);
        }
        public async Task TestVMScaleSetWithPublicIP()
        {
            EnsureClientsInitialized(LocationWestCentralUs);
            // Create resource group
            string rgName             = Recording.GenerateAssetName(TestPrefix) + 1;
            var    vmssName           = Recording.GenerateAssetName("vmss");
            var    dnsname            = Recording.GenerateAssetName("dnsname");
            string storageAccountName = Recording.GenerateAssetName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;

            bool passed = false;
            // Hard code the location to "westcentralus".
            // This is because NRP is still deploying to other regions and is not available worldwide.
            // Before changing the default location, we have to save it to be reset it at the end of the test.
            // Since ComputeManagementTestUtilities.DefaultLocation is a static variable and can affect other tests if it is not reset.

            ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true);

            var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

            var vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet = vnetResponse.Subnets[1];

            var publicipConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration("pip1");

            publicipConfiguration.IdleTimeoutInMinutes = 10;
            publicipConfiguration.DnsSettings          = new VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings(dnsname);

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile
                .NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration = publicipConfiguration,
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName);

            Assert.NotNull(vmss.Value.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration);
            Assert.AreEqual("pip1", vmss.Value.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.Name);
            Assert.AreEqual(10, vmss.Value.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.IdleTimeoutInMinutes);
            Assert.NotNull(vmss.Value.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.DnsSettings);
            Assert.AreEqual(dnsname, vmss.Value.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.DnsSettings.DomainNameLabel);
            passed = true;
            Assert.True(passed);
        }
        public async Task TestVMScaleSetWithPublicIPAndPublicIPPrefix()
        {
            EnsureClientsInitialized(LocationWestCentralUs);
            // Create resource group
            string rgName             = Recording.GenerateAssetName(TestPrefix) + 1;
            var    vmssName           = Recording.GenerateAssetName("vmss");
            var    dnsname            = Recording.GenerateAssetName("dnsname");
            string storageAccountName = Recording.GenerateAssetName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;

            bool passed = false;

            ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true);

            var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

            var vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet     = vnetResponse.Subnets[1];
            var publicIpPrefix = await CreatePublicIPPrefix(rgName, 30);

            var publicipConfiguration = new VirtualMachineScaleSetPublicIPAddressConfiguration("pip1");

            publicipConfiguration.IdleTimeoutInMinutes = 10;
            publicipConfiguration.DnsSettings          = new VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings(dnsname);
            publicipConfiguration.PublicIPPrefix       = new Azure.ResourceManager.Compute.Models.SubResource();
            publicipConfiguration.PublicIPPrefix.Id    = publicIpPrefix.Id;

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile
                .NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration = publicipConfiguration,
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.NotNull(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration);
            Assert.AreEqual("pip1", vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.Name);
            Assert.AreEqual(10, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.IdleTimeoutInMinutes);
            Assert.NotNull(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.DnsSettings);
            Assert.AreEqual(dnsname, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.DnsSettings.DomainNameLabel);
            Assert.AreEqual(publicIpPrefix.Id, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].PublicIPAddressConfiguration.PublicIPPrefix.Id);
            passed = true;
            Assert.True(passed);
        }
        public async Task TestVMScaleSetWithnIpv6()
        {
            EnsureClientsInitialized(DefaultLocation);

            ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true);

            // Create resource group
            string rgName             = Recording.GenerateAssetName(TestPrefix) + 1;
            var    vmssName           = Recording.GenerateAssetName("vmss");
            var    dnsname            = Recording.GenerateAssetName("dnsname");
            string storageAccountName = Recording.GenerateAssetName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;

            bool passed = false;
            var  storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

            var vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet = vnetResponse.Subnets[1];

            var ipv6ipconfig = new VirtualMachineScaleSetIPConfiguration("ipv6");

            ipv6ipconfig.Name = "ipv6";
            ipv6ipconfig.PrivateIPAddressVersion = Azure.ResourceManager.Compute.Models.IPVersion.IPv6;

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
            {
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile
                .NetworkInterfaceConfigurations[0].IpConfigurations[0].PrivateIPAddressVersion = Azure.ResourceManager.Compute.Models.IPVersion.IPv4;
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile
                .NetworkInterfaceConfigurations[0].IpConfigurations.Add(ipv6ipconfig);
            },
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.AreEqual(2, vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations.Count);

            passed = true;
            Assert.True(passed);
        }
Example #7
0
        public async Task <(VirtualMachineScaleSet, VirtualMachineScaleSet)> CreateVMScaleSet_NoAsyncTracking(
            string rgName,
            string vmssName,
            StorageAccount storageAccount,
            ImageReference imageRef,
            VirtualMachineScaleSetExtensionProfile extensionProfile = null,
            Action <VirtualMachineScaleSet> vmScaleSetCustomizer    = null,
            bool createWithPublicIpAddress = false,
            bool createWithManagedDisks    = false,
            bool hasDiffDisks          = false,
            bool createWithHealthProbe = false,
            Subnet subnet              = null,
            IList <string> zones       = null,
            int?osDiskSizeInGB         = null,
            string ppgId               = null,
            string machineSizeType     = null,
            bool?enableUltraSSD        = false,
            string diskEncryptionSetId = null,
            AutomaticRepairsPolicy automaticRepairsPolicy = null)
        {
            try
            {
                var createOrUpdateResponse = await CreateVMScaleSetAndGetOperationResponse(rgName,
                                                                                           vmssName,
                                                                                           storageAccount,
                                                                                           imageRef,
                                                                                           extensionProfile,
                                                                                           vmScaleSetCustomizer,
                                                                                           createWithPublicIpAddress,
                                                                                           createWithManagedDisks,
                                                                                           hasDiffDisks,
                                                                                           createWithHealthProbe,
                                                                                           subnet,
                                                                                           zones,
                                                                                           osDiskSizeInGB,
                                                                                           ppgId : ppgId,
                                                                                           machineSizeType : machineSizeType,
                                                                                           enableUltraSSD : enableUltraSSD,
                                                                                           diskEncryptionSetId : diskEncryptionSetId,
                                                                                           automaticRepairsPolicy : automaticRepairsPolicy);

                var getResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName);

                return(getResponse, createOrUpdateResponse.Item2);
            }
            catch
            {
                throw;
            }
        }
        public async Task TestVMScaleSetWithLicenseType()
        {
            EnsureClientsInitialized(DefaultLocation);

            // 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);

            VirtualMachineScaleSet inputVMScaleSet;

            Action <VirtualMachineScaleSet> vmProfileCustomizer = vmss =>
            {
                vmss.VirtualMachineProfile.StorageProfile.ImageReference = GetPlatformVMImage(true).Result;
                vmss.VirtualMachineProfile.LicenseType = "Windows_Server";
            };

            try
            {
                var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                    rgName : rgName,
                    vmssName : vmssName,
                    storageAccount : storageAccountOutput,
                    imageRef : null,
                    createWithManagedDisks : true,
                    vmScaleSetCustomizer : vmProfileCustomizer
                    );

                VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;
                inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;

                var response = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

                Assert.AreEqual("Windows_Server", response.VirtualMachineProfile.LicenseType);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("One or more errors occurred while preparing VM disks. See disk instance view for details."))
                {
                    return;
                }
                throw;
            }
        }
Example #9
0
        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));
        }
Example #10
0
        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 TestVMSSAccelNtwkng()
        {
            EnsureClientsInitialized(LocationWestCentralUs);

            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 vnetResponse = await CreateVNETWithSubnets(rgName, 2);

            var vmssSubnet = vnetResponse.Subnets[1];

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : imageRef,
                vmScaleSetCustomizer :
                (virtualMachineScaleSet) =>
            {
                virtualMachineScaleSet.Sku.Name = VirtualMachineSizeTypes.StandardDS11V2.ToString();
                virtualMachineScaleSet.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].EnableAcceleratedNetworking = true;
            },
                createWithPublicIpAddress : false,
                subnet : vmssSubnet);

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var vmss = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.True(vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].EnableAcceleratedNetworking == true);
            passed = true;
            Assert.True(passed);
        }
        public async Task TestVMScaleSetDiagnosticsProfile()
        {
            EnsureClientsInitialized(DefaultLocation);
            // 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);

            VirtualMachineScaleSet inputVMScaleSet;

            Action <VirtualMachineScaleSet> vmProfileCustomizer = vmss =>
            {
                vmss.VirtualMachineProfile.DiagnosticsProfile = new DiagnosticsProfile(
                    new BootDiagnostics
                {
                    Enabled    = true,
                    StorageUri = string.Format(Constants.StorageAccountBlobUriTemplate, storageAccountName)
                });
            };
            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName : rgName,
                vmssName : vmssName,
                storageAccount : storageAccountOutput,
                imageRef : await GetPlatformVMImage(true),
                createWithManagedDisks : true,
                vmScaleSetCustomizer : vmProfileCustomizer
                );

            VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var response = (await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName)).Value;

            Assert.True(response.VirtualMachineProfile.DiagnosticsProfile.BootDiagnostics.Enabled.GetValueOrDefault(true));
        }
Example #13
0
        //[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);
        }
Example #14
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));
        }
Example #15
0
        //[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);
        }
Example #16
0
        private async Task <(VirtualMachineScaleSet, VirtualMachineScaleSet)> CreateVMScaleSetAndGetOperationResponse(
            string rgName,
            string vmssName,
            StorageAccount storageAccount,
            ImageReference imageRef,
            VirtualMachineScaleSetExtensionProfile extensionProfile = null,
            Action <VirtualMachineScaleSet> vmScaleSetCustomizer    = null,
            bool createWithPublicIpAddress = false,
            bool createWithManagedDisks    = false,
            bool hasDiffDisks          = false,
            bool createWithHealthProbe = false,
            Subnet subnet              = null,
            IList <string> zones       = null,
            int?osDiskSizeInGB         = null,
            string ppgId               = null,
            string machineSizeType     = null,
            bool?enableUltraSSD        = false,
            string diskEncryptionSetId = null,
            AutomaticRepairsPolicy automaticRepairsPolicy = null)
        {
            // Create the resource Group, it might have been already created during StorageAccount creation.
            var resourceGroup = await ResourceGroupsOperations.CreateOrUpdateAsync(
                rgName,
                new ResourceGroup(m_location));

            var getPublicIpAddressResponse = createWithPublicIpAddress ? null : await CreatePublicIP(rgName);

            var subnetResponse = subnet ?? await CreateVNET(rgName);

            var nicResponse = await CreateNIC(
                rgName,
                subnetResponse,
                getPublicIpAddressResponse != null?getPublicIpAddressResponse.IpAddress : null);

            var loadBalancer = ((getPublicIpAddressResponse != null && createWithHealthProbe) ?
                                (await CreatePublicLoadBalancerWithProbe(rgName, getPublicIpAddressResponse)) : null);

            Assert.True(createWithManagedDisks || storageAccount != null);
            var inputVMScaleSet = CreateDefaultVMScaleSetInput(rgName, storageAccount?.Name, imageRef, subnetResponse.Id, hasManagedDisks: createWithManagedDisks,
                                                               healthProbeId: loadBalancer?.Probes?.FirstOrDefault()?.Id,
                                                               loadBalancerBackendPoolId: loadBalancer?.BackendAddressPools?.FirstOrDefault()?.Id, zones: zones, osDiskSizeInGB: osDiskSizeInGB,
                                                               machineSizeType: machineSizeType, enableUltraSSD: enableUltraSSD, diskEncryptionSetId: diskEncryptionSetId, automaticRepairsPolicy: automaticRepairsPolicy);

            if (vmScaleSetCustomizer != null)
            {
                vmScaleSetCustomizer(inputVMScaleSet);
            }

            if (hasDiffDisks)
            {
                VirtualMachineScaleSetOSDisk osDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionTypes.FromImage);
                osDisk.Caching          = CachingTypes.ReadOnly;
                osDisk.DiffDiskSettings = new DiffDiskSettings
                {
                    Option = "Local",
                    //TODO the value of "Placement" may not be given
                    //Placement = DiffDiskPlacement.CacheDisk
                };
                inputVMScaleSet.VirtualMachineProfile.StorageProfile.OsDisk = osDisk;
            }

            inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile;

            if (ppgId != null)
            {
                inputVMScaleSet.ProximityPlacementGroup = new Azure.ResourceManager.Compute.Models.SubResource()
                {
                    Id = ppgId
                };
            }

            VirtualMachineScaleSet createOrUpdateResponse = null;

            try
            {
                createOrUpdateResponse = await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartCreateOrUpdateAsync(rgName, vmssName, inputVMScaleSet));

                Assert.True(createOrUpdateResponse.Name == vmssName);
                Assert.True(createOrUpdateResponse.Location.ToLower() == inputVMScaleSet.Location.ToLower().Replace(" ", ""));
            }
            catch (Exception e)
            {
                if (e.Message.Contains("the allotted time"))
                {
                    createOrUpdateResponse = await VirtualMachineScaleSetsOperations.GetAsync(rgName, vmssName);
                }
                else
                {
                    throw;
                }
            }

            ValidateVMScaleSet(inputVMScaleSet, createOrUpdateResponse, createWithManagedDisks, ppgId: ppgId);

            return(createOrUpdateResponse, inputVMScaleSet);
        }
Example #17
0
        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));
        }