diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java index 49a83010a28..66018dd899d 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java @@ -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) { diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/KVMPhysicalDiskTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/KVMPhysicalDiskTest.java new file mode 100644 index 00000000000..bd644c85cd8 --- /dev/null +++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/KVMPhysicalDiskTest.java @@ -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); + } +} \ No newline at end of file diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/LibvirtStoragePoolTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/LibvirtStoragePoolTest.java new file mode 100644 index 00000000000..90f6f875f90 --- /dev/null +++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/LibvirtStoragePoolTest.java @@ -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()); + } +} \ No newline at end of file