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