/// <summary> /// Generates a disk used when the DiskCreateOption is Import /// </summary> /// <returns></returns> private Disk GenerateImportDisk(string diskCreateOption, string rgName) { // Create a VM, so we can use its OS disk for creating the image string storageAccountName = ComputeManagementTestUtilities.GenerateName(DiskNamePrefix); string asName = ComputeManagementTestUtilities.GenerateName("as"); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); VirtualMachine inputVM = null; // Create Storage Account var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); // Create the VM, whose OS disk will be used in creating the image var createdVM = CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM); var listResponse = m_CrpClient.VirtualMachines.ListAll(); Assert.True(listResponse.Count() >= 1); string[] id = createdVM.Id.Split('/'); string subscription = id[2]; var uri = createdVM.StorageProfile.OsDisk.Vhd.Uri; m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name); m_CrpClient.VirtualMachines.Delete(rgName, createdVM.Name); Disk disk = GenerateBaseDisk(diskCreateOption); disk.CreationData.SourceUri = uri; disk.CreationData.StorageAccountId = "subscriptions/" + subscription + "/resourceGroups/" + rgName + "/providers/Microsoft.Storage/storageAccounts/" + storageAccountName; return(disk); }
public void DiskManagedByTest() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { EnsureClientsInitialized(context); var rgName = TestUtilities.GenerateName(TestPrefix); var diskName = TestUtilities.GenerateName(DiskNamePrefix); // Create a VM, so we can use its OS disk for testing managedby string storageAccountName = ComputeManagementTestUtilities.GenerateName(DiskNamePrefix); string avSet = ComputeManagementTestUtilities.GenerateName("avSet"); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); VirtualMachine inputVM = null; // Create Storage Account for creating vm var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); // Create the VM, whose OS disk will be used in creating the image var createdVM = CreateVM(rgName, avSet, storageAccountOutput, imageRef, out inputVM, hasManagedDisks: true); var listResponse = m_CrpClient.VirtualMachines.ListAll(); Assert.True(listResponse.Count() >= 1); var vmName = createdVM.Name; var vmDiskName = createdVM.StorageProfile.OsDisk.Name; //get disk from VM Disk diskFromVM = m_CrpClient.Disks.Get(rgName, vmDiskName); //managedby should have format: "/subscriptions/{subId}/resourceGroups/{rg}/Microsoft.Compute/virtualMachines/vm1" Assert.Contains(vmName, diskFromVM.ManagedBy); m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name); m_CrpClient.VirtualMachines.Delete(rgName, createdVM.Name); m_CrpClient.Disks.Delete(rgName, diskName); m_ResourcesClient.ResourceGroups.Delete(rgName); } }
public void CanUpdateVMDisk() { TestLogTracingInterceptor.Current.Start(); using (var undoContext = UndoContext.Current) { undoContext.Start(); var mgmt = fixture.GetManagementClient(); var compute = fixture.GetComputeManagementClient(); var storage = fixture.GetStorageManagementClient(); try { string storageAccountName = TestUtilities.GenerateName("psteststo").ToLower(); string serviceName = TestUtilities.GenerateName("pstestsvc"); string serviceLabel = serviceName + "1"; string serviceDescription = serviceName + "2"; string deploymentName = string.Format("{0}Prod", serviceName); string deploymentLabel = deploymentName; string location = mgmt.GetDefaultLocation("Storage", "Compute"); const string usWestLocStr = "West US"; if (mgmt.Locations.List().Any( c => string.Equals(c.Name, usWestLocStr, StringComparison.OrdinalIgnoreCase))) { location = usWestLocStr; } storage.StorageAccounts.Create( new StorageAccountCreateParameters { Location = location, Label = storageAccountName, Name = storageAccountName, AccountType = StorageAccountTypes.StandardGRS }); compute.HostedServices.Create( new HostedServiceCreateParameters { Location = location, Label = serviceDescription, Description = serviceLabel, ServiceName = serviceName, ExtendedProperties = new Dictionary <string, string> { { "foo1", "bar" }, { "foo2", "baz" } } }); var hostedService = compute.HostedServices.Get(serviceName); Assert.True(hostedService.Properties.Label == serviceDescription); Assert.True(hostedService.Properties.Description == serviceLabel); Assert.True(hostedService.Properties.ExtendedProperties["foo1"] == "bar"); Assert.True(hostedService.Properties.ExtendedProperties["foo2"] == "baz"); var image = compute.VirtualMachineOSImages.List() .FirstOrDefault(s => string.Equals(s.OperatingSystemType, "Windows", StringComparison.OrdinalIgnoreCase) && s.LogicalSizeInGB < 100); Assert.True(!string.IsNullOrEmpty(image.IOType)); var osDiskSourceUri = new Uri(string.Format( "http://{1}.blob.core.windows.net/myvhds/{0}.vhd", serviceName, storageAccountName)); var dataDiskSourceUri = new Uri(string.Format( "http://{1}.blob.core.windows.net/myvhds/{0}5.vhd", serviceName, storageAccountName)); compute.VirtualMachines.CreateDeployment( serviceName, new VirtualMachineCreateDeploymentParameters { Name = deploymentName, DeploymentSlot = DeploymentSlot.Production, Label = deploymentLabel, Roles = new List <Role>() { new Role() { ProvisionGuestAgent = false, ResourceExtensionReferences = null, RoleName = serviceName, RoleType = VirtualMachineRoleType.PersistentVMRole.ToString(), RoleSize = VirtualMachineRoleSize.Large.ToString(), OSVirtualHardDisk = new OSVirtualHardDisk { HostCaching = VirtualHardDiskHostCaching.ReadWrite, SourceImageName = image.Name, MediaLink = osDiskSourceUri, }, DataVirtualHardDisks = new List <DataVirtualHardDisk>( Enumerable.Repeat(new DataVirtualHardDisk { Label = "testDataDiskLabel5", LogicalUnitNumber = 0, LogicalDiskSizeInGB = 1, HostCaching = "ReadOnly", MediaLink = dataDiskSourceUri, }, 1)), ConfigurationSets = new List <ConfigurationSet>() { new ConfigurationSet { AdminUserName = "******", AdminPassword = "******", ConfigurationSetType = ConfigurationSetTypes .WindowsProvisioningConfiguration, ComputerName = serviceName, HostName = string.Format("{0}.cloudapp.net", serviceName), EnableAutomaticUpdates = false, TimeZone = "Pacific Standard Time" }, } } }, }); // Create virtual disks string dataDiskBlobName = "datadisk.vhd"; string osDiskBlobName = "osdisk.vhd"; var dataDiskBlobUri = ComputeManagementTestUtilities.CopyBlobInStorage( storageAccountName, dataDiskSourceUri, "myvhds", dataDiskBlobName); var osDiskBlobUri = ComputeManagementTestUtilities.CopyBlobInStorage( storageAccountName, osDiskSourceUri, "myvhds", osDiskBlobName); string dataDiskName = TestUtilities.GenerateName("datadisk"); string osDiskName = TestUtilities.GenerateName("osdisk"); string dataDiskLabel = "DataDiskLabelOld"; string osDiskLabel = "OSDiskLabelOld"; compute.VirtualMachineDisks.CreateDisk(new VirtualMachineDiskCreateParameters() { Name = dataDiskName, Label = dataDiskLabel, MediaLinkUri = dataDiskBlobUri, }); compute.VirtualMachineDisks.CreateDisk(new VirtualMachineDiskCreateParameters() { Name = osDiskName, Label = osDiskLabel, MediaLinkUri = osDiskBlobUri, OperatingSystemType = "Windows", }); // Verify disks before update var dataDiskReturned = compute.VirtualMachineDisks.GetDisk(dataDiskName); var osDiskReturned = compute.VirtualMachineDisks.GetDisk(osDiskName); Assert.Equal(dataDiskName, dataDiskReturned.Name); Assert.Equal(dataDiskLabel, dataDiskReturned.Label); Assert.Equal(1, dataDiskReturned.LogicalSizeInGB); Assert.Equal(osDiskName, osDiskReturned.Name); Assert.Equal(osDiskLabel, osDiskReturned.Label); Assert.True(osDiskReturned.LogicalSizeInGB < 100); Assert.Equal("Windows", osDiskReturned.OperatingSystemType); // Updating disks dataDiskLabel = "DataDiskLabelNew"; osDiskLabel = "OSDiskLabelNew"; compute.VirtualMachineDisks.UpdateDiskSize(dataDiskName, new VirtualMachineDiskUpdateParameters() { Name = dataDiskName, Label = dataDiskLabel, ResizedSizeInGB = 500, }); compute.VirtualMachineDisks.UpdateDiskSize(osDiskName, new VirtualMachineDiskUpdateParameters() { Name = osDiskName, Label = osDiskLabel, ResizedSizeInGB = 128, }); // Verify disks after update dataDiskReturned = compute.VirtualMachineDisks.GetDisk(dataDiskName); osDiskReturned = compute.VirtualMachineDisks.GetDisk(osDiskName); Assert.Equal(dataDiskName, dataDiskReturned.Name); Assert.Equal(dataDiskLabel, dataDiskReturned.Label); Assert.Equal(500, dataDiskReturned.LogicalSizeInGB); Assert.Equal(osDiskName, osDiskReturned.Name); Assert.Equal(osDiskLabel, osDiskReturned.Label); Assert.Equal(128, osDiskReturned.LogicalSizeInGB); Assert.Equal("Windows", osDiskReturned.OperatingSystemType); // Delete the service compute.HostedServices.DeleteAll(serviceName); } finally { undoContext.Dispose(); mgmt.Dispose(); compute.Dispose(); storage.Dispose(); TestLogTracingInterceptor.Current.Stop(); } } }
public void VMImage() { TestLogTracingInterceptor.Current.Start(); using (var undoContext = UndoContext.Current) { undoContext.Start(); var mgmt = fixture.GetManagementClient(); var compute = ComputeManagementTestUtilities.GetComputeManagementClient(fixture); var storage = fixture.GetStorageManagementClient(); // Test only in Dogfood environment if (compute.BaseUri.ToString().Contains(".management.core.windows.net")) { return; } try { string storageAccountName = TestUtilities.GenerateName("rdfepir").ToLower(); var vmImageName = TestUtilities.GenerateName("vmimage").ToLower(); var vmImageBlobName = vmImageName + ".vhd"; var publicVMImageBlob_Linux_WestUS = new Uri("http://longlivedstoragerruswest.blob.core.test-cint.azure-test.net/vhdblobs/CoreOS-Stable-Generalized.30GB.vhd"); string location = "West US"; try { // ************** // SETUP // ************** // Create storage account. Used to place vhd blobs. storage.StorageAccounts.Create( new StorageAccountCreateParameters { Location = location, Label = storageAccountName, Name = storageAccountName, AccountType = StorageAccountTypes.StandardGRS }); // Copy public vmimage blob into our storage account (needed for vmimage create call to work). var vmImageBlobUri = Microsoft.Azure.Test.ComputeManagementTestUtilities.CopyPageBlobInStorage( storageAccountName, publicVMImageBlob_Linux_WestUS, "vmimages", vmImageBlobName); // Create vmimage from vhd in our storage account blob. Now we can create VMs from this image. compute.VirtualMachineVMImages.Create( new VirtualMachineVMImageCreateParameters { Name = vmImageName, Label = "test", Description = "test", Eula = "http://test.com", SmallIconUri = "test", IconUri = "test", PrivacyUri = new Uri("http://test.com/"), ShowInGui = false, ImageFamily = "test", Language = "test", PublishedDate = DateTime.Now, RecommendedVMSize = VirtualMachineRoleSize.Small, OSDiskConfiguration = new OSDiskConfigurationCreateParameters { HostCaching = VirtualHardDiskHostCaching.ReadWrite, OS = VirtualMachineVMImageOperatingSystemType.Windows, OSState = VirtualMachineVMImageOperatingSystemState.Generalized, MediaLink = vmImageBlobUri } }); // ************** // TESTS // ************** var vmImageParamater = new VirtualMachineVMImageReplicateParameters() { TargetLocations = new[] { location }, ComputeImageAttributes = new ComputeImageAttributes() { Offer = "TestOffer", Sku = "Standard", Version = "1.0.0" }, // Providing this should fail for a subscription that // does not have image market place rights. // Only one customer can hve image market place rights. MarketplaceImageAttributes = new MarketplaceImageAttributes() { PublisherId = "publisherId", Plan = new Plan() { Name = "PlanName", Publisher = "PlanPublisher", Product = "PlanProduct" } } }; // Replicate (check new contract with ComputeImageAttributes and MarketplaceImageAttributes is accepted - 200 OK) var replicateResponse = compute.VirtualMachineVMImages.Replicate(vmImageName, vmImageParamater); Assert.Equal(HttpStatusCode.OK, replicateResponse.StatusCode); Assert.True(!string.IsNullOrEmpty(replicateResponse.RequestId)); // ListDetails (check new contract with ComputeImageAttributes and MarketplaceImageAttributes is returned) var vmImage = compute.VirtualMachineVMImages.GetDetails(vmImageName); Assert.NotNull(vmImage.ComputeImageAttributes); Assert.Equal(vmImageParamater.ComputeImageAttributes.Offer, vmImage.ComputeImageAttributes.Offer); Assert.Equal(vmImageParamater.ComputeImageAttributes.Version, vmImage.ComputeImageAttributes.Version); Assert.Equal(vmImageParamater.ComputeImageAttributes.Sku, vmImage.ComputeImageAttributes.Sku); Assert.NotNull(vmImage.MarketplaceImageAttributes); Assert.Equal(vmImageParamater.MarketplaceImageAttributes.PublisherId, vmImage.MarketplaceImageAttributes.PublisherId); Assert.NotNull(vmImage.MarketplaceImageAttributes.Plan); Assert.Equal(vmImageParamater.MarketplaceImageAttributes.Plan.Name, vmImage.MarketplaceImageAttributes.Plan.Name); Assert.Equal(vmImageParamater.MarketplaceImageAttributes.Plan.Product, vmImage.MarketplaceImageAttributes.Plan.Product); Assert.Equal(vmImageParamater.MarketplaceImageAttributes.Plan.Publisher, vmImage.MarketplaceImageAttributes.Plan.Publisher); // Share async (check new async share succeeds) var shareResponse = compute.VirtualMachineVMImages.Share(vmImageName, "Private"); Assert.Equal(OperationStatus.Succeeded, shareResponse.Status); Assert.True(!string.IsNullOrEmpty(shareResponse.RequestId)); } finally { // CLEANUP // Unreplicate vm image compute.VirtualMachineVMImages.Unreplicate(vmImageName); // Delete vm image compute.VirtualMachineVMImages.Delete(vmImageName, true); // Delete storage account storage.StorageAccounts.Delete(storageAccountName); } } finally { undoContext.Dispose(); mgmt.Dispose(); compute.Dispose(); storage.Dispose(); TestLogTracingInterceptor.Current.Stop(); } } }