From 1255d91eefd4df1b90753fcfe0a2687402052a32 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 6 Jan 2012 11:30:50 -0800 Subject: [PATCH] got rid of propertyutils --- ...MachineFromIMachineIfNotAlreadyExists.java | 33 +++++----- .../functions/CreateAndInstallVm.java | 65 ++++++++++++------- ...isterMachineFromIsoIfNotAlreadyExists.java | 50 ++++++++------ .../BaseVirtualBoxClientLiveTest.java | 16 ++--- ...hineFromIsoIfNotAlreadyExistsLiveTest.java | 4 +- .../functions/CreateAndInstallVmLiveTest.java | 6 +- ...hineFromIsoIfNotAlreadyExistsLiveTest.java | 4 +- .../predicates/IsLinkedClonesLiveTest.java | 53 ++++++--------- .../predicates/SshAvailableLiveTest.java | 32 +++++---- .../virtualbox/util/PropertyUtils.java | 31 --------- 10 files changed, 138 insertions(+), 156 deletions(-) delete mode 100644 sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/util/PropertyUtils.java diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java index e40d0a1329..e3c8b7b922 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java @@ -28,8 +28,8 @@ import javax.inject.Named; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; +import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.domain.VmSpec; -import org.jclouds.virtualbox.util.PropertyUtils; import org.virtualbox_4_1.CloneMode; import org.virtualbox_4_1.CloneOptions; import org.virtualbox_4_1.IMachine; @@ -42,9 +42,9 @@ import com.google.common.base.Function; import com.google.inject.Inject; /** - * CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the - * followings: - cloning the master - register the clone machine - - * + * CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the followings: - cloning + * the master - register the clone machine - + * * @author Andrea Turli */ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Function { @@ -53,14 +53,16 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - private VirtualBoxManager manager; - private VmSpec vmSpec; - boolean isLinkedClone; - + private final VirtualBoxManager manager; + private final String workingDir; + private final VmSpec vmSpec; + private final boolean isLinkedClone; + @Inject - public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( - VirtualBoxManager manager, VmSpec vmSpec, boolean isLinkedClone) { + public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(VirtualBoxManager manager, + @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) String workingDir, VmSpec vmSpec, boolean isLinkedClone) { this.manager = manager; + this.workingDir = workingDir; this.vmSpec = vmSpec; this.isLinkedClone = isLinkedClone; } @@ -83,15 +85,16 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu } private IMachine cloneMachine(VmSpec vmSpec, IMachine master) { - String workingDir = PropertyUtils.getWorkingDirFromProperty(); String settingsFile = manager.getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir); - IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite()); + IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), + vmSpec.getVmId(), vmSpec.isForceOverwrite()); List options = new ArrayList(); - if(isLinkedClone) + if (isLinkedClone) options.add(CloneOptions.Link); // TODO snapshot name - ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc").apply(master); + ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc") + .apply(master); // clone IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options); @@ -103,5 +106,5 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu manager.getVBox().registerMachine(clonedMachine); return clonedMachine; } - + } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java index 3ce8b334cc..292a7d6562 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java @@ -19,9 +19,23 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.inject.Inject; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; +import static org.jclouds.virtualbox.util.MachineUtils.applyForMachine; +import static org.jclouds.virtualbox.util.MachineUtils.lockMachineAndApply; +import static org.jclouds.virtualbox.util.MachineUtils.lockSessionOnMachineAndApply; +import static org.virtualbox_4_1.LockType.Shared; +import static org.virtualbox_4_1.LockType.Write; + +import java.io.File; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; +import javax.inject.Named; + import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.options.RunScriptOptions; @@ -29,23 +43,26 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshException; -import org.jclouds.virtualbox.domain.*; +import org.jclouds.virtualbox.config.VirtualBoxConstants; +import org.jclouds.virtualbox.domain.DeviceDetails; +import org.jclouds.virtualbox.domain.ExecutionType; +import org.jclouds.virtualbox.domain.HardDisk; +import org.jclouds.virtualbox.domain.IsoImage; +import org.jclouds.virtualbox.domain.NatAdapter; +import org.jclouds.virtualbox.domain.StorageController; +import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.settings.KeyboardScancodes; -import org.virtualbox_4_1.*; +import org.virtualbox_4_1.AccessMode; +import org.virtualbox_4_1.DeviceType; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_1.IProgress; +import org.virtualbox_4_1.ISession; +import org.virtualbox_4_1.VirtualBoxManager; -import javax.annotation.Resource; -import javax.inject.Named; -import java.io.File; -import java.util.Map; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; -import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; -import static org.jclouds.virtualbox.util.MachineUtils.*; -import static org.virtualbox_4_1.LockType.Shared; -import static org.virtualbox_4_1.LockType.Write; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Inject; public class CreateAndInstallVm implements Function { @@ -54,6 +71,7 @@ public class CreateAndInstallVm implements Function { protected Logger logger = Logger.NULL; private final VirtualBoxManager manager; + private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists; private String guestId; private final ComputeServiceContext context; private final String hostId; @@ -63,10 +81,13 @@ public class CreateAndInstallVm implements Function { private final ExecutionType executionType; @Inject - public CreateAndInstallVm(VirtualBoxManager manager, String guestId, ComputeServiceContext context, - String hostId, Predicate socketTester, - String webServerHost, int webServerPort, ExecutionType executionType) { + public CreateAndInstallVm(VirtualBoxManager manager, + CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists, + @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) String workingDir, String guestId, + ComputeServiceContext context, String hostId, Predicate socketTester, String webServerHost, + int webServerPort, ExecutionType executionType) { this.manager = manager; + this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists; this.guestId = guestId; this.context = context; this.hostId = hostId; @@ -81,7 +102,7 @@ public class CreateAndInstallVm implements Function { ensureWebServerIsRunning(); - final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpec); + final IMachine vm =createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(vmSpec); String vmName = vmSpec.getVmName(); diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java index 68a2e3e9a4..fb0f0d9341 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java @@ -33,13 +33,13 @@ import javax.inject.Named; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; +import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.domain.DeviceDetails; import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.IsoImage; import org.jclouds.virtualbox.domain.NatAdapter; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; -import org.jclouds.virtualbox.util.PropertyUtils; import org.virtualbox_4_1.AccessMode; import org.virtualbox_4_1.DeviceType; import org.virtualbox_4_1.IMachine; @@ -54,14 +54,18 @@ import com.google.common.base.Function; * @author Mattias Holmqvist */ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Function { - + @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - private VirtualBoxManager manager; - public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(VirtualBoxManager manager) { + private final VirtualBoxManager manager; + private final String workingDir; + + public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(VirtualBoxManager manager, + @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) String workingDir) { this.manager = manager; + this.workingDir = workingDir; } @Override @@ -84,15 +88,14 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi } private IMachine createMachine(IVirtualBox vBox, VmSpec vmSpec) { - String workingDir = PropertyUtils.getWorkingDirFromProperty(); - String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName() , workingDir); + String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir); - IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), - vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite()); + IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), + vmSpec.getVmId(), vmSpec.isForceOverwrite()); manager.getVBox().registerMachine(newMachine); - + String vmName = vmSpec.getVmName(); - + // Change RAM ensureMachineHasMemory(vmName, vmSpec.getMemory()); @@ -114,25 +117,30 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi } return newMachine; } - + private void setupDvdsForController(VmSpec vmSpecification, String vmName, StorageController controller) { Set dvds = controller.getIsoImages(); for (IsoImage dvd : dvds) { String dvdSource = dvd.getSourcePath(); - final IMedium dvdMedium = manager.getVBox().openMedium(dvdSource, DeviceType.DVD, - AccessMode.ReadOnly, vmSpecification.isForceOverwrite()); + final IMedium dvdMedium = manager.getVBox().openMedium(dvdSource, DeviceType.DVD, AccessMode.ReadOnly, + vmSpecification.isForceOverwrite()); ensureMachineDevicesAttached(vmName, dvdMedium, dvd.getDeviceDetails(), controller.getName()); } } - - private void ensureMachineDevicesAttached(String vmName, IMedium medium, DeviceDetails deviceDetails, String controllerName) { - lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(deviceDetails, medium, controllerName)); + + private void ensureMachineDevicesAttached(String vmName, IMedium medium, DeviceDetails deviceDetails, + String controllerName) { + lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(deviceDetails, medium, + controllerName)); } - + private String missingIDEControllersMessage(VmSpec vmSpecification) { - return String.format("First controller is not an IDE controller. Please verify that the VM spec is a correct master node: %s", vmSpecification); + return String + .format( + "First controller is not an IDE controller. Please verify that the VM spec is a correct master node: %s", + vmSpecification); } - + private void setupHardDisksForController(String vmName, StorageController controller) { Set hardDisks = controller.getHardDisks(); for (HardDisk hardDisk : hardDisks) { @@ -157,7 +165,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi } public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) { - lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"), - new AddIDEControllerIfNotExists(checkNotNull(storageController, "storageController"))); + lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"), new AddIDEControllerIfNotExists(checkNotNull( + storageController, "storageController"))); } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index c2ca14e133..04da8f47de 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -29,6 +29,7 @@ import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.domain.Credentials; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.InetSocketAddressConnect; @@ -36,19 +37,17 @@ import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; -import org.jclouds.virtualbox.util.PropertyUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.virtualbox_4_1.SessionState; import org.virtualbox_4_1.VirtualBoxManager; +import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.name.Names; /** * Tests behavior of {@code VirtualBoxClient} @@ -68,6 +67,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { protected String operatingSystemIso; protected String guestAdditionsIso; protected String adminDisk; + protected String workingDir; @Override protected void setupCredentials() { @@ -89,22 +89,18 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { Properties overrides = setupProperties(); context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet. of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); - intializeImageIdFromContext(); + Function configProperties = context.utils().injector().getInstance(ValueOfConfigurationKeyOrNull.class); + imageId = configProperties.apply(ComputeServiceConstants.PROPERTY_IMAGE_ID); + workingDir = configProperties.apply(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR); jetty = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource); startVboxIfNotAlreadyRunning(); hostVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0); - String workingDir = PropertyUtils.getWorkingDirFromProperty(); adminDisk = workingDir + "/testadmin.vdi"; operatingSystemIso = String.format("%s/%s.iso", workingDir, imageId); guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", workingDir, hostVersion); } - protected void intializeImageIdFromContext() { - imageId = context.utils().injector().getInstance( - Key.get(String.class, Names.named(ComputeServiceConstants.PROPERTY_IMAGE_ID))); - } - @AfterClass(groups = "live") protected void tearDown() throws Exception { if (context != null) diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java index f75fe09955..57f9f5da8d 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java @@ -77,7 +77,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends .cleanUpMode(mode) .forceOverwrite(true).build(); IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( - manager, clonedVmSpec, IS_LINKED_CLONE).apply(master); + manager, workingDir, 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,7 +99,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends VmSpec vmSpec = VmSpec.builder().id(vmId).name(vmName) .osTypeId(osTypeId).memoryMB(512).cleanUpMode(CleanupMode.Full) .controller(ideController).forceOverwrite(true).build(); - return new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpec); + return new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir).apply(vmSpec); } catch (IllegalStateException e) { // already created diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java index c0ae64252b..8aa0bbd8c0 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java @@ -105,9 +105,9 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { "localhost", new Credentials("toor", "password")); Predicate socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS); - IMachine imageMachine = new CreateAndInstallVm(manager, guestId, localHostContext, hostId, - socketTester, "127.0.0.1", 8080, HEADLESS) - .apply(vmSpecification); + IMachine imageMachine = new CreateAndInstallVm(manager, new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( + manager, workingDir), workingDir, guestId, localHostContext, hostId, socketTester, "127.0.0.1", 8080, + HEADLESS).apply(vmSpecification); IMachineToImage iMachineToImage = new IMachineToImage(manager, map); Image newImage = iMachineToImage.apply(imageMachine); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java index 5823d0c9f1..8808ad2a5d 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java @@ -71,7 +71,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends new UnregisterMachineIfExistsAndDeleteItsMedia(manager) .apply(launchSpecification); IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( - manager).apply(launchSpecification); + manager, workingDir).apply(launchSpecification); IMachine machine = manager.getVBox().findMachine(vmName); assertEquals(debianNode.getName(), machine.getName()); new UnregisterMachineIfExistsAndDeleteItsMedia(manager) @@ -88,7 +88,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends .apply(launchSpecification); try { - new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager) + new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir) .apply(launchSpecification); fail(); } catch (VBoxException e) { diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IsLinkedClonesLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IsLinkedClonesLiveTest.java index 3c6bcc5ccf..427cf65ac2 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IsLinkedClonesLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IsLinkedClonesLiveTest.java @@ -45,7 +45,7 @@ import org.virtualbox_4_1.VirtualBoxManager; public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest { private static final boolean IS_LINKED_CLONE = true; - private String vmId = "jclouds-image-iso-1"; + private String vmId = "jclouds-image-iso-1"; private String osTypeId = "DEBIAN"; private String ideControllerName = "IDE Controller"; private String cloneId = "jclouds-is-linked-clone-clone"; @@ -54,62 +54,49 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest { private StorageController masterStorageController; private VmSpec masterSpec; private VmSpec cloneSpec; - + @Override @BeforeClass(groups = "live") public void setupClient() { super.setupClient(); - HardDisk hardDisk = HardDisk.builder() - .diskpath(adminDisk).autoDelete(true) - .controllerPort(0).deviceSlot(1).build(); - masterStorageController = StorageController.builder() - .name(ideControllerName).bus(StorageBus.IDE) - .attachISO(0, 0, operatingSystemIso) - .attachHardDisk(hardDisk) - .attachISO(1, 1, guestAdditionsIso) - .build(); - masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512) - .osTypeId(osTypeId).controller(masterStorageController) - .forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); + HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1) + .build(); + masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0, + operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build(); + masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId).controller( + masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); - cloneSpec = VmSpec.builder().id(cloneId).name(cloneName).memoryMB(512) - .osTypeId(osTypeId).forceOverwrite(true) - .cleanUpMode(CleanupMode.Full).build(); + cloneSpec = VmSpec.builder().id(cloneId).name(cloneName).memoryMB(512).osTypeId(osTypeId).forceOverwrite(true) + .cleanUpMode(CleanupMode.Full).build(); } @Test public void testLinkedClone() { - VirtualBoxManager manager = (VirtualBoxManager) context - .getProviderSpecificContext().getApi(); + VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); - IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( - manager).apply(masterSpec); - IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( - manager, cloneSpec, IS_LINKED_CLONE).apply(master); + IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir).apply(masterSpec); + IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, cloneSpec, + IS_LINKED_CLONE).apply(master); assertTrue(new IsLinkedClone(manager).apply(clone)); - new UnregisterMachineIfExistsAndDeleteItsMedia(manager) - .apply(new IMachineToVmSpec().apply(clone)); + new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(clone)); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); } public void testFullClone() { - VirtualBoxManager manager = (VirtualBoxManager) context - .getProviderSpecificContext().getApi(); + VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); - IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( - manager).apply(masterSpec); - IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( - manager, cloneSpec, !IS_LINKED_CLONE).apply(master); + IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir).apply(masterSpec); + IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, cloneSpec, + !IS_LINKED_CLONE).apply(master); assertFalse(new IsLinkedClone(manager).apply(clone)); - new UnregisterMachineIfExistsAndDeleteItsMedia(manager) - .apply(new IMachineToVmSpec().apply(clone)); + new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(clone)); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java index 32e636b808..421d0be8b0 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java @@ -20,6 +20,7 @@ import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.functions.CreateAndInstallVm; +import org.jclouds.virtualbox.functions.CreateAndRegisterMachineFromIsoIfNotAlreadyExists; import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; @@ -42,14 +43,13 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest { @Test public void testSshDaemonIsRunning() { VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); - ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest( - hostId, "localhost", guestId, "localhost", new Credentials("toor", "password")); + ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, + "localhost", new Credentials("toor", "password")); getNodeWithSshDaemonRunning(manager, localHostContext); ensureMachineIsLaunched(vmName); - RetryablePredicate predicate = new RetryablePredicate( - new SshAvailable(localHostContext), 5, 1, - TimeUnit.SECONDS); + RetryablePredicate predicate = new RetryablePredicate(new SshAvailable(localHostContext), 5, 1, + TimeUnit.SECONDS); assertTrue(predicate.apply(guestId)); lockSessionOnMachineAndApply(manager, Shared, vmName, new Function() { @@ -66,20 +66,19 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest { private IMachine getNodeWithSshDaemonRunning(VirtualBoxManager manager, ComputeServiceContext localHostContext) { try { - Predicate socketTester = new RetryablePredicate( - new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS); + Predicate socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 10, 1, + TimeUnit.SECONDS); String vmId = "jclouds-image-iso-2"; StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE) - .attachISO(0, 0, operatingSystemIso) - .attachHardDisk(HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).build()).build(); - VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("") - .memoryMB(512) - .controller(ideController) - .forceOverwrite(true).build(); + .attachISO(0, 0, operatingSystemIso).attachHardDisk( + HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).build()).build(); + VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("").memoryMB(512).controller( + ideController).forceOverwrite(true).build(); - return new CreateAndInstallVm(manager, guestId, localHostContext, - hostId, socketTester, "127.0.0.1", 8080, HEADLESS).apply(vmSpecification); + return new CreateAndInstallVm(manager, new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, + workingDir), guestId, vmId, localHostContext, hostId, socketTester, "127.0.0.1", 8080, HEADLESS) + .apply(vmSpecification); } catch (IllegalStateException e) { // already created return manager.getVBox().findMachine(vmName); @@ -87,8 +86,7 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest { } private void ensureMachineIsLaunched(String vmName) { - applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning( - manager, ExecutionType.GUI, "")); + applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, "")); } } \ No newline at end of file diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/util/PropertyUtils.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/util/PropertyUtils.java deleted file mode 100644 index fe34719e72..0000000000 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/util/PropertyUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.jclouds.virtualbox.util; - -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR; - -public class PropertyUtils { - - public static String getWorkingDirFromProperty() { - final String defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test"; - return System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir); - } - -}