mirror of https://github.com/apache/jclouds.git
issue 384: preparation to address https://github.com/jclouds/jclouds/pull/266/files#r304746
This commit is contained in:
parent
912a2f9ae0
commit
3aaaa22660
|
@ -26,6 +26,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
/**
|
||||
* A representation of a hard disk in a VirtualBox VM.
|
||||
* <p/>
|
||||
* name is a description to identify the hard disk.
|
||||
* diskPath is an absolute path to the file that is the location of the storage for the hard disk.
|
||||
* diskFormat is any of the formats supported by ISystemProperties.getMediumFormats() in the VirtualBox API.
|
||||
* This call is platform-dependent so the supported formats differ from host to host. The default format used is VDI.
|
||||
|
@ -35,17 +36,20 @@ public class HardDisk {
|
|||
|
||||
public static final String DEFAULT_DISK_FORMAT = "vdi";
|
||||
|
||||
private final String name;
|
||||
private final String diskFormat;
|
||||
private final String diskPath;
|
||||
private final DeviceDetails deviceDetails;
|
||||
|
||||
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat) {
|
||||
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, String name) {
|
||||
checkNotNull(deviceDetails, "deviceDetails");
|
||||
checkNotNull(diskPath, "diskPath");
|
||||
checkNotNull(diskFormat, "diskFormat");
|
||||
checkNotNull(name, "name");
|
||||
this.diskPath = diskPath;
|
||||
this.diskFormat = diskFormat;
|
||||
this.deviceDetails = deviceDetails;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDiskPath() {
|
||||
|
@ -60,21 +64,26 @@ public class HardDisk {
|
|||
return deviceDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o instanceof HardDisk) {
|
||||
HardDisk hardDisk = (HardDisk) o;
|
||||
return Objects.equal(deviceDetails, hardDisk.deviceDetails) &&
|
||||
Objects.equal(diskFormat, hardDisk.diskFormat) &&
|
||||
Objects.equal(diskPath, hardDisk.diskPath);
|
||||
Objects.equal(diskPath, hardDisk.diskPath) &&
|
||||
Objects.equal(name, hardDisk.name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(diskPath, diskFormat, deviceDetails);
|
||||
return Objects.hashCode(diskPath, diskFormat, deviceDetails, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,6 +92,7 @@ public class HardDisk {
|
|||
"diskFormat='" + diskFormat + '\'' +
|
||||
", diskPath='" + diskPath + '\'' +
|
||||
", deviceDetails=" + deviceDetails +
|
||||
", name=" + name +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,24 @@
|
|||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import static org.jclouds.virtualbox.domain.HardDisk.DEFAULT_DISK_FORMAT;
|
||||
|
||||
/**
|
||||
|
@ -64,6 +75,12 @@ public class StorageController {
|
|||
return bus;
|
||||
}
|
||||
|
||||
public HardDisk getHardDisk(String diskName) {
|
||||
|
||||
final Iterable<HardDisk> hardDisks = filter(getHardDisks(), new HardDiskPredicate(diskName));
|
||||
return Iterables.getOnlyElement(hardDisks);
|
||||
}
|
||||
|
||||
public Set<HardDisk> getHardDisks() {
|
||||
return hardDisks;
|
||||
}
|
||||
|
@ -126,13 +143,13 @@ public class StorageController {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder attachHardDisk(int controllerPort, int deviceSlot, String diskPath) {
|
||||
hardDisks.add(new HardDisk(new DeviceDetails(controllerPort, deviceSlot, DeviceType.HardDisk), diskPath, DEFAULT_DISK_FORMAT));
|
||||
public Builder attachHardDisk(int controllerPort, int deviceSlot, String diskPath, String name) {
|
||||
hardDisks.add(new HardDisk(new DeviceDetails(controllerPort, deviceSlot, DeviceType.HardDisk), diskPath, DEFAULT_DISK_FORMAT, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder attachHardDisk(int controllerPort, int deviceSlot, String diskPath, String diskFormat) {
|
||||
hardDisks.add(new HardDisk(new DeviceDetails(controllerPort, deviceSlot, DeviceType.HardDisk), diskPath, diskFormat));
|
||||
public Builder attachHardDisk(int controllerPort, int deviceSlot, String diskPath, String diskFormat, String name) {
|
||||
hardDisks.add(new HardDisk(new DeviceDetails(controllerPort, deviceSlot, DeviceType.HardDisk), diskPath, diskFormat, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -141,6 +158,19 @@ public class StorageController {
|
|||
checkNotNull(bus);
|
||||
return new StorageController(name, bus, hardDisks, dvds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class HardDiskPredicate implements Predicate<HardDisk> {
|
||||
|
||||
private String diskName;
|
||||
|
||||
public HardDiskPredicate(String diskName) {
|
||||
this.diskName = diskName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(@Nullable HardDisk hardDisk) {
|
||||
return hardDisk.getName().equals(diskName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -82,15 +82,11 @@ public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function<VmSp
|
|||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Problem in deleting the media attached to %s", machine.getName());
|
||||
propagate(e);
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected <T> T propagate(Exception e) {
|
||||
Throwables.propagate(e);
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
||||
import static org.jclouds.virtualbox.domain.Statements.getIpAddress;
|
||||
import static org.jclouds.virtualbox.domain.Statements.exportIpAddressFromVmNamed;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -40,7 +40,7 @@ import com.google.common.io.Resources;
|
|||
public class GetIPAddressFromGuestAdditionsTest {
|
||||
|
||||
ScriptBuilder getIpAddressBuilder = new ScriptBuilder()
|
||||
.addStatement(getIpAddress("{args}"))
|
||||
.addStatement(exportIpAddressFromVmNamed("{args}"))
|
||||
.addStatement(interpret("echo {varl}FOUND_IP_ADDRESS{varr}{lf}"));
|
||||
|
||||
public void testUNIX() throws IOException {
|
||||
|
|
|
@ -75,6 +75,6 @@ public class VmSpecTest {
|
|||
.controller(
|
||||
StorageController.builder().name("Controller")
|
||||
.bus(StorageBus.IDE)
|
||||
.attachHardDisk(0, 0, "/tmp/tempdisk.vdi").build());
|
||||
.attachHardDisk(0, 0, "/tmp/tempdisk.vdi", "tempdisk").build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,6 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.virtualbox.domain.DeviceDetails;
|
||||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.*;
|
||||
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static org.easymock.EasyMock.anyLong;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
|
@ -36,6 +29,17 @@ import static org.easymock.classextension.EasyMock.replay;
|
|||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.virtualbox_4_1.DeviceType.HardDisk;
|
||||
|
||||
import org.jclouds.virtualbox.domain.DeviceDetails;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
|
@ -47,6 +51,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
|
||||
String controllerName = "IDE Controller";
|
||||
String diskPath = "/Users/johndoe/jclouds-virtualbox-images/admin.vdi";
|
||||
String diskName = "admin";
|
||||
String diskFormat = "vdi";
|
||||
int controllerPort = 0;
|
||||
int device = 1;
|
||||
|
@ -68,7 +73,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
StorageController controller = StorageController.builder()
|
||||
.name(controllerName)
|
||||
.bus(StorageBus.IDE)
|
||||
.attachHardDisk(controllerPort, device, diskPath)
|
||||
.attachHardDisk(controllerPort, device, diskPath, diskName)
|
||||
.build();
|
||||
|
||||
|
||||
|
@ -108,7 +113,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
StorageController controller = StorageController.builder()
|
||||
.name(controllerName)
|
||||
.bus(StorageBus.IDE)
|
||||
.attachHardDisk(controllerPort, deviceSlot, "/Users/mattias/jclouds-virtualbox-test/testadmin.vdi")
|
||||
.attachHardDisk(controllerPort, deviceSlot, "/Users/mattias/jclouds-virtualbox-test/testadmin.vdi", "testadmin")
|
||||
.build();
|
||||
|
||||
DeviceDetails deviceDetails = getOnlyElement(controller.getHardDisks()).getDeviceDetails();
|
||||
|
@ -146,7 +151,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
|||
StorageController controller = StorageController.builder()
|
||||
.name(controllerName)
|
||||
.bus(StorageBus.IDE)
|
||||
.attachHardDisk(controllerPort, deviceSlot, "/Users/mattias/jclouds-virtualbox-test/testadmin.vdi")
|
||||
.attachHardDisk(controllerPort, deviceSlot, "/Users/mattias/jclouds-virtualbox-test/testadmin.vdi", "testadmin")
|
||||
.build();
|
||||
|
||||
DeviceDetails deviceDetails = getOnlyElement(controller.getHardDisks()).getDeviceDetails();
|
||||
|
|
|
@ -19,7 +19,13 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import static org.jclouds.virtualbox.domain.ExecutionType.HEADLESS;
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.Bridged;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.net.IPSocket;
|
||||
|
@ -30,14 +36,12 @@ import org.jclouds.virtualbox.domain.StorageController;
|
|||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.jclouds.virtualbox.util.PropertyUtils;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.*;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.jclouds.virtualbox.domain.ExecutionType.HEADLESS;
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.Bridged;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
|
@ -57,7 +61,6 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
|||
|
||||
private String vmName = "jclouds-image-virtualbox-iso-to-machine-test";
|
||||
private String cloneName = vmName + "_clone";
|
||||
private String isoName = "ubuntu-11.04-server-i386.iso";
|
||||
|
||||
@Test
|
||||
public void testCloneMachineFromAnotherMachine() throws Exception {
|
||||
|
@ -86,7 +89,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
|||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||
StorageController ideController = StorageController.builder().name(controllerIDE).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId(osTypeId)
|
||||
.controller(ideController)
|
||||
|
|
|
@ -87,7 +87,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||
ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(ideController)
|
||||
|
@ -95,7 +95,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
.cleanUpMode(CleanupMode.DetachAllReturnHardDisksOnly)
|
||||
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();
|
||||
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager, CleanupMode.Full).apply(vmSpecification);
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(vmSpecification);
|
||||
}
|
||||
|
||||
public void testCreateImageMachineFromIso() throws Exception {
|
||||
|
@ -115,9 +115,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
// YAML the image desc
|
||||
Set<? extends Image> images = context.getComputeService().listImages();
|
||||
Iterable<String> imageIds = transform(images, extractId());
|
||||
|
||||
assertTrue(any(imageIds, equalTo(newImage.getId())));
|
||||
|
||||
}
|
||||
|
||||
private Function<Image, String> extractId() {
|
||||
|
|
|
@ -24,11 +24,15 @@ import static org.testng.Assert.fail;
|
|||
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
||||
import org.jclouds.virtualbox.util.PropertyUtils;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
||||
/**
|
||||
|
@ -36,24 +40,40 @@ import org.virtualbox_4_1.VBoxException;
|
|||
*/
|
||||
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
||||
@Test
|
||||
private String ideControllerName;
|
||||
private CleanupMode mode;
|
||||
private StorageController ideController;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
ideControllerName = "IDE Controller";
|
||||
mode = CleanupMode.Full;
|
||||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||
ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNewMachine() throws Exception {
|
||||
String vmName = "jclouds-test-create-1-node";
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager, CleanupMode.Full).apply(vmName);
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName)
|
||||
.osTypeId("Debian").forceOverwrite(true).build();
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).controller(ideController).cleanUpMode(mode)
|
||||
.osTypeId("Debian").forceOverwrite(true).build();
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(launchSpecification);
|
||||
IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
assertEquals(debianNode.getName(), machine.getName());
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager, CleanupMode.Full).apply(vmName);
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(launchSpecification);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNewMachineWithBadOsType() throws Exception {
|
||||
String vmName = "jclouds-test-create-2-node";
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager, CleanupMode.Full).apply(vmName);
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName)
|
||||
.osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).controller(ideController).cleanUpMode(mode)
|
||||
.osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(launchSpecification);
|
||||
|
||||
try {
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
fail();
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
|
|||
@Test
|
||||
public void testCreateMedium() throws Exception {
|
||||
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-1.vdi";
|
||||
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi");
|
||||
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi", "vdi");
|
||||
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
|
||||
manager.getVBox().findMedium(path, DeviceType.HardDisk);
|
||||
assertFileCanBeDeleted(path);
|
||||
|
@ -50,7 +50,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
|
|||
@Test
|
||||
public void testCreateMediumFailWhenUsingNonFullyQualifiedPath() throws Exception {
|
||||
String path = "test-medium-2.vdi";
|
||||
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi");
|
||||
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi", "vdi");
|
||||
try {
|
||||
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
|
||||
fail();
|
||||
|
@ -63,7 +63,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
|
|||
@Test
|
||||
public void testCreateSameMediumTwiceWhenUsingOverwrite() throws Exception {
|
||||
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-3.vdi";
|
||||
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi");
|
||||
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi", "vdi");
|
||||
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
|
||||
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
|
||||
manager.getVBox().findMedium(path, DeviceType.HardDisk);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static org.easymock.EasyMock.anyLong;
|
||||
import static org.easymock.EasyMock.eq;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
|
@ -48,11 +47,14 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
|
||||
private String adminDiskPath;
|
||||
private String diskFormat;
|
||||
private String diskName;
|
||||
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() throws Exception {
|
||||
adminDiskPath = "/Users/johndoe/jclouds-virtualbox-images/admin.vdi";
|
||||
diskFormat = "vdi";
|
||||
diskName = "diskName";
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -158,7 +160,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
}
|
||||
|
||||
private HardDisk createTestHardDisk() {
|
||||
return new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), adminDiskPath, diskFormat);
|
||||
return new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), adminDiskPath, diskFormat, diskName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,18 +29,28 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
@Test(groups = "unit", testName = "UnregisterMachineIfExistsTest")
|
||||
public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
||||
|
||||
private String ideControllerName = "IDE Controller";
|
||||
private CleanupMode mode = CleanupMode.Full;
|
||||
private String vmName = "jclouds-image-example-machine-to-be-destroyed";
|
||||
private String vmId = "jclouds-image-iso-unregister";
|
||||
private String osTypeId = "";
|
||||
|
||||
@Test
|
||||
public void testUnregisterExistingMachine() throws Exception {
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
|
@ -49,13 +59,17 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
|||
IProgress progress = createNiceMock(IProgress.class);
|
||||
List<IMedium> media = new ArrayList<IMedium>();
|
||||
List<IMedium> mediums = Collections.unmodifiableList(media);
|
||||
|
||||
CleanupMode mode = CleanupMode.Full;
|
||||
String vmName = "jclouds-image-example-machine-to-be-destroyed";
|
||||
|
||||
String vmId = "jclouds-image-iso-unregister";
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512) .cleanUpMode(mode)
|
||||
.build();
|
||||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||
StorageController ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.DetachAllReturnHardDisksOnly)
|
||||
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();
|
||||
|
||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||
expect(vBox.findMachine(vmName)).andReturn(registeredMachine);
|
||||
|
|
|
@ -69,7 +69,7 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi").build();
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin").build();
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("")
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true).build();
|
||||
|
|
Loading…
Reference in New Issue