Exemple #1
0
        private async Task TestVMScaleSetVMOperationsInternal(bool hasManagedDisks = false)
        {
            InitializeCommon();
            instanceId = "0";

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

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

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            var getResponse = (await VirtualMachineScaleSetVMsOperations.GetAsync(rgName, vmScaleSet.Name, instanceId)).Value;

            var imageReference = getResponse.StorageProfile.ImageReference;

            Assert.NotNull(imageReference?.ExactVersion);
            Assert.AreEqual(imageReference.Version, imageReference.ExactVersion);

            VirtualMachineScaleSetVM vmScaleSetVMModel = GenerateVMScaleSetVMModel(vmScaleSet, instanceId, hasManagedDisks);

            ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, getResponse, hasManagedDisks);

            var getInstanceViewResponse = await VirtualMachineScaleSetVMsOperations.GetInstanceViewAsync(rgName,
                                                                                                         vmScaleSet.Name, instanceId);

            Assert.True(getInstanceViewResponse != null, "VMScaleSetVM not returned.");
            ValidateVMScaleSetVMInstanceView(getInstanceViewResponse, hasManagedDisks);

            //var query = new Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM>();
            //query.SetFilter(vm => vm.LatestModelApplied == true);
            var query        = "properties/latestModelApplied eq true";
            var listResponse = await(VirtualMachineScaleSetVMsOperations.ListAsync(rgName, vmssName, query)).ToEnumerableAsync();

            Assert.False(listResponse == null, "VMScaleSetVMs not returned");
            Assert.True(listResponse.Count() == inputVMScaleSet.Sku.Capacity);

            query = null;
            //query.Filter = null;
            //query.Expand = "instanceView";
            listResponse = await(VirtualMachineScaleSetVMsOperations.ListAsync(rgName, vmssName, query, null, "instanceView")).ToEnumerableAsync();
            Assert.False(listResponse == null, "VMScaleSetVMs not returned");
            Assert.True(listResponse.Count() == inputVMScaleSet.Sku.Capacity);

            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartStartAsync(rgName, vmScaleSet.Name, instanceId));
            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartReimageAsync(rgName, vmScaleSet.Name, instanceId));

            if (hasManagedDisks)
            {
                await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartReimageAllAsync(rgName, vmScaleSet.Name, instanceId));
            }
            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartRestartAsync(rgName, vmScaleSet.Name, instanceId));
            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartPowerOffAsync(rgName, vmScaleSet.Name, instanceId));
            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartDeallocateAsync(rgName, vmScaleSet.Name, instanceId));
            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartDeleteAsync(rgName, vmScaleSet.Name, instanceId));

            passed = true;
            Assert.True(passed);
        }
Exemple #2
0
        //[Trait("Name", "TestVMScaleSetRollingUpgrade")]
        public async Task TestVMScaleSetRollingUpgrade()
        {
            EnsureClientsInitialized(LocationSouthCentralUs);

            // Create resource group
            var    rgName             = Recording.GenerateAssetName(TestPrefix);
            var    vmssName           = Recording.GenerateAssetName("vmss");
            string storageAccountName = Recording.GenerateAssetName(TestPrefix);
            VirtualMachineScaleSet inputVMScaleSet;
            ImageReference         imageRef = await GetPlatformVMImage(useWindowsImage : true);

            VirtualMachineScaleSetExtensionProfile extensionProfile = new VirtualMachineScaleSetExtensionProfile()
            {
                Extensions =
                {
                    GetTestVMSSVMExtension(),
                }
            };

            var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

            await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, "VMScaleSetDoesNotExist"));

            var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(
                rgName,
                vmssName,
                storageAccountOutput,
                imageRef,
                null,
                (vmScaleSet) =>
            {
                vmScaleSet.Overprovision      = false;
                vmScaleSet.UpgradePolicy.Mode = UpgradeMode.Rolling;
            },
                createWithManagedDisks : true,
                createWithPublicIpAddress : false,
                createWithHealthProbe : true);

            VirtualMachineScaleSet getResponse = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

            var getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName);

            Assert.NotNull(getInstanceViewResponse);
            ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse);

            var getVMInstanceViewResponse = await VirtualMachineScaleSetVMsOperations.GetInstanceViewAsync(rgName, vmssName, "0");

            Assert.NotNull(getVMInstanceViewResponse);
            Assert.NotNull(getVMInstanceViewResponse.Value.VmHealth);
            Assert.AreEqual("HealthState/healthy", getVMInstanceViewResponse.Value.VmHealth.Status.Code);

            // Update the VMSS by adding an extension
            WaitSeconds(600);
            var vmssStatus = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName);

            inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile;
            await UpdateVMScaleSet(rgName, vmssName, inputVMScaleSet);

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

            ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks: true);

            getInstanceViewResponse = await VirtualMachineScaleSetsOperations.GetInstanceViewAsync(rgName, vmssName);

            Assert.NotNull(getInstanceViewResponse);
            ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse);

            await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteAsync(rgName, vmssName));
        }
        private async Task 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);
        }