Esempio n. 1
0
 internal AzureSLA GetDiskSLA(DataDisk datadisk)
 {
     return this.GetDiskSLA(datadisk.DiskSizeGB, datadisk.Vhd.Uri);
 }
        public void TestVMDataDiskScenario()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();
                EnsureClientsInitialized();

                ImageReference imgageRef = GetPlatformVMImage(useWindowsImage: true);
                // Create resource group
                var rgName = TestUtilities.GenerateName(TestPrefix);
                string storageAccountName = TestUtilities.GenerateName(TestPrefix);
                string asName = TestUtilities.GenerateName("as");
                VirtualMachine inputVM;
                bool passed = false;

                try
                {
                    // Create Storage Account, so that both the VMs can share it
                    var storageAccountOutput = CreateStorageAccount( rgName, storageAccountName );

                    Action<VirtualMachine> addDataDiskToVM = vm =>
                    {
                        string containerName = TestUtilities.GenerateName(TestPrefix);
                        var vhdContainer = string.Format(Constants.StorageAccountBlobUriTemplate, storageAccountName) + containerName;
                        var vhduri = vhdContainer + string.Format("/{0}.vhd", TestUtilities.GenerateName(TestPrefix));

                        vm.HardwareProfile.VirtualMachineSize = VirtualMachineSizeTypes.StandardA4;
                        vm.StorageProfile.DataDisks = new List<DataDisk>();
                        foreach (int index in new int[] {1, 2})
                        {
                            var diskName = "dataDisk" + index;
                            var ddUri = vhdContainer + string.Format("/{0}{1}.vhd", diskName, TestUtilities.GenerateName(TestPrefix));
                            var dd = new DataDisk
                            {
                                Caching = CachingTypes.None,
                                SourceImage = null,
                                DiskSizeGB = 10,
                                CreateOption = DiskCreateOptionTypes.Empty,
                                Lun = 1 + index,
                                Name = diskName,
                                VirtualHardDisk = new VirtualHardDisk
                                {
                                    Uri = ddUri
                                }
                            };
                            vm.StorageProfile.DataDisks.Add(dd);
                        }

                        var testStatus = new InstanceViewStatus
                        {
                            Code = "test",
                            Message = "test"
                        };

                        var testStatusList = new List<InstanceViewStatus> { testStatus };

                        // Negative tests for a bug in 5.0.0 that read-only fields have side-effect on the request body
                        vm.InstanceView = new VirtualMachineInstanceView
                        {
                            Statuses = testStatusList,
                            VMAgent = new VirtualMachineAgentInstanceView
                            {
                                Statuses = testStatusList,
                                ExtensionHandlers = new List<VirtualMachineExtensionHandlerInstanceView>
                                {
                                    new VirtualMachineExtensionHandlerInstanceView
                                    {
                                        Status = testStatus,
                                        Type = "test",
                                        TypeHandlerVersion = "test"
                                    }
                                },
                                VMAgentVersion = "test"
                            },
                            Disks = new List<DiskInstanceView>
                            {
                                new DiskInstanceView
                                {
                                    Statuses = testStatusList,
                                    Name = "test"
                                }
                            },
                            Extensions = new List<VirtualMachineExtensionInstanceView>
                            {
                                new VirtualMachineExtensionInstanceView
                                {
                                    Statuses = testStatusList
                                }
                            }
                        };
                    };

                    var vm1 = CreateVM_NoAsyncTracking(rgName, asName, storageAccountOutput, imgageRef, out inputVM, addDataDiskToVM);

                    var getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.GetWithInstanceView(rgName, inputVM.Name);
                    Assert.True(getVMWithInstanceViewResponse.StatusCode == HttpStatusCode.OK);
                    Assert.True(getVMWithInstanceViewResponse.VirtualMachine != null, "VM in Get");
                    ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse.VirtualMachine);

                    var vm2 = getVMWithInstanceViewResponse.VirtualMachine;
                    var vmReCreateResponse = m_CrpClient.VirtualMachines.CreateOrUpdate(rgName, getVMWithInstanceViewResponse.VirtualMachine);
                    Assert.True(vmReCreateResponse.Status != ComputeOperationStatus.Failed);

                    var lroResponse = m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name);
                    Assert.True(lroResponse.Status != OperationStatus.Failed);

                    passed = true;
                }
                finally
                {
                    var deleteResourceGroupResponse = m_ResourcesClient.ResourceGroups.Delete(rgName);
                    Assert.True(deleteResourceGroupResponse.StatusCode == HttpStatusCode.OK);
                    Assert.True(passed);
                }
            }
        }