You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2015/11/02 13:32:35 UTC

[1/2] git commit: updated refs/heads/master to 30a8528

Repository: cloudstack
Updated Branches:
  refs/heads/master a981d34f4 -> 30a852897


kvm: Add UnitTests for LibvirtUtilitiesHelper

These were lacking, but this helper is used in various places
inside the KVM code.

Some simple tests to verify the helper is doing what we expect it
to do.


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

Branch: refs/heads/master
Commit: 602231132d7fcfddf037b3c166b720b8acf5fadb
Parents: eabf11c
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Thu Oct 29 12:52:42 2015 +0100
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Fri Oct 30 12:34:00 2015 +0100

----------------------------------------------------------------------
 .../LibvirtCopyVolumeCommandWrapper.java        |  2 +-
 ...ivateTemplateFromSnapshotCommandWrapper.java |  2 +-
 .../wrapper/LibvirtUtilitiesHelper.java         |  2 +-
 .../resource/LibvirtComputingResourceTest.java  | 18 +++----
 .../wrapper/LibvirtUtilitiesHelperTest.java     | 56 ++++++++++++++++++++
 .../java/com/cloud/utils/script/Script.java     |  4 ++
 6 files changed, 72 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/60223113/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java
index e6df525..b2248b9 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java
@@ -66,7 +66,7 @@ public final class LibvirtCopyVolumeCommandWrapper extends CommandWrapper<CopyVo
             }
 
             final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
