mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
Add Unit Tests for Libvirt/KVM storage code
These classes were not covered by Unit Tests and this commit adds some tests for their basic functionality.
This commit is contained in:
parent
fb4e6ed6ba
commit
7568f2123c
@ -32,7 +32,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
public class LibvirtStoragePool implements KVMStoragePool {
|
||||
private static final Logger s_logger = Logger.getLogger(LibvirtStoragePool.class);
|
||||
protected String uuid;
|
||||
protected String uri;
|
||||
protected long capacity;
|
||||
protected long used;
|
||||
protected long available;
|
||||
@ -100,10 +99,6 @@ public class LibvirtStoragePool implements KVMStoragePool {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public String uri() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhysicalDiskFormat getDefaultFormat() {
|
||||
if (getStoragePoolType() == StoragePoolType.CLVM || getStoragePoolType() == StoragePoolType.RBD) {
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
// 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.hypervisor.kvm.storage;
|
||||
|
||||
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class KVMPhysicalDiskTest extends TestCase {
|
||||
|
||||
public void testRBDStringBuilder() {
|
||||
assertEquals(KVMPhysicalDisk.RBDStringBuilder("ceph-monitor", 8000, "admin", "supersecret", "volume1"),
|
||||
"rbd:volume1:mon_host=ceph-monitor\\\\:8000:auth_supported=cephx:id=admin:key=supersecret:rbd_default_format=2:client_mount_timeout=30");
|
||||
}
|
||||
|
||||
public void testAttributes() {
|
||||
String name = "3bc186e0-6c29-45bf-b2b0-ddef6f91f5ef";
|
||||
String path = "/" + name;
|
||||
|
||||
LibvirtStoragePool pool = Mockito.mock(LibvirtStoragePool.class);
|
||||
|
||||
KVMPhysicalDisk disk = new KVMPhysicalDisk(path, name, pool);
|
||||
assertEquals(disk.getName(), name);
|
||||
assertEquals(disk.getPath(), path);
|
||||
assertEquals(disk.getPool(), pool);
|
||||
assertEquals(disk.getSize(), 0);
|
||||
assertEquals(disk.getVirtualSize(), 0);
|
||||
|
||||
disk.setSize(1024);
|
||||
disk.setVirtualSize(2048);
|
||||
assertEquals(disk.getSize(), 1024);
|
||||
assertEquals(disk.getVirtualSize(), 2048);
|
||||
|
||||
disk.setFormat(PhysicalDiskFormat.RAW);
|
||||
assertEquals(disk.getFormat(), PhysicalDiskFormat.RAW);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
// 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.hypervisor.kvm.storage;
|
||||
|
||||
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
|
||||
import org.libvirt.StoragePool;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LibvirtStoragePoolTest extends TestCase {
|
||||
|
||||
public void testAttributes() {
|
||||
String uuid = "4c4fb08b-373e-4f30-a120-3aa3a43f31da";
|
||||
String name = "myfirstpool";
|
||||
|
||||
StoragePoolType type = StoragePoolType.NetworkFilesystem;
|
||||
|
||||
StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
|
||||
StoragePool storage = Mockito.mock(StoragePool.class);
|
||||
|
||||
LibvirtStoragePool pool = new LibvirtStoragePool(uuid, name, type, adapter, storage);
|
||||
assertEquals(pool.getCapacity(), 0);
|
||||
assertEquals(pool.getUsed(), 0);
|
||||
assertEquals(pool.getName(), name);
|
||||
assertEquals(pool.getUuid(), uuid);
|
||||
assertEquals(pool.getAvailable(), 0);
|
||||
assertEquals(pool.getStoragePoolType(), type);
|
||||
|
||||
pool.setCapacity(2048);
|
||||
pool.setUsed(1024);
|
||||
pool.setAvailable(1023);
|
||||
|
||||
assertEquals(pool.getCapacity(), 2048);
|
||||
assertEquals(pool.getUsed(), 1024);
|
||||
assertEquals(pool.getAvailable(), 1023);
|
||||
}
|
||||
|
||||
public void testDefaultFormats() {
|
||||
String uuid = "f40cbf53-1f37-4c62-8912-801edf398f47";
|
||||
String name = "myfirstpool";
|
||||
|
||||
StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
|
||||
StoragePool storage = Mockito.mock(StoragePool.class);
|
||||
|
||||
LibvirtStoragePool nfsPool = new LibvirtStoragePool(uuid, name, StoragePoolType.NetworkFilesystem, adapter, storage);
|
||||
assertEquals(nfsPool.getDefaultFormat(), PhysicalDiskFormat.QCOW2);
|
||||
assertEquals(nfsPool.getStoragePoolType(), StoragePoolType.NetworkFilesystem);
|
||||
|
||||
LibvirtStoragePool rbdPool = new LibvirtStoragePool(uuid, name, StoragePoolType.RBD, adapter, storage);
|
||||
assertEquals(rbdPool.getDefaultFormat(), PhysicalDiskFormat.RAW);
|
||||
assertEquals(rbdPool.getStoragePoolType(), StoragePoolType.RBD);
|
||||
|
||||
LibvirtStoragePool clvmPool = new LibvirtStoragePool(uuid, name, StoragePoolType.CLVM, adapter, storage);
|
||||
assertEquals(clvmPool.getDefaultFormat(), PhysicalDiskFormat.RAW);
|
||||
assertEquals(clvmPool.getStoragePoolType(), StoragePoolType.CLVM);
|
||||
}
|
||||
|
||||
public void testExternalSnapshot() {
|
||||
String uuid = "60b46738-c5d0-40a9-a79e-9a4fe6295db7";
|
||||
String name = "myfirstpool";
|
||||
|
||||
StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
|
||||
StoragePool storage = Mockito.mock(StoragePool.class);
|
||||
|
||||
LibvirtStoragePool nfsPool = new LibvirtStoragePool(uuid, name, StoragePoolType.NetworkFilesystem, adapter, storage);
|
||||
assertFalse(nfsPool.isExternalSnapshot());
|
||||
|
||||
LibvirtStoragePool rbdPool = new LibvirtStoragePool(uuid, name, StoragePoolType.RBD, adapter, storage);
|
||||
assertTrue(rbdPool.isExternalSnapshot());
|
||||
|
||||
LibvirtStoragePool clvmPool = new LibvirtStoragePool(uuid, name, StoragePoolType.CLVM, adapter, storage);
|
||||
assertTrue(clvmPool.isExternalSnapshot());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user