mirror of https://github.com/apache/jclouds.git
got rid of propertyutils
This commit is contained in:
parent
347a12a68f
commit
1255d91eef
|
@ -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<IMachine, IMachine> {
|
||||
|
@ -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<CloneOptions> options = new ArrayList<CloneOptions>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<VmSpec, IMachine> {
|
||||
|
||||
|
@ -54,6 +71,7 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
|
|||
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<VmSpec, IMachine> {
|
|||
private final ExecutionType executionType;
|
||||
|
||||
@Inject
|
||||
public CreateAndInstallVm(VirtualBoxManager manager, String guestId, ComputeServiceContext context,
|
||||
String hostId, Predicate<IPSocket> 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<IPSocket> 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<VmSpec, IMachine> {
|
|||
|
||||
ensureWebServerIsRunning();
|
||||
|
||||
final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpec);
|
||||
final IMachine vm =createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(vmSpec);
|
||||
|
||||
String vmName = vmSpec.getVmName();
|
||||
|
||||
|
|
|
@ -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<VmSpec, IMachine> {
|
||||
|
||||
|
||||
@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<IsoImage> 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<HardDisk> 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")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
|
||||
intializeImageIdFromContext();
|
||||
Function<String, String> 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -105,9 +105,9 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
"localhost", new Credentials("toor", "password"));
|
||||
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> predicate = new RetryablePredicate<String>(
|
||||
new SshAvailable(localHostContext), 5, 1,
|
||||
TimeUnit.SECONDS);
|
||||
RetryablePredicate<String> predicate = new RetryablePredicate<String>(new SshAvailable(localHostContext), 5, 1,
|
||||
TimeUnit.SECONDS);
|
||||
assertTrue(predicate.apply(guestId));
|
||||
|
||||
lockSessionOnMachineAndApply(manager, Shared, vmName, new Function<ISession, Void>() {
|
||||
|
@ -66,20 +66,19 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
|
||||
private IMachine getNodeWithSshDaemonRunning(VirtualBoxManager manager, ComputeServiceContext localHostContext) {
|
||||
try {
|
||||
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(
|
||||
new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
|
||||
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(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, ""));
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue