issue 384: fixed Clone and CreateAndRegister tests

This commit is contained in:
andreaturli 2012-01-22 13:09:24 +00:00
parent 345f83581c
commit 6739644809
7 changed files with 46 additions and 15 deletions

View File

@ -82,7 +82,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
}
private boolean machineNotFoundException(VBoxException e) {
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ");
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ") ||
e.getMessage().contains("Could not find a registered machine with UUID {");
}
private IMachine cloneMachine(VmSpec vmSpec, IMachine master) {

View File

@ -81,8 +81,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
public IMachine apply(@Nullable IMachineSpec launchSpecification) {
final IVirtualBox vBox = manager.get().getVBox();
String vmName = launchSpecification.getVmSpec().getVmName();
String vmId = launchSpecification.getVmSpec().getVmId();
try {
vBox.findMachine(vmName);
vBox.findMachine(vmId);
throw new IllegalStateException("Machine " + vmName + " is already registered.");
} catch (VBoxException e) {
if (machineNotFoundException(e))
@ -93,7 +95,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
}
private boolean machineNotFoundException(VBoxException e) {
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ");
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ") ||
e.getMessage().contains("Could not find a registered machine with UUID {");
}
private IMachine createMachine(IVirtualBox vBox, IMachineSpec machineSpec) {

View File

@ -20,9 +20,12 @@
package org.jclouds.virtualbox.functions;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
import static org.testng.Assert.assertEquals;
import com.google.inject.Injector;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.*;
import org.testng.annotations.BeforeClass;
@ -33,6 +36,7 @@ import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.StorageBus;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
/**
@ -66,7 +70,18 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
VmSpec sourceVmSpec = VmSpec.builder().id(sourceName).name(sourceName).osTypeId("").memoryMB(512).cleanUpMode(
CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
IsoSpec isoSpec = IsoSpec.builder().build();
Injector injector = context.utils().injector();
Function<String, String> configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
IsoSpec isoSpec = IsoSpec.builder()
.sourcePath(operatingSystemIso)
.installationScript(configProperties
.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE)
.replace("HOSTNAME", sourceVmSpec.getVmName()))
.preConfiguration(preconfigurationUri)
.build();
//IsoSpec isoSpec = IsoSpec.builder().build();
NetworkSpec networkSpec = NetworkSpec.builder().build();
sourceMachineSpec = IMachineSpec.builder().iso(isoSpec).vm(sourceVmSpec).network(networkSpec).build();

View File

@ -75,7 +75,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
.attachISO(0, 0, operatingSystemIso)
.attachHardDisk(hardDisk)
.attachISO(1, 1, guestAdditionsIso).build();
vmSpecification = VmSpec.builder().id("jclouds-image-iso-1").name(vmName).memoryMB(512).osTypeId("")
vmSpecification = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).osTypeId("")
.controller(ideController)
.forceOverwrite(true)
.cleanUpMode(CleanupMode.Full).build();

View File

@ -21,6 +21,8 @@ package org.jclouds.virtualbox.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.util.UUID;
import com.google.inject.Injector;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.*;
@ -54,8 +56,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
@Test
public void testCreateNewMachine() throws Exception {
String vmName = "jclouds-test-create-1-node";
String vmId = UUID.randomUUID().toString();
VmSpec vmSpec = VmSpec.builder()
.id(vmName)
.id(vmId)
.name(vmName)
.memoryMB(512)
.controller(ideController)
@ -84,7 +88,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
@Test
public void testCreateNewMachineWithBadOsType() throws Exception {
String vmName = "jclouds-test-create-2-node";
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).controller(ideController)
String vmId = UUID.randomUUID().toString();
VmSpec vmSpec = VmSpec.builder()
.id(vmId)
.name(vmName).memoryMB(512).controller(ideController)
.cleanUpMode(mode).osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
IsoSpec isoSpec = IsoSpec.builder()
.sourcePath(operatingSystemIso)

View File

@ -30,9 +30,11 @@ import static org.easymock.classextension.EasyMock.verify;
import java.net.URI;
import org.easymock.EasyMock;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IMachineSpec;
import org.jclouds.virtualbox.domain.IsoSpec;
import org.jclouds.virtualbox.domain.NetworkSpec;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.util.MachineUtils;
import org.testng.annotations.Test;
@ -41,6 +43,7 @@ import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
@ -61,7 +64,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
IVirtualBox vBox = createMock(IVirtualBox.class);
Supplier<URI> preconfiguration = createNiceMock(Supplier.class);
String vmName = "jclouds-image-my-ubuntu-image";
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE).build();
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController).cleanUpMode(
CleanupMode.Full).build();
IMachineSpec machineSpec = IMachineSpec.builder()
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").preConfiguration(preconfiguration).build())
@ -74,8 +78,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
expect(vBox.composeMachineFilename(vmName, "/tmp/workingDir")).andReturn("settingsFile");
StringBuilder errorMessageBuilder = new StringBuilder();
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine named ");
errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test' (0x80BB0001)");
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)");
String errorMessage = errorMessageBuilder.toString();
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
@ -102,7 +106,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
verify(manager, createdMachine, vBox, session);
}
@Test(expectedExceptions = IllegalStateException.class, enabled=false)
@Test(expectedExceptions = IllegalStateException.class)
public void testFailIfMachineIsAlreadyRegistered() throws Exception {
MachineUtils machineUtils = createMock(MachineUtils.class);
@ -119,7 +123,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
replay(manager, vBox, machineUtils);
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
CleanupMode.Full).build();
IMachineSpec machineSpec = IMachineSpec.builder()
@ -152,7 +156,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
replay(manager, vBox, machineUtils);
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
.memoryMB(1024).build();
IMachineSpec machineSpec = IMachineSpec.builder()
.iso(IsoSpec.builder()

View File

@ -69,7 +69,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
.build();
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
VmSpec masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId).controller(
VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).osTypeId(osTypeId).controller(
masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
masterMachineSpec = IMachineSpec.builder()
.iso(IsoSpec.builder()