cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 0b4cc5d
Date Mon, 02 Nov 2015 16:54:05 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 0c52f70b4 -> 0b4cc5de8


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.


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

Branch: refs/heads/master
Commit: 7568f2123cb8b5d820acc2c23f453ccf8d1b6138
Parents: fb4e6ed
Author: Wido den Hollander <wido@widodh.nl>
Authored: Tue Oct 27 13:21:28 2015 +0100
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Tue Oct 27 13:21:28 2015 +0100

----------------------------------------------------------------------
 .../kvm/storage/LibvirtStoragePool.java         |  5 --
 .../kvm/storage/KVMPhysicalDiskTest.java        | 52 +++++++++++
 .../kvm/storage/LibvirtStoragePoolTest.java     | 91 ++++++++++++++++++++
 3 files changed, 143 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7568f212/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java
----------------------------------------------------------------------
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 49a8301..66018dd 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)
{

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7568f212/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/KVMPhysicalDiskTest.java
----------------------------------------------------------------------
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 0000000..bd644c8
--- /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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7568f212/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/storage/LibvirtStoragePoolTest.java
----------------------------------------------------------------------
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 0000000..90f6f87
--- /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


Mime
View raw message