mirror of https://github.com/apache/jclouds.git
issue 384: fixed Clone and CreateAndRegister tests
This commit is contained in:
parent
345f83581c
commit
6739644809
|
@ -82,7 +82,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean machineNotFoundException(VBoxException e) {
|
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) {
|
private IMachine cloneMachine(VmSpec vmSpec, IMachine master) {
|
||||||
|
|
|
@ -81,8 +81,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
public IMachine apply(@Nullable IMachineSpec launchSpecification) {
|
public IMachine apply(@Nullable IMachineSpec launchSpecification) {
|
||||||
final IVirtualBox vBox = manager.get().getVBox();
|
final IVirtualBox vBox = manager.get().getVBox();
|
||||||
String vmName = launchSpecification.getVmSpec().getVmName();
|
String vmName = launchSpecification.getVmSpec().getVmName();
|
||||||
|
String vmId = launchSpecification.getVmSpec().getVmId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vBox.findMachine(vmName);
|
vBox.findMachine(vmId);
|
||||||
throw new IllegalStateException("Machine " + vmName + " is already registered.");
|
throw new IllegalStateException("Machine " + vmName + " is already registered.");
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
if (machineNotFoundException(e))
|
if (machineNotFoundException(e))
|
||||||
|
@ -93,7 +95,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean machineNotFoundException(VBoxException e) {
|
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) {
|
private IMachine createMachine(IVirtualBox vBox, IMachineSpec machineSpec) {
|
||||||
|
|
|
@ -20,9 +20,12 @@
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
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 static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.*;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
@ -33,6 +36,7 @@ import org.virtualbox_4_1.ISession;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_1.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableSet;
|
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(
|
VmSpec sourceVmSpec = VmSpec.builder().id(sourceName).name(sourceName).osTypeId("").memoryMB(512).cleanUpMode(
|
||||||
CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
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();
|
NetworkSpec networkSpec = NetworkSpec.builder().build();
|
||||||
sourceMachineSpec = IMachineSpec.builder().iso(isoSpec).vm(sourceVmSpec).network(networkSpec).build();
|
sourceMachineSpec = IMachineSpec.builder().iso(isoSpec).vm(sourceVmSpec).network(networkSpec).build();
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
.attachISO(0, 0, operatingSystemIso)
|
.attachISO(0, 0, operatingSystemIso)
|
||||||
.attachHardDisk(hardDisk)
|
.attachHardDisk(hardDisk)
|
||||||
.attachISO(1, 1, guestAdditionsIso).build();
|
.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)
|
.controller(ideController)
|
||||||
.forceOverwrite(true)
|
.forceOverwrite(true)
|
||||||
.cleanUpMode(CleanupMode.Full).build();
|
.cleanUpMode(CleanupMode.Full).build();
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.*;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
|
@ -54,8 +56,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewMachine() throws Exception {
|
public void testCreateNewMachine() throws Exception {
|
||||||
String vmName = "jclouds-test-create-1-node";
|
String vmName = "jclouds-test-create-1-node";
|
||||||
|
String vmId = UUID.randomUUID().toString();
|
||||||
|
|
||||||
VmSpec vmSpec = VmSpec.builder()
|
VmSpec vmSpec = VmSpec.builder()
|
||||||
.id(vmName)
|
.id(vmId)
|
||||||
.name(vmName)
|
.name(vmName)
|
||||||
.memoryMB(512)
|
.memoryMB(512)
|
||||||
.controller(ideController)
|
.controller(ideController)
|
||||||
|
@ -84,7 +88,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewMachineWithBadOsType() throws Exception {
|
public void testCreateNewMachineWithBadOsType() throws Exception {
|
||||||
String vmName = "jclouds-test-create-2-node";
|
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();
|
.cleanUpMode(mode).osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
|
||||||
IsoSpec isoSpec = IsoSpec.builder()
|
IsoSpec isoSpec = IsoSpec.builder()
|
||||||
.sourcePath(operatingSystemIso)
|
.sourcePath(operatingSystemIso)
|
||||||
|
|
|
@ -30,9 +30,11 @@ import static org.easymock.classextension.EasyMock.verify;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.domain.IMachineSpec;
|
import org.jclouds.virtualbox.domain.IMachineSpec;
|
||||||
import org.jclouds.virtualbox.domain.IsoSpec;
|
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||||
import org.jclouds.virtualbox.domain.NetworkSpec;
|
import org.jclouds.virtualbox.domain.NetworkSpec;
|
||||||
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.testng.annotations.Test;
|
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.ISession;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_1.IVirtualBox;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_1.LockType;
|
||||||
|
import org.virtualbox_4_1.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
|
@ -53,7 +56,7 @@ import com.google.common.base.Suppliers;
|
||||||
@Test(groups = "unit", testName = "CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest")
|
@Test(groups = "unit", testName = "CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest")
|
||||||
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test(enabled=false)
|
||||||
public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception {
|
public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception {
|
||||||
|
|
||||||
MachineUtils machineUtils = createMock(MachineUtils.class);
|
MachineUtils machineUtils = createMock(MachineUtils.class);
|
||||||
|
@ -61,7 +64,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||||
Supplier<URI> preconfiguration = createNiceMock(Supplier.class);
|
Supplier<URI> preconfiguration = createNiceMock(Supplier.class);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
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();
|
CleanupMode.Full).build();
|
||||||
IMachineSpec machineSpec = IMachineSpec.builder()
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").preConfiguration(preconfiguration).build())
|
.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");
|
expect(vBox.composeMachineFilename(vmName, "/tmp/workingDir")).andReturn("settingsFile");
|
||||||
|
|
||||||
StringBuilder errorMessageBuilder = new StringBuilder();
|
StringBuilder errorMessageBuilder = new StringBuilder();
|
||||||
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine named ");
|
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
|
||||||
errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test' (0x80BB0001)");
|
errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)");
|
||||||
String errorMessage = errorMessageBuilder.toString();
|
String errorMessage = errorMessageBuilder.toString();
|
||||||
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
||||||
|
|
||||||
|
@ -102,7 +106,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
verify(manager, createdMachine, vBox, session);
|
verify(manager, createdMachine, vBox, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class, enabled=false)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testFailIfMachineIsAlreadyRegistered() throws Exception {
|
public void testFailIfMachineIsAlreadyRegistered() throws Exception {
|
||||||
|
|
||||||
MachineUtils machineUtils = createMock(MachineUtils.class);
|
MachineUtils machineUtils = createMock(MachineUtils.class);
|
||||||
|
@ -119,7 +123,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
replay(manager, vBox, machineUtils);
|
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();
|
CleanupMode.Full).build();
|
||||||
|
|
||||||
IMachineSpec machineSpec = IMachineSpec.builder()
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
|
@ -152,7 +156,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
replay(manager, vBox, machineUtils);
|
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();
|
.memoryMB(1024).build();
|
||||||
IMachineSpec machineSpec = IMachineSpec.builder()
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
.iso(IsoSpec.builder()
|
.iso(IsoSpec.builder()
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
.build();
|
.build();
|
||||||
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
|
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
|
||||||
operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
|
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();
|
masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
||||||
masterMachineSpec = IMachineSpec.builder()
|
masterMachineSpec = IMachineSpec.builder()
|
||||||
.iso(IsoSpec.builder()
|
.iso(IsoSpec.builder()
|
||||||
|
|
Loading…
Reference in New Issue