kvm upgrade issue from 2.2.14: 1. the uuid passed by mgt server is malformat, libvirt can't start vm. 2. the template path on primary storage is incorrect, which contains absolute path

This commit is contained in:
Edison Su 2013-08-30 18:06:08 -07:00
parent 3ddc6da10b
commit 0eb3944fc8
3 changed files with 38 additions and 1 deletions

View File

@ -3357,10 +3357,28 @@ ServerResource {
}
}
protected String getUuid(String uuid) {
if (uuid == null) {
uuid = UUID.randomUUID().toString();
} else {
try {
UUID uuid2 = UUID.fromString(uuid);
String uuid3 = uuid2.toString();
if (!uuid3.equals(uuid)) {
uuid = UUID.randomUUID().toString();
}
} catch (IllegalArgumentException e) {
uuid = UUID.randomUUID().toString();
}
}
return uuid;
}
protected LibvirtVMDef createVMFromSpec(VirtualMachineTO vmTO) {
LibvirtVMDef vm = new LibvirtVMDef();
vm.setDomainName(vmTO.getName());
vm.setDomUUID(vmTO.getUuid());
String uuid = vmTO.getUuid();
uuid = getUuid(uuid);
vm.setDomUUID(uuid);
vm.setDomDescription(vmTO.getOs());
GuestDef guest = new GuestDef();

View File

@ -289,6 +289,10 @@ public class KVMStorageProcessor implements StorageProcessor {
if (primaryPool.getType() == StoragePoolType.CLVM) {
vol = templateToPrimaryDownload(templatePath, primaryPool);
} else {
if (templatePath.contains("/mnt")) {
//upgrade issue, if the path contains path, need to extract the volume uuid from path
templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
}
BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
vol = storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), BaseVol.getPool());
}

View File

@ -24,11 +24,13 @@ import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine;
import junit.framework.Assert;
import org.apache.commons.lang.SystemUtils;
import org.junit.Assume;
import org.junit.Test;
import java.util.Random;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -195,4 +197,17 @@ public class LibvirtComputingResourceTest {
Pair<Double, Double> stats = LibvirtComputingResource.getNicStats("lo");
assertNotNull(stats);
}
@Test
public void testUUID() {
String uuid = "1";
LibvirtComputingResource lcr = new LibvirtComputingResource();
uuid =lcr.getUuid(uuid);
Assert.assertTrue(!uuid.equals("1"));
String oldUuid = UUID.randomUUID().toString();
uuid = oldUuid;
uuid = lcr.getUuid(uuid);
Assert.assertTrue(uuid.equals(oldUuid));
}
}