mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Merge pull request #795 from borisroman/CLOUDSTACK-8819
CLOUDSTACK-8819: Added QCOW2 virtual size checking for S3.- Cleaned up S3TemplateDownloader - Created static QCOW2 utils class. - Reformatted some parts of DownloadManagerImpl * pr/795: Added Unit Tests for QCOW2Utils. Fixed Findbugs issue introduced by 1c6378ec0056e8c75990a4a0c15e99b2df162a75 PR #795. Added QCOW2 virtual size checking for S3. Signed-off-by: Wido den Hollander <wido@widodh.nl>
This commit is contained in:
commit
d091b9189c
@ -78,6 +78,7 @@ 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;
|
||||
@ -423,7 +424,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()).toString();
|
||||
templateName = java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName() + System.currentTimeMillis()).getBytes(StringUtils.getPreferredCharset())).toString();
|
||||
}
|
||||
|
||||
// run script to mv the temporary template file to the final template
|
||||
|
||||
121
utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java
Normal file
121
utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java
Normal file
@ -0,0 +1,121 @@
|
||||
//
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user