cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [3/4] git commit: updated refs/heads/4.5 to bab9938
Date Fri, 18 Sep 2015 04:46:54 GMT
Added Unit Tests for QCOW2Utils.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/54595d11
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/54595d11
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/54595d11

Branch: refs/heads/4.5
Commit: 54595d11d4548591f94da19478595c6620e7e018
Parents: dc670d5
Author: Boris Schrijver <boris@pcextreme.nl>
Authored: Tue Sep 15 09:15:26 2015 +0200
Committer: Boris Schrijver <boris@pcextreme.nl>
Committed: Wed Sep 16 16:10:44 2015 +0200

----------------------------------------------------------------------
 .../storage/template/DownloadManagerImpl.java   |   4 +-
 .../com/cloud/utils/storage/QCOW2UtilsTest.java | 122 +++++++++++++++++++
 2 files changed, 124 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54595d11/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
index 35010b0..a1afe8d 100755
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
 import java.math.BigInteger;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
@@ -78,7 +79,6 @@ import com.cloud.storage.template.TemplateProp;
 import com.cloud.storage.template.VhdProcessor;
 import com.cloud.storage.template.VmdkProcessor;
 import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.StringUtils;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.OutputInterpreter;
@@ -419,7 +419,7 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
         if (extension.equals("iso")) {
             templateName = jobs.get(jobId).getTmpltName().trim().replace(" ", "_");
         } else {
-            templateName = java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName()
+ System.currentTimeMillis()).getBytes(StringUtils.getPreferredCharset())).toString();
+            templateName = java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName()
+ System.currentTimeMillis()).getBytes(Charset.forName("UTF-8"))).toString();
         }
 
         // run script to mv the temporary template file to the final template

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/54595d11/utils/test/com/cloud/utils/storage/QCOW2UtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/storage/QCOW2UtilsTest.java b/utils/test/com/cloud/utils/storage/QCOW2UtilsTest.java
new file mode 100644
index 0000000..a3ebe72
--- /dev/null
+++ b/utils/test/com/cloud/utils/storage/QCOW2UtilsTest.java
@@ -0,0 +1,122 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils.storage;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class QCOW2UtilsTest {
+
+    InputStream inputStream;
+
+    final Long virtualSize = 21474836480L;
+
+    /**
+     * The QCOW2 Header
+     *
+     * uint32_t magic;
+     * uint32_t version;
+     *
+     * uint64_t backing_file_offset;
+     * uint32_t backing_file_size;
+     *
+     * uint32_t cluster_bits;
+     * uint64_t size;
+     *
+     * uint32_t crypt_method;
+     *
+     * uint32_t l1_size;
+     * int64_t l1_table_offset;
+     *
+     * uint64_t refcount_table_offset;
+     * uint32_t refcount_table_clusters;
+     *
+     * uint32_t nb_snapshots;
+     * uint64_t snapshots_offset;
+     *
+     * @see https://people.gnome.org/~markmc/qcow-image-format.html
+     */
+
+    @Before
+    public void setup() {
+
+        ByteBuffer byteBuffer = ByteBuffer.allocate(72);
+
+        // Magic
+        byteBuffer.put("QFI".getBytes(Charset.forName("UTF-8")));
+        byteBuffer.put((byte)0xfb);
+
+        // Version
+        byteBuffer.putInt(2);
+
+        // Backing file offset
+        byteBuffer.putLong(0L);
+
+        // Backing file size
+        byteBuffer.putInt(0);
+
+        // Cluster bits
+        byteBuffer.putInt(0);
+
+        // Size
+        byteBuffer.putLong(virtualSize);
+
+        // Crypt method
+        byteBuffer.putInt(0);
+
+        // L1 Size
+        byteBuffer.putInt(0);
+
+        // L1 Table offset
+        byteBuffer.putLong(0L);
+
+        // Refcount table offset
+        byteBuffer.putLong(0L);
+
+        // Refcount table cluster
+        byteBuffer.putInt(0);
+
+        // NB Snapshots
+        byteBuffer.putInt(0);
+
+        // Snapshots offset
+        byteBuffer.putLong(0L);
+
+        inputStream = new ByteArrayInputStream(byteBuffer.array());
+    }
+
+    @Test
+    public void getVirtualSizeHeaderLocation() {
+        assertEquals(24, QCOW2Utils.getVirtualSizeHeaderLocation());
+    }
+
+    @Test
+    public void getVirtualSizeTest() throws IOException {
+        assertEquals(virtualSize.longValue(), QCOW2Utils.getVirtualSize(inputStream));
+    }
+}


Mime
View raw message