mirror of https://github.com/apache/jclouds.git
corrected formatting and small bug in CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest
This commit is contained in:
parent
fa26fe34f9
commit
d2e1e36256
|
@ -23,6 +23,8 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.CloneSpec;
|
import org.jclouds.virtualbox.domain.CloneSpec;
|
||||||
|
@ -52,18 +54,13 @@ import com.google.inject.Injector;
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest")
|
||||||
public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest extends
|
public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
BaseVirtualBoxClientLiveTest {
|
|
||||||
|
|
||||||
private static final boolean IS_LINKED_CLONE = true;
|
private static final boolean IS_LINKED_CLONE = true;
|
||||||
|
|
||||||
private CloneSpec cloneSpec;
|
|
||||||
private MasterSpec sourceMachineSpec;
|
private MasterSpec sourceMachineSpec;
|
||||||
|
|
||||||
private CleanupMode mode = CleanupMode.Full;
|
private CleanupMode mode = CleanupMode.Full;
|
||||||
|
|
||||||
private VmSpec clonedVmSpec;
|
private VmSpec clonedVmSpec;
|
||||||
|
|
||||||
private NetworkSpec cloneNetworkSpec;
|
private NetworkSpec cloneNetworkSpec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,12 +68,9 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
String sourceName = VIRTUALBOX_IMAGE_PREFIX
|
String sourceName = VIRTUALBOX_IMAGE_PREFIX
|
||||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass()
|
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
||||||
.getSimpleName());
|
String cloneName = VIRTUALBOX_IMAGE_PREFIX + "Clone#"
|
||||||
String cloneName = VIRTUALBOX_IMAGE_PREFIX
|
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
||||||
+ "Clone#"
|
|
||||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass()
|
|
||||||
.getSimpleName());
|
|
||||||
|
|
||||||
StorageController ideController = StorageController
|
StorageController ideController = StorageController
|
||||||
.builder()
|
.builder()
|
||||||
|
@ -84,61 +78,54 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten
|
||||||
.bus(StorageBus.IDE)
|
.bus(StorageBus.IDE)
|
||||||
.attachISO(0, 0, operatingSystemIso)
|
.attachISO(0, 0, operatingSystemIso)
|
||||||
.attachHardDisk(
|
.attachHardDisk(
|
||||||
HardDisk.builder().diskpath(adminDisk)
|
HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).autoDelete(true).build())
|
||||||
.controllerPort(0).deviceSlot(1)
|
|
||||||
.autoDelete(true).build())
|
|
||||||
.attachISO(1, 1, guestAdditionsIso).build();
|
.attachISO(1, 1, guestAdditionsIso).build();
|
||||||
|
|
||||||
VmSpec sourceVmSpec = VmSpec.builder().id(sourceName).name(sourceName)
|
VmSpec sourceVmSpec = VmSpec.builder().id(sourceName).name(sourceName).osTypeId("").memoryMB(512)
|
||||||
.osTypeId("").memoryMB(512).cleanUpMode(CleanupMode.Full)
|
.cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
||||||
.controller(ideController).forceOverwrite(true).build();
|
|
||||||
|
|
||||||
Injector injector = context.utils().injector();
|
Injector injector = context.utils().injector();
|
||||||
Function<String, String> configProperties = injector
|
Function<String, String> configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
|
||||||
.getInstance(ValueOfConfigurationKeyOrNull.class);
|
|
||||||
IsoSpec isoSpec = IsoSpec
|
IsoSpec isoSpec = IsoSpec
|
||||||
.builder()
|
.builder()
|
||||||
.sourcePath(operatingSystemIso)
|
.sourcePath(operatingSystemIso)
|
||||||
.installationScript(
|
.installationScript(
|
||||||
configProperties.apply(
|
configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME",
|
||||||
VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace(
|
sourceVmSpec.getVmName())).build();
|
||||||
"HOSTNAME", sourceVmSpec.getVmName())).build();
|
|
||||||
|
|
||||||
NetworkAdapter networkAdapter = NetworkAdapter.builder()
|
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged)
|
||||||
.networkAttachmentType(NetworkAttachmentType.Bridged).build();
|
.build();
|
||||||
|
|
||||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
|
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||||
.builder().addNetworkAdapter(networkAdapter).build();
|
.build();
|
||||||
|
|
||||||
this.cloneNetworkSpec = NetworkSpec.builder()
|
this.cloneNetworkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build();
|
||||||
.addNIC(0L, networkInterfaceCard).build();
|
|
||||||
|
|
||||||
sourceMachineSpec = MasterSpec.builder().iso(isoSpec).vm(sourceVmSpec)
|
|
||||||
.network(cloneNetworkSpec).build();
|
|
||||||
|
|
||||||
this.clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName)
|
|
||||||
.memoryMB(512).cleanUpMode(mode).forceOverwrite(true).build();
|
|
||||||
|
|
||||||
|
sourceMachineSpec = MasterSpec.builder().iso(isoSpec).vm(sourceVmSpec).network(cloneNetworkSpec).build();
|
||||||
|
|
||||||
|
this.clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(mode)
|
||||||
|
.forceOverwrite(true).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneMachineFromAnotherMachine() throws Exception {
|
public void testCloneMachineFromAnotherMachine() throws Exception {
|
||||||
|
CloneSpec cloneSpec = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
IMachine source = getSourceNode();
|
IMachine source = getSourceNode();
|
||||||
CloneSpec cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(cloneNetworkSpec).master(source)
|
|
||||||
.linked(IS_LINKED_CLONE)
|
cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(cloneNetworkSpec).master(source)
|
||||||
.build();
|
.linked(IS_LINKED_CLONE).build();
|
||||||
|
|
||||||
if (source.getCurrentSnapshot() != null) {
|
if (source.getCurrentSnapshot() != null) {
|
||||||
ISession session = manager.get().openMachineSession(source);
|
ISession session = manager.get().openMachineSession(source);
|
||||||
session.getConsole().deleteSnapshot(
|
session.getConsole().deleteSnapshot(source.getCurrentSnapshot().getId());
|
||||||
source.getCurrentSnapshot().getId());
|
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
}
|
}
|
||||||
|
|
||||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
|
||||||
manager, workingDir,machineUtils).apply(cloneSpec);
|
.apply(cloneSpec);
|
||||||
assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName());
|
assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName());
|
||||||
|
|
||||||
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(clone);
|
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(clone);
|
||||||
|
@ -146,22 +133,22 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten
|
||||||
// TODO ssh into the node
|
// TODO ssh into the node
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(),
|
Set<VmSpec> specs = cloneSpec == null ? ImmutableSet.of(sourceMachineSpec.getVmSpec()) : ImmutableSet.of(
|
||||||
sourceMachineSpec.getVmSpec()))
|
cloneSpec.getVmSpec(), sourceMachineSpec.getVmSpec());
|
||||||
|
for (VmSpec spec : specs) {
|
||||||
undoVm(spec);
|
undoVm(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMachine getSourceNode() {
|
private IMachine getSourceNode() {
|
||||||
try {
|
try {
|
||||||
Injector injector = context.utils().injector();
|
Injector injector = context.utils().injector();
|
||||||
return injector.getInstance(
|
return injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(sourceMachineSpec);
|
||||||
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class)
|
|
||||||
.apply(sourceMachineSpec);
|
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// already created
|
// already created
|
||||||
return manager.get().getVBox()
|
return manager.get().getVBox().findMachine(sourceMachineSpec.getVmSpec().getVmId());
|
||||||
.findMachine(sourceMachineSpec.getVmSpec().getVmId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue