You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by wi...@apache.org on 2013/02/25 15:44:57 UTC
[24/28] git commit: refs/heads/qemu-img - Add more extensive tests
for resizing
Add more extensive tests for resizing
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/23a40a2b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/23a40a2b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/23a40a2b
Branch: refs/heads/qemu-img
Commit: 23a40a2be6dddfac45970919e76caf470fc0417e
Parents: e5b23b8
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Mon Feb 25 14:54:15 2013 +0100
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Mon Feb 25 14:54:15 2013 +0100
----------------------------------------------------------------------
.../org/apache/cloudstack/utils/qemu/QemuImg.java | 7 +-
.../apache/cloudstack/utils/qemu/QemuImgTest.java | 90 +++++++++++++--
2 files changed, 88 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23a40a2b/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
----------------------------------------------------------------------
diff --git a/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java b/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
index fe2af6c..45d2f13 100644
--- a/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
+++ b/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
@@ -299,11 +299,16 @@ public class QemuImg {
public void resize(QemuImgFile file, long size, boolean delta) throws QemuImgException {
String newSize = null;
+ if (size == 0) {
+ throw new QemuImgException("size should never be exactly zero");
+ }
+
if (delta) {
if (size > 0) {
newSize = "+" + Long.toString(size);
} else {
- newSize = "-" + Long.toString(size);
+ newSize = Long.toString(size);
+ System.out.println("NEW SIZE: " + newSize);
}
} else {
if (size <= 0) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/23a40a2b/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
----------------------------------------------------------------------
diff --git a/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java b/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
index 2d63564..86237ba 100644
--- a/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
+++ b/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
@@ -23,12 +23,14 @@ import org.apache.cloudstack.utils.qemu.QemuImgFile;
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
import java.util.Map;
import java.util.HashMap;
+import java.util.UUID;
import java.io.File;
public class QemuImgTest {
+
@Test
public void testCreateAndInfo() {
- String filename = "/tmp/test-image.qcow2";
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
/* 10TB virtual_size */
long size = 10995116277760l;
@@ -55,7 +57,7 @@ public class QemuImgTest {
@Test
public void testCreateAndInfoWithOptions() {
- String filename = "/tmp/test-options-image.qcow2";
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
/* 10TB virtual_size */
long size = 10995116277760l;
@@ -85,7 +87,7 @@ public class QemuImgTest {
@Test
public void testCreateAndResize() {
- String filename = "/tmp/test-resize-image.qcow2";
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
long startSize = 20480;
long endSize = 40960;
@@ -112,9 +114,65 @@ public class QemuImgTest {
}
+ @Test
+ public void testCreateAndResizeDeltaPositive() {
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
+
+ long startSize = 20480;
+ long increment = 20480;
+ QemuImgFile file = new QemuImgFile(filename, startSize, PhysicalDiskFormat.RAW);
+
+ try {
+ QemuImg qemu = new QemuImg();
+ qemu.create(file);
+ qemu.resize(file, increment, true);
+ Map<String, String> info = qemu.info(file);
+
+ if (info == null) {
+ fail("We didn't get any information back from qemu-img");
+ }
+
+ Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
+ assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
+ } catch (QemuImgException e) {
+ fail(e.getMessage());
+ }
+
+ File f = new File(filename);
+ f.delete();
+ }
+
+ @Test
+ public void testCreateAndResizeDeltaNegative() {
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
+
+ long startSize = 81920;
+ long increment = -40960;
+ QemuImgFile file = new QemuImgFile(filename, startSize, PhysicalDiskFormat.RAW);
+
+ try {
+ QemuImg qemu = new QemuImg();
+ qemu.create(file);
+ qemu.resize(file, increment, true);
+ Map<String, String> info = qemu.info(file);
+
+ if (info == null) {
+ fail("We didn't get any information back from qemu-img");
+ }
+
+ Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
+ assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
+ } catch (QemuImgException e) {
+ fail(e.getMessage());
+ }
+
+ File f = new File(filename);
+ f.delete();
+ }
+
@Test(expected = QemuImgException.class)
public void testCreateAndResizeFail() throws QemuImgException {
- String filename = "/tmp/test-resize-image.qcow2";
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
long startSize = 20480;
@@ -139,11 +197,27 @@ public class QemuImgTest {
}
+ @Test(expected = QemuImgException.class)
+ public void testCreateAndResizeZero() throws QemuImgException {
+ String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
+
+ long startSize = 20480;
+ QemuImgFile file = new QemuImgFile(filename, 20480, PhysicalDiskFormat.QCOW2);
+
+ QemuImg qemu = new QemuImg();
+ qemu.create(file);
+ qemu.resize(file, 0);
+
+ File f = new File(filename);
+ f.delete();
+
+ }
+
@Test
public void testConvertBasic() {
long srcSize = 20480;
- String srcFileName = "/tmp/test-src-image.qcow2";
- String destFileName = "/tmp/test-dest-image.qcow2";
+ String srcFileName = "/tmp/" + UUID.randomUUID() + ".qcow2";
+ String destFileName = "/tmp/" + UUID.randomUUID() + ".qcow2";
QemuImgFile srcFile = new QemuImgFile(srcFileName, srcSize);
QemuImgFile destFile = new QemuImgFile(destFileName);
@@ -167,8 +241,8 @@ public class QemuImgTest {
@Test
public void testConvertAdvanced() {
long srcSize = 4019200;
- String srcFileName = "/tmp/test-src-image.qcow2";
- String destFileName = "/tmp/test-dest-image.qcow2";
+ String srcFileName = "/tmp/" + UUID.randomUUID() + ".qcow2";
+ String destFileName = "/tmp/" + UUID.randomUUID() + ".qcow2";
PhysicalDiskFormat srcFormat = PhysicalDiskFormat.RAW;
PhysicalDiskFormat destFormat = PhysicalDiskFormat.QCOW2;