mirror of https://github.com/apache/jclouds.git
Removed settingsFile until properly supported. Added live tests for AttachDistroMediumToMachine.
This commit is contained in:
parent
be1847ce9b
commit
13f1a68b67
|
@ -19,29 +19,26 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Function<String, IMachine> {
|
||||
|
||||
private String settingsFile;
|
||||
private String osTypeId;
|
||||
private String vmId;
|
||||
private boolean forceOverwrite;
|
||||
private VirtualBoxManager manager;
|
||||
|
||||
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String settingsFile, String osTypeId, String vmId,
|
||||
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String osTypeId, String vmId,
|
||||
boolean forceOverwrite, VirtualBoxManager manager) {
|
||||
this.settingsFile = settingsFile;
|
||||
this.osTypeId = osTypeId;
|
||||
this.vmId = vmId;
|
||||
this.forceOverwrite = forceOverwrite;
|
||||
|
@ -68,7 +65,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
|||
}
|
||||
|
||||
private IMachine createMachine(IVirtualBox vBox, String vmName) {
|
||||
IMachine newMachine = vBox.createMachine(settingsFile, vmName, osTypeId, vmId, forceOverwrite);
|
||||
// TODO: add support for settingsfile
|
||||
String settingsFile1 = null;
|
||||
IMachine newMachine = vBox.createMachine(settingsFile1, vmName, osTypeId, vmId, forceOverwrite);
|
||||
manager.getVBox().registerMachine(newMachine);
|
||||
return newMachine;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
private VirtualBoxManager manager;
|
||||
private String adminDisk;
|
||||
private String diskFormat;
|
||||
private String settingsFile;
|
||||
private String vmName;
|
||||
private String osTypeId;
|
||||
private String vmId;
|
||||
|
@ -75,14 +74,13 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
private int webServerPort;
|
||||
|
||||
@Inject
|
||||
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile,
|
||||
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat,
|
||||
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
|
||||
ComputeServiceContext context, String hostId, String guestId, Predicate<IPSocket> socketTester,
|
||||
String webServerHost, int webServerPort) {
|
||||
this.manager = manager;
|
||||
this.adminDisk = adminDisk;
|
||||
this.diskFormat = diskFormat;
|
||||
this.settingsFile = settingsFile;
|
||||
this.vmName = vmName;
|
||||
this.osTypeId = osTypeId;
|
||||
this.vmId = vmId;
|
||||
|
@ -101,7 +99,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
|||
|
||||
ensureWebServerIsRunning();
|
||||
|
||||
final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite,
|
||||
final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(osTypeId, vmId, forceOverwrite,
|
||||
manager).apply(vmName);
|
||||
|
||||
final String defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test";
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.functions;
|
||||
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExists;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.jclouds.virtualbox.util.MachineUtils.lockMachineAndApply;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
*/
|
||||
public class AttachDistroMediumToMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
||||
@Test
|
||||
public void testAttachMediumToMachine() throws Exception {
|
||||
String nodeName = "test-attach-medium-node-1";
|
||||
String controllerName = "My Controller";
|
||||
new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(nodeName);
|
||||
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-attach-medium-1.vdi";
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("Debian", nodeName, true, manager)
|
||||
.apply(nodeName);
|
||||
lockMachineAndApply(manager, LockType.Write, nodeName,
|
||||
new AddIDEControllerIfNotExists(controllerName));
|
||||
IMedium medium = new CreateMediumIfNotAlreadyExists(manager, "vdi", true).apply(path);
|
||||
lockMachineAndApply(manager, LockType.Write, nodeName,
|
||||
new AttachDistroMediumToMachine(controllerName, medium));
|
||||
new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(nodeName);
|
||||
medium.close();
|
||||
assertFileCanBeDeleted(path);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachMediumToMachineTwice() throws Exception {
|
||||
String nodeName = "test-attach-medium-node-2";
|
||||
String controllerName = "My Controller";
|
||||
new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(nodeName);
|
||||
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-attach-medium-2.vdi";
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("Debian", nodeName, true, manager)
|
||||
.apply(nodeName);
|
||||
lockMachineAndApply(manager, LockType.Write, nodeName, new AddIDEControllerIfNotExists(controllerName));
|
||||
IMedium medium = new CreateMediumIfNotAlreadyExists(manager, "vdi", true).apply(path);
|
||||
lockMachineAndApply(manager, LockType.Write, nodeName, new AttachDistroMediumToMachine(controllerName, medium));
|
||||
lockMachineAndApply(manager, LockType.Write, nodeName, new AttachDistroMediumToMachine(controllerName, medium));
|
||||
new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(nodeName);
|
||||
medium.close();
|
||||
assertFileCanBeDeleted(path);
|
||||
}
|
||||
|
||||
private void assertFileCanBeDeleted(String path) {
|
||||
File file = new File(path);
|
||||
boolean mediumDeleted = file.delete();
|
||||
assertTrue(mediumDeleted);
|
||||
}
|
||||
}
|
|
@ -85,7 +85,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
|||
try {
|
||||
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
|
||||
return new IsoToIMachine(manager, adminDisk, diskFormat,
|
||||
settingsFile, vmName, osTypeId, vmId, forceOverwrite,
|
||||
vmName, osTypeId, vmId, forceOverwrite,
|
||||
controllerIDE, localHostContext, hostId, guestId, socketTester,
|
||||
"127.0.0.1", 8080).apply(isoName);
|
||||
} catch (IllegalStateException e) {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
|||
@Test
|
||||
public void testCreateNewMachine() throws Exception {
|
||||
new UnregisterMachineIfExists(manager, CleanupMode.Full).apply("jclouds-test-create-1-node");
|
||||
IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(null, "Debian", "jclouds-test-create-1", true, manager)
|
||||
IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("Debian", "jclouds-test-create-1", true, manager)
|
||||
.apply("jclouds-test-create-1-node");
|
||||
IMachine machine = manager.getVBox().findMachine("jclouds-test-create-1-node");
|
||||
assertEquals(debianNode.getName(), machine.getName());
|
||||
|
@ -49,7 +49,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
|||
public void testCreateNewMachineWithBadOsType() throws Exception {
|
||||
new UnregisterMachineIfExists(manager, CleanupMode.Full).apply("jclouds-test-create-2-node");
|
||||
try {
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(null, "SomeWeirdUnknownOs", "jclouds-test-create-2", true, manager)
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("SomeWeirdUnknownOs", "jclouds-test-create-2", true, manager)
|
||||
.apply("jclouds-test-create-2-node");
|
||||
fail();
|
||||
} catch (VBoxException e) {
|
||||
|
|
|
@ -68,7 +68,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", false, manager).apply(vmName);
|
||||
|
||||
verify(manager, vBox);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", false, manager).apply(vmName);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = VBoxException.class)
|
||||
|
@ -107,7 +107,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", false, manager).apply(vmName);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.in;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
|
@ -36,7 +35,6 @@ import org.jclouds.compute.ComputeServiceContext;
|
|||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.predicates.SocketOpenPredicates;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.json.Json;
|
||||
|
@ -44,7 +42,6 @@ import org.jclouds.json.config.GsonModule;
|
|||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.predicates.SocketOpen;
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExists;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
|
@ -67,7 +64,6 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||
.getInstance(Json.class));
|
||||
|
||||
private String settingsFile = null;
|
||||
private boolean forceOverwrite = true;
|
||||
private String vmId = "jclouds-image-iso-1";
|
||||
private String osTypeId = "";
|
||||
|
@ -92,7 +88,7 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId,
|
||||
"localhost", new Credentials("toor", "password"));
|
||||
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
|
||||
IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, settingsFile, vmName, osTypeId, vmId,
|
||||
IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, vmName, osTypeId, vmId,
|
||||
forceOverwrite, controllerIDE, localHostContext, hostId, guestId, socketTester, "127.0.0.1", 8080)
|
||||
.apply("ubuntu-11.04-server-i386.iso");
|
||||
|
||||
|
|
Loading…
Reference in New Issue