-            final String volumeName = libvirtUtilitiesHelper.generatereUUIDName();
+            final String volumeName = libvirtUtilitiesHelper.generateUUIDName();
 
             if (copyToSecondary) {
                 final String destVolumeName = volumeName + ".qcow2";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/60223113/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java
index 440a252..735206f 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java
@@ -54,7 +54,7 @@ public final class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper extend
 
         final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
         final String templateInstallFolder = "template/tmpl/" + templateFolder;
-        final String tmplName = libvirtUtilitiesHelper.generatereUUIDName();
+        final String tmplName = libvirtUtilitiesHelper.generateUUIDName();
         final String tmplFileName = tmplName + ".qcow2";
 
         KVMStoragePool secondaryPool = null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/60223113/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java
index 1a1a6d3..7a93e1f 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java
@@ -64,7 +64,7 @@ public class LibvirtUtilitiesHelper {
         return qcow2Processor;
     }
 
-    public String generatereUUIDName() {
+    public String generateUUIDName() {
         return UUID.randomUUID().toString();
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/60223113/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index 98a074a..b15e148 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -3743,7 +3743,7 @@ public class LibvirtComputingResourceTest {
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
         when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(tmplName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
 
         try {
             when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
@@ -3817,7 +3817,7 @@ public class LibvirtComputingResourceTest {
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
         when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(tmplName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
 
         try {
             when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenThrow(ConfigurationException.class);
@@ -3890,7 +3890,7 @@ public class LibvirtComputingResourceTest {
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
         when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(tmplName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
 
         try {
             when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
@@ -3964,7 +3964,7 @@ public class LibvirtComputingResourceTest {
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
         when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(tmplName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
 
         try {
             when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenReturn(qcow2Processor);
@@ -4022,7 +4022,7 @@ public class LibvirtComputingResourceTest {
         snapshotPath = snapshotPath.substring(0, index);
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(tmplName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
 
         when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
         when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
@@ -4067,7 +4067,7 @@ public class LibvirtComputingResourceTest {
         when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(destVolumeName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
         when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
         when(storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolURL)).thenReturn(secondary);
         when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
@@ -4113,7 +4113,7 @@ public class LibvirtComputingResourceTest {
         when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
         when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(destVolumeName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
         when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
         when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
         when(storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
@@ -4156,7 +4156,7 @@ public class LibvirtComputingResourceTest {
         when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
         when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(destVolumeName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
         when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
         when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
         when(storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
@@ -4230,7 +4230,7 @@ public class LibvirtComputingResourceTest {
                 pool.getUserInfo(), pool.getType())).thenReturn(primary);
 
         when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
-        when(libvirtUtilitiesHelper.generatereUUIDName()).thenReturn(destVolumeName);
+        when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
         when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
         when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
         when(storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/60223113/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelperTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelperTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelperTest.java
new file mode 100644
index 0000000..bb7a3f5
--- /dev/null
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelperTest.java
@@ -0,0 +1,56 @@
+// 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.resource.wrapper;
+
+import java.util.UUID;
+
+import com.cloud.utils.script.Script;
+
+import junit.framework.TestCase;
+
+public class LibvirtUtilitiesHelperTest extends TestCase {
+
+    public void testGenerateUUID() {
+        LibvirtUtilitiesHelper helper = new LibvirtUtilitiesHelper();
+        UUID uuid = UUID.fromString(helper.generateUUIDName());
+        assertEquals(4, uuid.version());
+    }
+
+    public void testSSHKeyPaths() {
+        LibvirtUtilitiesHelper helper = new LibvirtUtilitiesHelper();
+        /* These paths are hardcoded in LibvirtComputingResource and we should
+         * verify that they do not change.
+         * Hardcoded paths are not what we want in the longer run
+         */
+        assertEquals("/root/.ssh", helper.retrieveSshKeysPath());
+        assertEquals("/root/.ssh/id_rsa.pub.cloud", helper.retrieveSshPubKeyPath());
+        assertEquals("/root/.ssh/id_rsa.cloud", helper.retrieveSshPrvKeyPath());
+    }
+
+    public void testBashScriptPath() {
+        LibvirtUtilitiesHelper helper = new LibvirtUtilitiesHelper();
+        assertEquals("/bin/bash", helper.retrieveBashScriptPath());
+    }
+
+    public void testBuildScript() {
+        LibvirtUtilitiesHelper helper = new LibvirtUtilitiesHelper();
+        String path = "/path/to/my/script";
+        Script script = helper.buildScript(path);
+        assertEquals(path + " ", script.toString());
+        assertEquals(LibvirtUtilitiesHelper.TIMEOUT, script.getTimeout());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/60223113/utils/src/main/java/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/script/Script.java b/utils/src/main/java/com/cloud/utils/script/Script.java
index 487c62c..b8cb4fe 100644
--- a/utils/src/main/java/com/cloud/utils/script/Script.java
+++ b/utils/src/main/java/com/cloud/utils/script/Script.java
@@ -158,6 +158,10 @@ public class Script implements Callable<String> {
         return builder.toString();
     }
 
+    public long getTimeout() {
+        return _timeout;
+    }
+
     public String execute() {
         return execute(new OutputInterpreter.OutputLogger(_logger));
     }


[2/2] git commit: updated refs/heads/master to 30a8528

Posted by re...@apache.org.
Merge pull request #1005 from wido/libvirt-unittests

kvm: Add UnitTests for LibvirtUtilitiesHelperThese were lacking, but this helper is used in various places
inside the KVM code.

Some simple tests to verify the helper is doing what we expect it
to do.

* pr/1005:
  kvm: Add UnitTests for LibvirtUtilitiesHelper

Signed-off-by: Remi Bergsma <gi...@remi.nl>


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

Branch: refs/heads/master
Commit: 30a852897362a1e897bcd5dedd9855de5dd99e89
Parents: a981d34 6022311
Author: Remi Bergsma <gi...@remi.nl>
Authored: Mon Nov 2 13:31:51 2015 +0100
Committer: Remi Bergsma <gi...@remi.nl>
Committed: Mon Nov 2 13:31:51 2015 +0100

----------------------------------------------------------------------
 .../LibvirtCopyVolumeCommandWrapper.java        |  2 +-
 ...ivateTemplateFromSnapshotCommandWrapper.java |  2 +-
 .../wrapper/LibvirtUtilitiesHelper.java         |  2 +-
 .../resource/LibvirtComputingResourceTest.java  | 18 +++----
 .../wrapper/LibvirtUtilitiesHelperTest.java     | 56 ++++++++++++++++++++
 .../java/com/cloud/utils/script/Script.java     |  4 ++
 6 files changed, 72 insertions(+), 12 deletions(-)
----------------------------------------------------------------------