public void Resize_Vhd_Blob_Shrink() { var firstSizeInGb = 2; var newSizeInGb = 1; var vhdFilePath = "TestDisk-Shrink.vhd"; var containerName = "test-container"; // First create the fixed VHD file VhdHelper.CreateVhdDisk(false, firstSizeInGb, vhdFilePath, "Testing Shrink Disk"); var vhdBlobUri = AzureStorageEmulatorHelper.UploadVhdFileToContainer(containerName, vhdFilePath); // Then resize the VHD file var resizeVhdHelper = new ResizeVhdHelper(); var firstResult = resizeVhdHelper.ResizeVhdBlob(newSizeInGb, vhdBlobUri, accountName, accountKey); var finalResult = ResizeResult.Error; if (firstResult == ResizeResult.Shrink) { resizeVhdHelper.IsExpand = false; finalResult = resizeVhdHelper.DoResizeVhdBlob(); } var length = AzureStorageEmulatorHelper.GetVhdSizeInContainer(vhdBlobUri); // Clean the files in the container and the local file system AddCleanupAction(() => AzureStorageEmulatorHelper.DeleteVhdFileInContainer(containerName, vhdBlobUri)); AddCleanupAction(() => File.Delete(vhdFilePath)); Assert.IsTrue(firstResult == ResizeResult.Shrink); Assert.IsTrue(finalResult == ResizeResult.Success); Assert.IsTrue(newSizeInGb == (int)ByteSize.FromBytes(length).GigaBytes); }
public void Resize_Vhd_Blob_Not_Exists() { var newSizeInGb = 1; var blobUri = new Uri(testDiskUri); var resizeVhdHelper = new ResizeVhdHelper(); var result = resizeVhdHelper.ResizeVhdBlob(newSizeInGb, blobUri, accountName, accountKey); Assert.IsTrue(result == ResizeResult.Error); }
public void Resize_Vhd_Blob_Empty_Account_Details() { var newSizeInGb = 1; var blobUri = new Uri(testDiskUri); var resizeVhdHelper = new ResizeVhdHelper(); var result = resizeVhdHelper.ResizeVhdBlob(newSizeInGb, blobUri, null, null); Assert.IsTrue(result == ResizeResult.Error); }
public void Resize_Vhd_Blob_Not_Exists_And_Bytes_Are_The_Same() { var newSizeInGb = 1; var blobUri = new Uri(testDiskUri); var resizeVhdHelper = new ResizeVhdHelper(); var result = resizeVhdHelper.ResizeVhdBlob(newSizeInGb, blobUri, accountName, accountKey); Assert.IsTrue(result == ResizeResult.Error); Assert.AreEqual(ByteSize.FromGigaBytes(newSizeInGb).Bytes, resizeVhdHelper.NewSize.Bytes); }
public void Resize_Vhd_Blob_Fail() { using (ShimsContext.Create()) { var newSizeInGb = 1; var blobUri = new Uri(testDiskUri); ShimCloudBlob.AllInstances.ExistsBlobRequestOptionsOperationContext = (blob, opts, context) => { throw new StorageException(); }; var resizeVhdHelper = new ResizeVhdHelper(); var result = resizeVhdHelper.ResizeVhdBlob(newSizeInGb, blobUri, accountName, accountKey); Assert.IsTrue(result == ResizeResult.Error); } }
public void Resize_Vhd_Blob_Dynamic_Disk() { var newSizeInGb = 1; var vhdFilePath = "TestDisk-Dynamic.vhd"; var containerName = "test-container"; // First create the dynamic VHD file VhdHelper.CreateVhdDisk(true, newSizeInGb, vhdFilePath, "Testing Disk"); var vhdBlobUri = AzureStorageEmulatorHelper.UploadVhdFileToContainer(containerName, vhdFilePath); // Then resize the VHD file var resizeVhdHelper = new ResizeVhdHelper(); var result = resizeVhdHelper.ResizeVhdBlob(newSizeInGb, vhdBlobUri, accountName, accountKey); var length = AzureStorageEmulatorHelper.GetVhdSizeInContainer(vhdBlobUri); // Clean the files in the container and the local file system AddCleanupAction(() => AzureStorageEmulatorHelper.DeleteVhdFileInContainer(containerName, vhdBlobUri)); AddCleanupAction(() => File.Delete(vhdFilePath)); Assert.IsTrue(result == ResizeResult.Error); Assert.IsTrue(ByteSize.FromGigaBytes(newSizeInGb) != ByteSize.FromBytes(length)); }
private static int Main(string[] args) { WriteHeader(); // Check argument count if (args.Length < 2) { WriteUsage(); return(-1); } // Parse arguments if (!long.TryParse(args[0], out long newSizeInGb) || (newSizeInGb * 1024 * 1024 * 1024) % 512 != 0) { Console.WriteLine("Argument size invalid. Please specify a valid disk size in GB (must be a whole number)."); return(-1); } if (!Uri.TryCreate(args[1], UriKind.Absolute, out Uri blobUri)) { Console.WriteLine("Argument bloburl invalid. Please specify a valid URL with an HTTP or HTTPS schema."); return(-1); } var accountName = ""; var accountKey = ""; if (args.Length == 4) { accountName = args[2]; accountKey = args[3]; } else if (!blobUri.Query.Contains("sig=")) { Console.WriteLine("Please specify either a blob URL with a shared access signature that allows write access or provide full storage credentials."); return(-1); } // Verify size. Size for disk must be <= 1023 GB if (newSizeInGb > 1023) { Console.WriteLine("The given disk size exceeds 1023 GB. Microsoft Azure will not be able to start the virtual machine stored on this disk if you continue."); Console.WriteLine("See https://msdn.microsoft.com/en-us/library/azure/dn197896.aspx for more information."); return(-1); } // Start the resize process var resizeVhdHelper = new ResizeVhdHelper(); var result = resizeVhdHelper.ResizeVhdBlob((int)newSizeInGb, blobUri, accountName, accountKey); if (result != ResizeResult.Shrink) { return((int)result); } Console.WriteLine("The specified VHD blob is larger than the specified new size. Shrinking disks is a potentially dangerous operation."); Console.WriteLine("Do you want to continue with shrinking the disk? (y/n)"); while (true) { var consoleKey = Console.ReadKey().KeyChar; if (consoleKey == 'n') { Console.WriteLine("Aborted."); return(-1); } if (consoleKey == 'y') { resizeVhdHelper.IsExpand = false; var finalResult = resizeVhdHelper.DoResizeVhdBlob(); return((int)finalResult); } } }