issue 384: modified CloneAndRegister constructor

This commit is contained in:
Andrea Turli 2012-01-05 13:46:38 +00:00
parent 85fae1687b
commit 7e68bba81c
3 changed files with 13 additions and 33 deletions

View File

@ -55,20 +55,14 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
private VirtualBoxManager manager;
private VmSpec vmSpec;
private CloneOptions cloneOptions;
@Inject
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
VirtualBoxManager manager, VmSpec vmSpec) {
this(manager, vmSpec, null);
}
boolean isLinkedClone;
@Inject
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
VirtualBoxManager manager, VmSpec vmSpec, CloneOptions cloneOptions) {
VirtualBoxManager manager, VmSpec vmSpec, boolean isLinkedClone) {
this.manager = manager;
this.vmSpec = vmSpec;
this.cloneOptions = cloneOptions;
this.isLinkedClone = isLinkedClone;
}
@Override
@ -93,8 +87,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
String settingsFile = manager.getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir);
IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite());
List<CloneOptions> options = new ArrayList<CloneOptions>();
if(cloneOptions != null)
options.add(cloneOptions);
if(isLinkedClone)
options.add(CloneOptions.Link);
// TODO snapshot name
ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc").apply(master);

View File

@ -22,13 +22,8 @@ package org.jclouds.virtualbox.functions;
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
import static org.testng.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.StorageController;
@ -42,8 +37,6 @@ import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Predicate;
/**
* @author Andrea Turli
*/
@ -51,14 +44,11 @@ import com.google.common.base.Predicate;
public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
BaseVirtualBoxClientLiveTest {
private String settingsFile = null;
private boolean forceOverwrite = true;
private static final boolean IS_LINKED_CLONE = true;
private String vmId = "jclouds-image-iso-1";
private String osTypeId = "";
private String osTypeId = "DEBIAN";
private String guestId = "guest";
private String hostId = "host";
private String snapshotName = "snap";
private String snapshotDesc = "snapDesc";
private String vmName = "jclouds-image-virtualbox-iso-to-machine-test";
private String cloneName = vmName + "_clone";
@ -66,8 +56,6 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
private String ideControllerName = "IDE Controller";
private CleanupMode mode = CleanupMode.Full;
private StorageController ideController;
@Test
public void testCloneMachineFromAnotherMachine() throws Exception {
@ -90,7 +78,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
.cleanUpMode(mode)
.forceOverwrite(true).build();
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
manager, clonedVmSpec).apply(master);
manager, clonedVmSpec, IS_LINKED_CLONE).apply(master);
assertEquals(clone.getName(), clonedVmSpec.getVmName());
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(clonedVmSpec);
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(master));
@ -99,8 +87,6 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
private IMachine getMasterNode(VirtualBoxManager manager,
ComputeServiceContext localHostContext) {
try {
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(
new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
String workingDir = PropertyUtils.getWorkingDirFromProperty();
StorageController ideController = StorageController
.builder()

View File

@ -34,7 +34,6 @@ import org.jclouds.virtualbox.util.PropertyUtils;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.CloneOptions;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VirtualBoxManager;
@ -46,8 +45,9 @@ import org.virtualbox_4_1.VirtualBoxManager;
@Test(groups = "live", singleThreaded = true, testName = "IsLinkedClonesLiveTest")
public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
private String vmId = "jclouds-image-iso-1";
private String osTypeId = "";
private static final boolean IS_LINKED_CLONE = true;
private String vmId = "jclouds-image-iso-1";
private String osTypeId = "DEBIAN";
private String ideControllerName = "IDE Controller";
private String cloneId = "jclouds-is-linked-clone-clone";
private String cloneName = "jclouds-is-linked-clone-clone";
@ -90,7 +90,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
manager).apply(masterSpec);
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
manager, cloneSpec, CloneOptions.Link).apply(master);
manager, cloneSpec, IS_LINKED_CLONE).apply(master);
assertTrue(new IsLinkedClone(manager).apply(clone));
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
@ -107,7 +107,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
manager).apply(masterSpec);
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
manager, cloneSpec).apply(master);
manager, cloneSpec, !IS_LINKED_CLONE).apply(master);
assertFalse(new IsLinkedClone(manager).apply(clone));
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)