From 3aaaa22660db055cb5ead5f62751f505c2529b2f Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Tue, 20 Dec 2011 13:07:50 +0000 Subject: [PATCH] issue 384: preparation to address https://github.com/jclouds/jclouds/pull/266/files#r304746 --- .../jclouds/virtualbox/domain/HardDisk.java | 18 +++++++-- .../virtualbox/domain/StorageController.java | 40 ++++++++++++++++--- ...isterMachineIfExistsAndDeleteItsMedia.java | 8 +--- .../GetIPAddressFromGuestAdditionsTest.java | 4 +- .../jclouds/virtualbox/domain/VmSpecTest.java | 2 +- ...diumToMachineIfNotAlreadyAttachedTest.java | 25 +++++++----- ...hineFromIsoIfNotAlreadyExistsLiveTest.java | 23 ++++++----- .../functions/CreateAndInstallVmLiveTest.java | 6 +-- ...hineFromIsoIfNotAlreadyExistsLiveTest.java | 36 +++++++++++++---- ...reateMediumIfNotAlreadyExistsLiveTest.java | 6 +-- .../CreateMediumIfNotAlreadyExistsTest.java | 6 ++- ...rMachineIfExistsAndDeleteItsMediaTest.java | 26 +++++++++--- .../predicates/SshAvailableLiveTest.java | 2 +- 13 files changed, 140 insertions(+), 62 deletions(-) diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java index ef52c270a7..3fc1214223 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java @@ -26,6 +26,7 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * A representation of a hard disk in a VirtualBox VM. *

+ * 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 + '}'; } } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java index 7bdcd6a7f1..663d1b0d43 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java @@ -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 hardDisks = filter(getHardDisks(), new HardDiskPredicate(diskName)); + return Iterables.getOnlyElement(hardDisks); + } + public Set 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 { + + private String diskName; + + public HardDiskPredicate(String diskName) { + this.diskName = diskName; + } + + @Override + public boolean apply(@Nullable HardDisk hardDisk) { + return hardDisk.getName().equals(diskName); + } + }; } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java index 9f9d48fdfe..b586d7e9e1 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java @@ -82,15 +82,11 @@ public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function T propagate(Exception e) { - Throwables.propagate(e); - assert false; - return null; - } + } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GetIPAddressFromGuestAdditionsTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GetIPAddressFromGuestAdditionsTest.java index 05b8c9184c..a87791cb64 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GetIPAddressFromGuestAdditionsTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GetIPAddressFromGuestAdditionsTest.java @@ -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 { diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java index 8bdc04a56c..4871ab2bdb 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java @@ -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()); } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java index 250c83b2cb..c2d9734fbd 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java @@ -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(); 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 07e48ef4b4..83911f23ed 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 @@ -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) 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 fa1087d2ad..cd11cedac0 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 @@ -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 images = context.getComputeService().listImages(); Iterable imageIds = transform(images, extractId()); - assertTrue(any(imageIds, equalTo(newImage.getId()))); - } private Function extractId() { 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 3306ff1764..8511f97a9a 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 @@ -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(); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java index ebe48653bd..708a97c63f 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java @@ -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); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java index 363e165f42..95600155cf 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java @@ -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); } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java index 453c5b60ed..77d246974e 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java @@ -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 media = new ArrayList(); List 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); 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 8cd2480423..18127f6290 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 @@ -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();