Ejemplo n.º 1
0
        public async Task TestVMScaleSetVMOperations_RunCommand()
        {
            EnsureClientsInitialized(DefaultLocation);
            InitializeCommon();
            instanceId = "0";
            bool passed = false;
            var  storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName);

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

            VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1;

            inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2;
            await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartStartAsync(rgName, vmScaleSet.Name, instanceId));

            RunCommandResult result = (await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartRunCommandAsync(rgName, vmScaleSet.Name, instanceId, new RunCommandInput("ipconfig")))).Value;

            Assert.NotNull(result);
            Assert.NotNull(result.Value);
            Assert.True(result.Value.Count > 0);
            passed = true;
            Assert.True(passed);
        }
Ejemplo n.º 2
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);
        }