Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Answer execute(final CopyVolumeCommand command, final LibvirtComputingRes
}

final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final String volumeName = libvirtUtilitiesHelper.generatereUUIDName();
final String volumeName = libvirtUtilitiesHelper.generateUUIDName();

if (copyToSecondary) {
final String destVolumeName = volumeName + ".qcow2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, fi

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Processor buildQCOW2Processor(final StorageLayer storage) throws Configur
return qcow2Processor;
}

public String generatereUUIDName() {
public String generateUUIDName() {
return UUID.randomUUID().toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3743,7 +3743,7 @@ public void testCreatePrivateTemplateFromSnapshotCommand() {

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);
Expand Down Expand Up @@ -3817,7 +3817,7 @@ public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException()

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);
Expand Down Expand Up @@ -3890,7 +3890,7 @@ public void testCreatePrivateTemplateFromSnapshotCommandInternalErrorException()

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);
Expand Down Expand Up @@ -3964,7 +3964,7 @@ public void testCreatePrivateTemplateFromSnapshotCommandIOException() {

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);
Expand Down Expand Up @@ -4022,7 +4022,7 @@ public void testCreatePrivateTemplateFromSnapshotCommandCloudRuntime() {
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);
Expand Down Expand Up @@ -4067,7 +4067,7 @@ public void testCopyVolumeCommand() {
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);
Expand Down Expand Up @@ -4113,7 +4113,7 @@ public void testCopyVolumeCommandToSecFalse() {
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);
Expand Down Expand Up @@ -4156,7 +4156,7 @@ public void testCopyVolumeCommandCloudRuntime() {
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);
Expand Down Expand Up @@ -4230,7 +4230,7 @@ public void testCopyVolumeCommandPrimaryNotFound() {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
4 changes: 4 additions & 0 deletions utils/src/main/java/com/cloud/utils/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ protected String buildCommandLine(List<String> command) {
return builder.toString();
}

public long getTimeout() {
return _timeout;
}

public String execute() {
return execute(new OutputInterpreter.OutputLogger(_logger));
}
Expand Down