public void TestVMDiskSizeScenario() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); var image = m_CrpClient.VirtualMachineImages.Get( this.m_location, imageRef.Publisher, imageRef.Offer, imageRef.Sku, imageRef.Version); Assert.True(image != null); // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); VirtualMachine inputVM; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var vm1 = CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM, (vm) => { vm.StorageProfile.OsDisk.DiskSizeGB = 150; }); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); ValidateVM(inputVM, getVMResponse, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); } finally { m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
public void TestListVMsInSubscriptionByLocation() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); string baseResourceGroupName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string resourceGroup1Name = baseResourceGroupName + "a"; string resourceGroup2Name = baseResourceGroupName + "b"; string availabilitySetName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); VirtualMachine inputVM1, inputVM2; try { // Create Storage Account, so that both VMs can share it StorageAccount storageAccountOutput = CreateStorageAccount(resourceGroup1Name, storageAccountName); VirtualMachine vm1 = CreateVM(resourceGroup1Name, availabilitySetName, storageAccountOutput, imageRef, out inputVM1); VirtualMachine vm2 = CreateVM(resourceGroup2Name, availabilitySetName, storageAccountOutput, imageRef, out inputVM2); var listResponse = m_CrpClient.VirtualMachines.ListByLocation(ComputeManagementTestUtilities.DefaultLocation); Assert.True(listResponse.Count() >= 2); Assert.Null(listResponse.NextPageLink); int vmsValidatedCount = 0; foreach (VirtualMachine vm in listResponse) { if (vm.Name.Equals(vm1.Name)) { ValidateVM(vm, vm1, Helpers.GetVMReferenceId(m_subId, resourceGroup1Name, vm1.Name)); vmsValidatedCount++; } else if (vm.Name.Equals(vm2.Name)) { ValidateVM(vm, vm2, Helpers.GetVMReferenceId(m_subId, resourceGroup2Name, vm2.Name)); vmsValidatedCount++; } } Assert.Equal(2, vmsValidatedCount); } finally { // Cleanup the created resources. rg2 first since the VM in it needs to be deleted before the // storage account, which is in rg1. try { m_ResourcesClient.ResourceGroups.Delete(resourceGroup2Name); } finally { m_ResourcesClient.ResourceGroups.Delete(resourceGroup1Name); } } } }
public void TestVMDiskSizeScenario() { using (var context = UndoContext.Current) { context.Start(); EnsureClientsInitialized(); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group var rgName = TestUtilities.GenerateName(TestPrefix); string storageAccountName = TestUtilities.GenerateName(TestPrefix); string asName = TestUtilities.GenerateName("as"); VirtualMachine inputVM; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var vm1 = CreateVM_NoAsyncTracking(rgName, asName, storageAccountOutput, imageRef, out inputVM, (vm) => { vm.StorageProfile.OSDisk.DiskSizeGB = 100; }); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True(getVMResponse.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, getVMResponse.VirtualMachine, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); } finally { var deleteResourceGroupResponse = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteResourceGroupResponse.StatusCode == HttpStatusCode.OK); } } }
public void TestVMBYOL() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { EnsureClientsInitialized(context); // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); VirtualMachine inputVM; string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); ImageReference dummyImageRef = null; // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); try { Action <VirtualMachine> useVMMImage = vm => { vm.StorageProfile.ImageReference = GetPlatformVMImage(true); vm.LicenseType = "Windows_Server"; }; VirtualMachine vm1 = null; try { vm1 = CreateVM_NoAsyncTracking(rgName, asName, storageAccountOutput, dummyImageRef, out inputVM, useVMMImage); } catch (Exception ex) { if (ex.Message.Contains("License type cannot be specified when creating a virtual machine from platform image. Please use an image from on-premises instead.")) { return; } throw; } var getResponse = m_CrpClient.VirtualMachines.GetWithHttpMessagesAsync(rgName, vm1.Name).GetAwaiter().GetResult(); Assert.True(getResponse.Response.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, getResponse.Body, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); var lroResponse = m_CrpClient.VirtualMachines.DeleteWithHttpMessagesAsync(rgName, inputVM.Name).GetAwaiter().GetResult(); Assert.True(lroResponse.Response.StatusCode == HttpStatusCode.OK); } finally { // Don't wait for RG deletion since it's too slow, and there is nothing interesting expected with // the resources from this test. //var deleteResourceGroupResponse = m_ResourcesClient.ResourceGroups.BeginDeleteWithHttpMessagesAsync(rgName); m_ResourcesClient.ResourceGroups.BeginDeleteWithHttpMessagesAsync(rgName); //Assert.True(deleteResourceGroupResponse.Result.Response.StatusCode == HttpStatusCode.Accepted || // deleteResourceGroupResponse.Result.Response.StatusCode == HttpStatusCode.NotFound); } } }
public void TestVMScenarioWithPlan() { using (var context = UndoContext.Current) { context.Start(); EnsureClientsInitialized(); string imgRefId = GetPlatformOSImage(useWindowsImage: true); var rgName = TestUtilities.GenerateName(TestPrefix); string storageAccountName = TestUtilities.GenerateName(TestPrefix); string asName = TestUtilities.GenerateName("as"); VirtualMachine inputVM; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var imageRef = new ImageReference { Publisher = "datastax", Offer = "datastax-enterprise-non-production-use-only", Sku = "sandbox_single-node", Version = "latest", }; var plan = new Microsoft.Azure.Management.Compute.Models.Plan { Publisher = imageRef.Publisher, Product = imageRef.Offer, Name = imageRef.Sku, }; var vm1 = CreateVM(rgName, asName, storageAccountOutput, imgRefId, out inputVM, (vm) => { vm.StorageProfile.SourceImage = null; vm.StorageProfile.ImageReference = imageRef; vm.Plan = plan; } ); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True(getVMResponse.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, getVMResponse.VirtualMachine, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); var listResponse = m_CrpClient.VirtualMachines.List(rgName); Assert.True(listResponse.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, listResponse.VirtualMachines.FirstOrDefault(x => x.Name == inputVM.Name), Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); } finally { var deleteResourceGroupResponse = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteResourceGroupResponse.StatusCode == HttpStatusCode.OK); } } }
public void TestVMScenarioOperations() { using (var context = UndoContext.Current) { context.Start(); EnsureClientsInitialized(); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group var rgName = TestUtilities.GenerateName(TestPrefix); string storageAccountName = TestUtilities.GenerateName(TestPrefix); string asName = TestUtilities.GenerateName("as"); VirtualMachine inputVM; try { // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var deleteVMResponse = m_CrpClient.VirtualMachines.Delete(rgName, "VMDoesNotExist"); Assert.True(deleteVMResponse.Status == OperationStatus.Succeeded); var deleteASResponse = m_CrpClient.AvailabilitySets.Delete(rgName, "ASDoesNotExist"); Assert.True(deleteASResponse.StatusCode == HttpStatusCode.NoContent); var vm1 = CreateVM_NoAsyncTracking(rgName, asName, storageAccountOutput, imageRef, out inputVM); 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 listResponse = m_CrpClient.VirtualMachines.List(rgName); Assert.True(listResponse.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, listResponse.VirtualMachines.FirstOrDefault(x => x.Name == inputVM.Name), Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); var listVMSizesResponse = m_CrpClient.VirtualMachines.ListAvailableSizes(rgName, inputVM.Name); Assert.True(listVMSizesResponse.StatusCode == HttpStatusCode.OK); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse); listVMSizesResponse = m_CrpClient.AvailabilitySets.ListAvailableSizes(rgName, asName); Assert.True(listVMSizesResponse.StatusCode == HttpStatusCode.OK); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse); var lroResponse = m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name); Assert.True(lroResponse.Status != OperationStatus.Failed); } finally { var deleteResourceGroupResponse = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteResourceGroupResponse.StatusCode == HttpStatusCode.OK); } } }
public void VMApplicationProfile_Tests() { string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); using (MockContext context = MockContext.Start(this.GetType())) { Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "centraluseuap"); EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); var image = m_CrpClient.VirtualMachineImages.Get( this.m_location, imageRef.Publisher, imageRef.Offer, imageRef.Sku, imageRef.Version); Assert.True(image != null); // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); VirtualMachine inputVM; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); IList <VMGalleryApplication> galleryApplications = new List <VMGalleryApplication>() { // when re-recording the test ensure that you use a valid packageReferenceId // refer to https://microsoft.sharepoint.com/:w:/t/ComputeVM/EcYeD-HHrLZHpYyxo3iRCtkB-VeO8BuWE4dq4hoX9tlzEg?e=nOTgTu // for how to create a valid VMApplication new VMGalleryApplication("/subscriptions/a53f7094-a16c-47af-abe4-b05c05d0d79a/resourceGroups/bhbrahma/providers/Microsoft.Compute/galleries/bhbrahmaGallery/applications/go/versions/1.15.8", treatFailureAsDeploymentFailure: true, enableAutomaticUpgrade: true) }; var vm1 = CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM, (vm) => { vm.StorageProfile.OsDisk.DiskSizeGB = 150; vm.ApplicationProfile = new ApplicationProfile(galleryApplications); }); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); ValidateVM(inputVM, getVMResponse, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); Assert.NotNull(getVMResponse.ApplicationProfile); Assert.NotNull(getVMResponse.ApplicationProfile.GalleryApplications); Assert.Equal(1, getVMResponse.ApplicationProfile.GalleryApplications.Count); VMGalleryApplication vmGalleryApplication = getVMResponse.ApplicationProfile.GalleryApplications[0]; Assert.True(vmGalleryApplication.TreatFailureAsDeploymentFailure); Assert.True(vmGalleryApplication.EnableAutomaticUpgrade); } finally { Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
public void TestDisablingHyperthreadingAndConstrainedvCPUsScenario() { string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap"); using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); var image = m_CrpClient.VirtualMachineImages.Get( this.m_location, imageRef.Publisher, imageRef.Offer, imageRef.Sku, imageRef.Version); Assert.True(image != null); Assert.NotNull(image.Disallowed.VmDiskType); // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); VirtualMachine inputVM; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); var vm1 = CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM, (vm) => { vm.StorageProfile.OsDisk.DiskSizeGB = 150; vm.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardD4V3; vm.HardwareProfile.VmSizeProperties = new VMSizeProperties { VCPUsAvailable = 1, VCPUsPerCore = 1 }; }); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); ValidateVM(inputVM, getVMResponse, Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); Assert.True(getVMResponse.HardwareProfile.VmSizeProperties.VCPUsAvailable == 1, "HardwareProfile.VmSizeProperties.VCPUsAvailable is not equal to 1"); Assert.True(getVMResponse.HardwareProfile.VmSizeProperties.VCPUsPerCore == 1, "HardwareProfile.VmSizeProperties.VCPUsPerCore is not equal to 1"); } finally { m_ResourcesClient.ResourceGroups.Delete(rgName); Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); } } }
public void TestVMScenarioOperations() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); VirtualMachine inputVM; try { // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); m_CrpClient.VirtualMachines.Delete(rgName, "VMDoesNotExist"); m_CrpClient.AvailabilitySets.Delete(rgName, "ASDoesNotExist"); var vm1 = CreateVM_NoAsyncTracking(rgName, asName, storageAccountOutput, imageRef, out inputVM); var getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name, InstanceViewTypes.InstanceView); Assert.True(getVMWithInstanceViewResponse != null, "VM in Get"); ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse); var listResponse = m_CrpClient.VirtualMachines.List(rgName); ValidateVM(inputVM, listResponse.FirstOrDefault(x => x.Name == inputVM.Name), Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name)); var listVMSizesResponse = m_CrpClient.VirtualMachines.ListAvailableSizes(rgName, inputVM.Name); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse); listVMSizesResponse = m_CrpClient.AvailabilitySets.ListAvailableSizes(rgName, asName); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse); m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name); } finally { m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
private void TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList <string> zones = null, string vmSize = "Standard_A1_v2", string osDiskStorageAccountType = "Standard_LRS", string dataDiskStorageAccountType = "Standard_LRS", bool?writeAcceleratorEnabled = null, bool hasDiffDisks = false, bool callUpdateVM = false, bool isPpgScenario = false, string diskEncryptionSetId = null, bool?encryptionAtHostEnabled = null, string securityType = null, bool isAutomaticPlacementOnDedicatedHostGroupScenario = false, ImageReference imageReference = null, bool validateListAvailableSize = true) { using (MockContext context = MockContext.Start(this.GetType(), methodName)) { EnsureClientsInitialized(context); ImageReference imageRef = imageReference ?? GetPlatformVMImage(useWindowsImage: true); const string expectedOSName = "Windows Server 2012 R2 Datacenter", expectedOSVersion = "Microsoft Windows NT 6.3.9600.0", expectedComputerName = ComputerName; // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); string ppgName = null, expectedPpgReferenceId = null; string dedicatedHostGroupName = null, dedicatedHostName = null, dedicatedHostGroupReferenceId = null, dedicatedHostReferenceId = null; if (isPpgScenario) { ppgName = ComputeManagementTestUtilities.GenerateName("ppgtest"); expectedPpgReferenceId = Helpers.GetProximityPlacementGroupRef(m_subId, rgName, ppgName); } 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); } VirtualMachine inputVM; try { if (!hasManagedDisks) { CreateStorageAccount(rgName, storageAccountName); } CreateVM(rgName, asName, storageAccountName, imageRef, out inputVM, hasManagedDisks: hasManagedDisks, hasDiffDisks: hasDiffDisks, vmSize: vmSize, osDiskStorageAccountType: osDiskStorageAccountType, dataDiskStorageAccountType: dataDiskStorageAccountType, writeAcceleratorEnabled: writeAcceleratorEnabled, zones: zones, ppgName: ppgName, diskEncryptionSetId: diskEncryptionSetId, encryptionAtHostEnabled: encryptionAtHostEnabled, securityType: securityType, dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId, dedicatedHostGroupName: dedicatedHostGroupName, dedicatedHostName: dedicatedHostName); // Instance view is not completely populated just after VM is provisioned. So we wait here for a few minutes to // allow GA blob to populate. ComputeManagementTestUtilities.WaitMinutes(5); var getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name, InstanceViewTypes.InstanceView); Assert.True(getVMWithInstanceViewResponse != null, "VM in Get"); if (diskEncryptionSetId != null) { Assert.True(getVMWithInstanceViewResponse.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet != null, "OsDisk.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getVMWithInstanceViewResponse.StorageProfile.OsDisk.ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "OsDisk.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); Assert.Equal(1, getVMWithInstanceViewResponse.StorageProfile.DataDisks.Count); Assert.True(getVMWithInstanceViewResponse.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet != null, ".DataDisks.ManagedDisk.DiskEncryptionSet is null"); Assert.True(string.Equals(diskEncryptionSetId, getVMWithInstanceViewResponse.StorageProfile.DataDisks[0].ManagedDisk.DiskEncryptionSet.Id, StringComparison.OrdinalIgnoreCase), "DataDisks.ManagedDisk.DiskEncryptionSet.Id is not matching with expected DiskEncryptionSet resource"); } ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion, dedicatedHostReferenceId); var getVMInstanceViewResponse = m_CrpClient.VirtualMachines.InstanceView(rgName, inputVM.Name); Assert.True(getVMInstanceViewResponse != null, "VM in InstanceView"); ValidateVMInstanceView(inputVM, getVMInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion, dedicatedHostReferenceId); bool hasUserDefinedAS = inputVM.AvailabilitySet != null; string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var listResponse = m_CrpClient.VirtualMachines.List(rgName); ValidateVM(inputVM, listResponse.FirstOrDefault(x => x.Name == inputVM.Name), expectedVMReferenceId, hasManagedDisks, hasUserDefinedAS, writeAcceleratorEnabled, hasDiffDisks, expectedPpgReferenceId: expectedPpgReferenceId, encryptionAtHostEnabled: encryptionAtHostEnabled, expectedDedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId); if (validateListAvailableSize) { var listVMSizesResponse = m_CrpClient.VirtualMachines.ListAvailableSizes(rgName, inputVM.Name); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); listVMSizesResponse = m_CrpClient.AvailabilitySets.ListAvailableSizes(rgName, asName); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); } if (securityType != null && securityType.Equals("TrustedLaunch")) { Assert.True(inputVM.SecurityProfile.UefiSettings.VTpmEnabled); Assert.True(inputVM.SecurityProfile.UefiSettings.SecureBootEnabled); } if (isPpgScenario) { ProximityPlacementGroup outProximityPlacementGroup = m_CrpClient.ProximityPlacementGroups.Get(rgName, ppgName); string expectedAvSetReferenceId = Helpers.GetAvailabilitySetRef(m_subId, rgName, asName); Assert.Equal(1, outProximityPlacementGroup.VirtualMachines.Count); Assert.Equal(1, outProximityPlacementGroup.AvailabilitySets.Count); Assert.Equal(expectedVMReferenceId, outProximityPlacementGroup.VirtualMachines.First().Id, StringComparer.OrdinalIgnoreCase); Assert.Equal(expectedAvSetReferenceId, outProximityPlacementGroup.AvailabilitySets.First().Id, StringComparer.OrdinalIgnoreCase); } if (callUpdateVM) { VirtualMachineUpdate updateParams = new VirtualMachineUpdate() { Tags = inputVM.Tags }; string updateKey = "UpdateTag"; updateParams.Tags.Add(updateKey, "UpdateTagValue"); VirtualMachine updateResponse = m_CrpClient.VirtualMachines.Update(rgName, inputVM.Name, updateParams); Assert.True(updateResponse.Tags.ContainsKey(updateKey)); } } finally { // Fire and forget. No need to wait for RG deletion completion try { m_ResourcesClient.ResourceGroups.BeginDelete(rgName); } catch (Exception e) { // Swallow this exception so that the original exception is thrown Console.WriteLine(e); } } } }
private void TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList <string> zones = null, string vmSize = "Standard_A0", string osDiskStorageAccountType = "Standard_LRS", string dataDiskStorageAccountType = "Standard_LRS", bool?writeAcceleratorEnabled = null, bool hasDiffDisks = false, bool callUpdateVM = false) { using (MockContext context = MockContext.Start(this.GetType().FullName, methodName)) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); const string expectedOSName = "Windows Server 2012 R2 Datacenter", expectedOSVersion = "Microsoft Windows NT 6.3.9600.0", expectedComputerName = ComputerName; // Create resource group var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); VirtualMachine inputVM; try { if (!hasManagedDisks) { CreateStorageAccount(rgName, storageAccountName); } CreateVM(rgName, asName, storageAccountName, imageRef, out inputVM, hasManagedDisks: hasManagedDisks, hasDiffDisks: hasDiffDisks, vmSize: vmSize, osDiskStorageAccountType: osDiskStorageAccountType, dataDiskStorageAccountType: dataDiskStorageAccountType, writeAcceleratorEnabled: writeAcceleratorEnabled, zones: zones); // Instance view is not completely populated just after VM is provisioned. So we wait here for a few minutes to // allow GA blob to populate. ComputeManagementTestUtilities.WaitMinutes(2); var getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name, InstanceViewTypes.InstanceView); Assert.True(getVMWithInstanceViewResponse != null, "VM in Get"); ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion); var getVMInstanceViewResponse = m_CrpClient.VirtualMachines.InstanceView(rgName, inputVM.Name); Assert.True(getVMInstanceViewResponse != null, "VM in InstanceView"); ValidateVMInstanceView(inputVM, getVMInstanceViewResponse, hasManagedDisks, expectedComputerName, expectedOSName, expectedOSVersion); bool hasUserDefinedAS = zones == null; var listResponse = m_CrpClient.VirtualMachines.List(rgName); ValidateVM(inputVM, listResponse.FirstOrDefault(x => x.Name == inputVM.Name), Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name), hasManagedDisks, hasUserDefinedAS, writeAcceleratorEnabled, hasDiffDisks); var listVMSizesResponse = m_CrpClient.VirtualMachines.ListAvailableSizes(rgName, inputVM.Name); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); listVMSizesResponse = m_CrpClient.AvailabilitySets.ListAvailableSizes(rgName, asName); Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks); if (callUpdateVM) { VirtualMachineUpdate updateParams = new VirtualMachineUpdate() { Tags = inputVM.Tags }; string updateKey = "UpdateTag"; updateParams.Tags.Add(updateKey, "UpdateTagValue"); VirtualMachine updateResponse = m_CrpClient.VirtualMachines.Update(rgName, inputVM.Name, updateParams); Assert.True(updateResponse.Tags.ContainsKey(updateKey)); } } finally { // Fire and forget. No need to wait for RG deletion completion try { m_ResourcesClient.ResourceGroups.BeginDelete(rgName); } catch (Exception e) { // Swallow this exception so that the original exception is thrown Console.WriteLine(e); } } } }
protected VirtualMachine CreateVM(string rgName, string asName, StorageAccount storageAccount, string imgRefId, out VirtualMachine inputVM, Action <VirtualMachine> vmCustomizer = null, bool createWithPublicIpAddress = false) { try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location }); PublicIpAddressGetResponse getPublicIpAddressResponse = createWithPublicIpAddress ? null : CreatePublicIP(rgName); SubnetGetResponse subnetResponse = CreateVNET(rgName); NetworkInterfaceGetResponse nicResponse = CreateNIC(rgName, subnetResponse.Subnet, getPublicIpAddressResponse.PublicIpAddress); string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccount.Name, imgRefId, asetId, nicResponse.NetworkInterface.Id); if (vmCustomizer != null) { vmCustomizer(inputVM); } string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = m_CrpClient.VirtualMachines.BeginCreatingOrUpdating( rgName, inputVM); Assert.True(createOrUpdateResponse.StatusCode == HttpStatusCode.Created); Assert.True(createOrUpdateResponse.VirtualMachine.Name == inputVM.Name); Assert.True(createOrUpdateResponse.VirtualMachine.Location == inputVM.Location.ToLower().Replace(" ", "") || createOrUpdateResponse.VirtualMachine.Location.ToLower() == inputVM.Location.ToLower()); Assert.True( createOrUpdateResponse.VirtualMachine.AvailabilitySetReference.ReferenceUri .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, createOrUpdateResponse.VirtualMachine, expectedVMReferenceId); var operationUri = new Uri(createOrUpdateResponse.AzureAsyncOperation); string operationId = operationUri.Segments.LastOrDefault(); var lroResponse = m_CrpClient.GetLongRunningOperationStatus(createOrUpdateResponse.AzureAsyncOperation.ToString()); ValidateLROResponse(lroResponse, operationId); var getResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True(getResponse.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, getResponse.VirtualMachine, expectedVMReferenceId); return(getResponse.VirtualMachine); } catch { var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK); throw; } }
protected VirtualMachine CreateVM_NoAsyncTracking( string rgName, string asName, StorageAccount storageAccount, ImageReference imageRef, out VirtualMachine inputVM, Action <VirtualMachine> vmCustomizer = null, bool createWithPublicIpAddress = false) { try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location }); PublicIpAddressGetResponse getPublicIpAddressResponse = createWithPublicIpAddress ? null : CreatePublicIP(rgName); SubnetGetResponse subnetResponse = CreateVNET(rgName); NetworkInterfaceGetResponse nicResponse = CreateNIC( rgName, subnetResponse.Subnet, getPublicIpAddressResponse != null ? getPublicIpAddressResponse.PublicIpAddress : null); string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccount.Name, imageRef, asetId, nicResponse.NetworkInterface.Id); if (vmCustomizer != null) { vmCustomizer(inputVM); } string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = m_CrpClient.VirtualMachines.BeginCreatingOrUpdating( rgName, inputVM); Assert.True(createOrUpdateResponse.StatusCode == HttpStatusCode.Created); Assert.True(createOrUpdateResponse.VirtualMachine.Name == inputVM.Name); Assert.True(createOrUpdateResponse.VirtualMachine.Location == inputVM.Location.ToLower().Replace(" ", "") || createOrUpdateResponse.VirtualMachine.Location.ToLower() == inputVM.Location.ToLower()); Assert.True( createOrUpdateResponse.VirtualMachine.AvailabilitySetReference.ReferenceUri .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, createOrUpdateResponse.VirtualMachine, expectedVMReferenceId); var operationUri = new Uri(createOrUpdateResponse.AzureAsyncOperation); string operationId = operationUri.Segments.LastOrDefault(); var lroResponse = m_CrpClient.GetLongRunningOperationStatus(createOrUpdateResponse.AzureAsyncOperation.ToString()); ValidateLROResponse(lroResponse, operationId); // CONSIDER dropping this Get and ValidateVM call. Nothing changes in the VM model after it's accepted. // There might have been intent to track the async operation to completion and then check the VM is // still this and okay, but that's not what the code above does and still doesn't make much sense. var getResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True(getResponse.StatusCode == HttpStatusCode.OK); ValidateVM(inputVM, getResponse.VirtualMachine, expectedVMReferenceId); return(getResponse.VirtualMachine); } catch { var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK); throw; } }
protected VirtualMachine CreateVM_NoAsyncTracking( string rgName, string asName, StorageAccount storageAccount, ImageReference imageRef, out VirtualMachine inputVM, Action <VirtualMachine> vmCustomizer = null, bool createWithPublicIpAddress = false, bool waitOperation = true) { try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location, Tags = new Dictionary <string, string>() { { rgName, DateTime.UtcNow.ToString("u") } } }); PublicIPAddress getPublicIpAddressResponse = createWithPublicIpAddress ? null : CreatePublicIP(rgName); Subnet subnetResponse = CreateVNET(rgName); NetworkInterface nicResponse = CreateNIC( rgName, subnetResponse, getPublicIpAddressResponse != null ? getPublicIpAddressResponse.IpAddress : null); string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccount.Name, imageRef, asetId, nicResponse.Id); if (vmCustomizer != null) { vmCustomizer(inputVM); } string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); VirtualMachine createOrUpdateResponse = null; if (waitOperation) { createOrUpdateResponse = m_CrpClient.VirtualMachines.CreateOrUpdate(rgName, inputVM.Name, inputVM); } else { createOrUpdateResponse = m_CrpClient.VirtualMachines.BeginCreateOrUpdate(rgName, inputVM.Name, inputVM); } Assert.True(createOrUpdateResponse.Name == inputVM.Name); Assert.True(createOrUpdateResponse.Location == inputVM.Location.ToLower().Replace(" ", "") || createOrUpdateResponse.Location.ToLower() == inputVM.Location.ToLower()); Assert.True( createOrUpdateResponse.AvailabilitySet.Id .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, createOrUpdateResponse, expectedVMReferenceId); // CONSIDER dropping this Get and ValidateVM call. Nothing changes in the VM model after it's accepted. // There might have been intent to track the async operation to completion and then check the VM is // still this and okay, but that's not what the code above does and still doesn't make much sense. var getResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); ValidateVM(inputVM, getResponse, expectedVMReferenceId); return(getResponse); } catch { m_ResourcesClient.ResourceGroups.Delete(rgName); throw; } }
public void TestListVMInSubscription() { using (var context = UndoContext.Current) { context.Start(); EnsureClientsInitialized(); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); string baseRGName = TestUtilities.GenerateName(TestPrefix); string rg1Name = baseRGName + "_1"; string rg2Name = baseRGName + "_2"; string asName = TestUtilities.GenerateName("as"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachine inputVM1, inputVM2; try { // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rg1Name, storageAccountName); var vm1 = CreateVM_NoAsyncTracking(rg1Name, asName, storageAccountOutput, imageRef, out inputVM1); var vm2 = CreateVM_NoAsyncTracking(rg2Name, asName, storageAccountOutput, imageRef, out inputVM2); var listResponse = m_CrpClient.VirtualMachines.ListAll(new ListParameters()); Assert.True(listResponse.StatusCode == HttpStatusCode.OK); Assert.True(listResponse.VirtualMachines.Count >= 2); Assert.Null(listResponse.NextLink); int vmsValidatedCount = 0; foreach (var vm in listResponse.VirtualMachines) { if (vm.Name == vm1.Name) { ValidateVM(vm, vm1, Helpers.GetVMReferenceId(m_subId, rg1Name, vm1.Name)); vmsValidatedCount++; } else if (vm.Name == vm2.Name) { ValidateVM(vm, vm2, Helpers.GetVMReferenceId(m_subId, rg2Name, vm2.Name)); vmsValidatedCount++; } } Assert.True(vmsValidatedCount == 2); } finally { // Cleanup the created resources. rg2 first since the VM in it needs to be deleted before the // storage account, which is in rg1. try { var deleteRg2Response = m_ResourcesClient.ResourceGroups.Delete(rg2Name); Assert.True(deleteRg2Response.StatusCode == HttpStatusCode.OK); } finally { var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rg1Name); Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK); } } } }
public void TestMultiIpConfigForMultiNICVM() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); string rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); VirtualMachine inputVM; try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location, Tags = new Dictionary <string, string>() { { rgName, DateTime.UtcNow.ToString("u") } } }); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); Subnet subnetResponse = CreateVNET(rgName); string nicname1 = ComputeManagementTestUtilities.GenerateName(null); string nicname2 = ComputeManagementTestUtilities.GenerateName(null); NetworkInterface nicResponse1 = CreateMultiIpConfigNIC(rgName, subnetResponse, nicname1); NetworkInterface nicResponse2 = CreateMultiIpConfigNIC(rgName, subnetResponse, nicname2); string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId, nicResponse1.Id); inputVM.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardA4V2; inputVM.NetworkProfile.NetworkInterfaces[0].Primary = false; inputVM.NetworkProfile.NetworkInterfaces.Add(new NetworkInterfaceReference { Id = nicResponse2.Id, Primary = true }); string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = m_CrpClient.VirtualMachines.CreateOrUpdate(rgName, inputVM.Name, inputVM); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True( getVMResponse.AvailabilitySet.Id .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, getVMResponse, expectedVMReferenceId); var getNicResponse1 = m_NrpClient.NetworkInterfaces.Get(rgName, nicResponse1.Name); // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode Assert.NotNull(getNicResponse1.MacAddress); Assert.NotNull(getNicResponse1.Primary); Assert.True(getNicResponse1.Primary != null && !getNicResponse1.Primary.Value); var getNicResponse2 = m_NrpClient.NetworkInterfaces.Get(rgName, nicResponse2.Name); // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode Assert.NotNull(getNicResponse2.MacAddress); Assert.NotNull(getNicResponse2.Primary); Assert.True(getNicResponse2.Primary != null && getNicResponse2.Primary.Value); // multi CA Assertions Assert.Equal(2, getNicResponse1.IpConfigurations.Count); Assert.Equal(2, getNicResponse2.IpConfigurations.Count); Assert.Single(getNicResponse1.IpConfigurations.Where(x => x.Primary == true)); Assert.Single(getNicResponse2.IpConfigurations.Where(x => x.Primary == true)); } finally { // Cleanup the created resources m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
public void TestEffectiveRouteAndAcls() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); string rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); VirtualMachine inputVM; try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location, Tags = new Dictionary <string, string>() { { rgName, DateTime.UtcNow.ToString("u") } } }); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); Subnet subnetResponse = CreateVNET(rgName); NetworkSecurityGroup nsgResponse = CreateNsg(rgName); NetworkInterface nicResponse = CreateNIC(rgName, subnetResponse, null, null, nsgResponse); string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId, nicResponse.Id); string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = m_CrpClient.VirtualMachines.CreateOrUpdate( rgName, inputVM.Name, inputVM); Assert.NotNull(createOrUpdateResponse); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True( getVMResponse.AvailabilitySet.Id .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, getVMResponse, expectedVMReferenceId); var getNicResponse = m_NrpClient.NetworkInterfaces.Get(rgName, nicResponse.Name); // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode Assert.NotNull(getNicResponse.MacAddress); Assert.NotNull(getNicResponse.Primary); Assert.True(getNicResponse.Primary != null && getNicResponse.Primary.Value); // Get Effective RouteTable var getEffectiveRouteTable = m_NrpClient.NetworkInterfaces.GetEffectiveRouteTable(rgName, nicResponse.Name); Assert.NotNull(getEffectiveRouteTable); Assert.NotEqual(0, getEffectiveRouteTable.Value.Count); Assert.Equal(getEffectiveRouteTable.Value[0].Source, EffectiveRouteSource.Default); Assert.Equal(getEffectiveRouteTable.Value[0].State, EffectiveRouteState.Active); // Get Effecting NSG var getEffectiveNSGresponse = m_NrpClient.NetworkInterfaces.ListEffectiveNetworkSecurityGroups(rgName, nicResponse.Name); Assert.NotNull(getEffectiveNSGresponse); Assert.NotEqual(0, getEffectiveNSGresponse.Value.Count); Assert.NotNull(getEffectiveNSGresponse.Value[0].Association); Assert.NotNull(getEffectiveNSGresponse.Value[0].Association.NetworkInterface); Assert.Null(getEffectiveNSGresponse.Value[0].Association.Subnet); Assert.Equal(getEffectiveNSGresponse.Value[0].Association.NetworkInterface.Id, nicResponse.Id); Assert.NotNull(getEffectiveNSGresponse.Value[0].NetworkSecurityGroup); Assert.Equal(getEffectiveNSGresponse.Value[0].NetworkSecurityGroup.Id, nsgResponse.Id); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules); Assert.NotEqual(0, getEffectiveNSGresponse.Value[0].EffectiveSecurityRules.Count); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].Access); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].DestinationAddressPrefix); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].DestinationPortRange); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].SourceAddressPrefix); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].SourcePortRange); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].Priority); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].Name); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].ExpandedDestinationAddressPrefix); Assert.NotNull(getEffectiveNSGresponse.Value[0].EffectiveSecurityRules[0].ExpandedSourceAddressPrefix); } finally { // Cleanup the created resources m_ResourcesClient.ResourceGroups.Delete(rgName); } } }
public void TestMultiNicVirtualMachineReference() { using (var context = UndoContext.Current) { context.Start(); EnsureClientsInitialized(); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); string rgName = TestUtilities.GenerateName(TestPrefix); string asName = TestUtilities.GenerateName("as"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachine inputVM; try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location }); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); SubnetGetResponse subnetResponse = CreateVNET(rgName); string nicname1 = TestUtilities.GenerateName(); string nicname2 = TestUtilities.GenerateName(); NetworkInterfaceGetResponse nicResponse1 = CreateNIC(rgName, subnetResponse.Subnet, null, nicname1); NetworkInterfaceGetResponse nicResponse2 = CreateNIC(rgName, subnetResponse.Subnet, null, nicname2); string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId, nicResponse1.NetworkInterface.Id); inputVM.HardwareProfile.VirtualMachineSize = VirtualMachineSizeTypes.StandardA4; inputVM.NetworkProfile.NetworkInterfaces[0].Primary = false; inputVM.NetworkProfile.NetworkInterfaces.Add(new NetworkInterfaceReference { ReferenceUri = nicResponse2.NetworkInterface.Id, Primary = true }); string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = m_CrpClient.VirtualMachines.CreateOrUpdate(rgName, inputVM); Assert.True(createOrUpdateResponse.StatusCode == HttpStatusCode.OK); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); Assert.True( getVMResponse.VirtualMachine.AvailabilitySetReference.ReferenceUri .ToLowerInvariant() == asetId.ToLowerInvariant()); ValidateVM(inputVM, getVMResponse.VirtualMachine, expectedVMReferenceId); var getNicResponse1 = m_NrpClient.NetworkInterfaces.Get(rgName, nicResponse1.NetworkInterface.Name); Assert.NotNull(getNicResponse1.NetworkInterface.MacAddress); Assert.NotNull(getNicResponse1.NetworkInterface.Primary); Assert.True(getNicResponse1.NetworkInterface.Primary != null && !getNicResponse1.NetworkInterface.Primary.Value); var getNicResponse2 = m_NrpClient.NetworkInterfaces.Get(rgName, nicResponse2.NetworkInterface.Name); Assert.NotNull(getNicResponse2.NetworkInterface.MacAddress); Assert.NotNull(getNicResponse2.NetworkInterface.Primary); Assert.True(getNicResponse2.NetworkInterface.Primary != null && getNicResponse2.NetworkInterface.Primary.Value); } finally { // Cleanup the created resources var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rgName); Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK); } } }
public void TestVirtualMachineNicConfiguration() { string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); using (MockContext context = MockContext.Start(this.GetType())) { // Hard code the location to "eastus2euap". // 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. Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap"); EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); string rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix); //string asName = ComputeManagementTestUtilities.GenerateName("as"); string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix); VirtualMachine inputVM; try { // Create the resource Group, it might have been already created during StorageAccount creation. var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate( rgName, new ResourceGroup { Location = m_location, Tags = new Dictionary <string, string>() { { rgName, DateTime.UtcNow.ToString("u") } } }); // Create Storage Account, so that both the VMs can share it var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); Subnet subnetResponse = CreateVNET(rgName); VirtualMachineNetworkInterfaceConfiguration vmNicConfig = CreateNICConfig(subnetResponse); //string asetId = CreateAvailabilitySet(rgName, asName); inputVM = CreateDefaultVMInput(rgName, storageAccountName, imageRef, asetId: null, vmNicConfig: vmNicConfig, networkApiVersion: NetworkApiVersion.TwoZeroTwoZeroHyphenMinusOneOneHyphenMinusZeroOne); string expectedVMReferenceId = Helpers.GetVMReferenceId(m_subId, rgName, inputVM.Name); var createOrUpdateResponse = m_CrpClient.VirtualMachines.CreateOrUpdate( rgName, inputVM.Name, inputVM); Assert.NotNull(createOrUpdateResponse); var getVMResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name); ValidateVM(inputVM, getVMResponse, expectedVMReferenceId, hasUserDefinedAS: false); var getNicResponse = m_NrpClient.NetworkInterfaces.List(rgName); // TODO AutoRest: Recording Passed, but these assertions failed in Playback mode Assert.NotNull(getNicResponse.FirstOrDefault().MacAddress); Assert.NotNull(getNicResponse.FirstOrDefault().Primary); Assert.True(getNicResponse.FirstOrDefault().Primary != null && getNicResponse.FirstOrDefault().Primary.Value); } finally { Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); // Cleanup the created resources m_ResourcesClient.ResourceGroups.Delete(rgName); } } }