mirror of https://github.com/apache/jclouds.git
Issue 384: support virtualbox 4.1.2r73507
This commit is contained in:
parent
04dde80bd4
commit
2274e7d4e6
|
@ -20,16 +20,15 @@ package org.jclouds.virtualbox.experiment;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Throwables.propagate;
|
import static com.google.common.base.Throwables.propagate;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.blockOnPort;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
|
@ -63,6 +62,7 @@ import org.virtualbox_4_1.IStorageController;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_1.LockType;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_1.MachineState;
|
||||||
import org.virtualbox_4_1.NATProtocol;
|
import org.virtualbox_4_1.NATProtocol;
|
||||||
|
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_1.SessionState;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_1.StorageBus;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
@ -116,10 +116,14 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
private String minorVersion;
|
private String minorVersion;
|
||||||
|
|
||||||
protected void setupCredentials() {
|
protected void setupCredentials() {
|
||||||
identity = System.getProperty("test." + provider + ".identity", "administrator");
|
identity = System.getProperty("test." + provider + ".identity",
|
||||||
credential = System.getProperty("test." + provider + ".credential", "12345");
|
"administrator");
|
||||||
endpoint = URI.create(System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/"));
|
credential = System.getProperty("test." + provider + ".credential",
|
||||||
apiVersion = System.getProperty("test." + provider + ".apiversion", "4.1.2r73507");
|
"12345");
|
||||||
|
endpoint = URI.create(System.getProperty("test." + provider
|
||||||
|
+ ".endpoint", "http://localhost:18083/"));
|
||||||
|
apiVersion = System.getProperty("test." + provider + ".apiversion",
|
||||||
|
"4.1.2r73507");
|
||||||
majorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 0);
|
majorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 0);
|
||||||
minorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 1);
|
minorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 1);
|
||||||
}
|
}
|
||||||
|
@ -130,8 +134,10 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
|
|
||||||
protected void setupConfigurationProperties() {
|
protected void setupConfigurationProperties() {
|
||||||
|
|
||||||
controllerIDE = System.getProperty("test." + provider + ".controllerIde", "IDE Controller");
|
controllerIDE = System.getProperty("test." + provider
|
||||||
controllerSATA = System.getProperty("test." + provider + ".controllerSata", "SATA Controller");
|
+ ".controllerIde", "IDE Controller");
|
||||||
|
controllerSATA = System.getProperty("test." + provider
|
||||||
|
+ ".controllerSata", "SATA Controller");
|
||||||
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
||||||
|
|
||||||
// VBOX
|
// VBOX
|
||||||
|
@ -139,34 +145,59 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
osTypeId = System.getProperty("test." + provider + ".osTypeId", "");
|
osTypeId = System.getProperty("test." + provider + ".osTypeId", "");
|
||||||
vmId = System.getProperty("test." + provider + ".vmId", null);
|
vmId = System.getProperty("test." + provider + ".vmId", null);
|
||||||
forceOverwrite = true;
|
forceOverwrite = true;
|
||||||
vmName = System.getProperty("test." + provider + ".vmname", "jclouds-virtualbox-kickstart-admin");
|
vmName = System.getProperty("test." + provider + ".vmname",
|
||||||
|
"jclouds-virtualbox-kickstart-admin");
|
||||||
|
|
||||||
workingDir = System.getProperty("user.home") + File.separator
|
workingDir = System.getProperty("user.home")
|
||||||
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
+ File.separator
|
||||||
|
+ System.getProperty("test." + provider + ".workingDir",
|
||||||
|
"jclouds-virtualbox-test");
|
||||||
if (new File(workingDir).mkdir())
|
if (new File(workingDir).mkdir())
|
||||||
;
|
;
|
||||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion
|
// gaIsoName = System.getProperty("test." + provider + ".gaIsoName",
|
||||||
+ "-update-" + minorVersion + ".iso");
|
// "VBoxGuestAdditions_" + majorVersion + "-update-" + minorVersion +
|
||||||
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl",
|
// ".iso");
|
||||||
"http://download.virtualbox.org/virtualbox/" + majorVersion + "/VBoxGuestAdditions_" + majorVersion + ".iso"));
|
gaIsoName = System.getProperty("test." + provider + ".gaIsoName",
|
||||||
|
"VBoxGuestAdditions_" + majorVersion + ".iso");
|
||||||
|
gaIsoUrl = URI.create(System.getProperty("test." + provider
|
||||||
|
+ ".gaIsoUrl", "http://download.virtualbox.org/virtualbox/"
|
||||||
|
+ majorVersion + "/" + gaIsoName));
|
||||||
|
|
||||||
distroIsoName = System.getProperty("test." + provider + ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
distroIsoName = System.getProperty("test." + provider
|
||||||
distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl",
|
+ ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
||||||
|
distroIsoUrl = URI
|
||||||
|
.create(System
|
||||||
|
.getProperty("test." + provider + ".distroIsoUrl",
|
||||||
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"));
|
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"));
|
||||||
|
|
||||||
originalDisk = workingDir + File.separator + "VDI" + File.separator
|
originalDisk = workingDir
|
||||||
+ System.getProperty("test." + provider + ".originalDisk", "centos-5.2-x86.vdi");
|
+ File.separator
|
||||||
clonedDisk = workingDir + File.separator + System.getProperty("test." + provider + ".clonedDisk", "template.vdi");
|
+ "VDI"
|
||||||
|
+ File.separator
|
||||||
|
+ System.getProperty("test." + provider + ".originalDisk",
|
||||||
|
"centos-5.2-x86.vdi");
|
||||||
|
clonedDisk = workingDir
|
||||||
|
+ File.separator
|
||||||
|
+ System.getProperty("test." + provider + ".clonedDisk",
|
||||||
|
"disk.vdi");
|
||||||
guestAdditionsDvd = workingDir
|
guestAdditionsDvd = workingDir
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ System.getProperty("test." + provider + ".guestAdditionsDvd", "VBoxGuestAdditions_" + majorVersion
|
+ System.getProperty("test." + provider + ".guestAdditionsDvd",
|
||||||
+ "-update-" + minorVersion + ".iso");
|
"VBoxGuestAdditions_" + majorVersion + "-update-"
|
||||||
|
+ minorVersion + ".iso");
|
||||||
|
|
||||||
preseedUrl = System.getProperty("test." + provider + ".preseedurl", "http://dl.dropbox.com/u/693111/preseed.cfg");
|
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
|
||||||
|
"http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||||
|
|
||||||
keyboardSequence = System.getProperty("test." + provider + ".keyboardSequence", "<Esc> <Esc> <Enter> "
|
keyboardSequence = System
|
||||||
|
.getProperty(
|
||||||
|
"test." + provider + ".keyboardSequence",
|
||||||
|
"<Esc> <Esc> <Enter> "
|
||||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
||||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " "
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||||
|
+ "hostname="
|
||||||
|
+ vmName
|
||||||
|
+ " "
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ "fb=false debconf/frontend=noninteractive "
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
+ "initrd=/install/initrd.gz -- <Enter>");
|
||||||
|
@ -176,16 +207,18 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
@BeforeGroups(groups = "live")
|
@BeforeGroups(groups = "live")
|
||||||
protected void setupClient() throws Exception {
|
protected void setupClient() throws Exception {
|
||||||
context = TestUtils.computeServiceForLocalhost();
|
context = TestUtils.computeServiceForLocalhost();
|
||||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);
|
socketTester = new RetryablePredicate<IPSocket>(
|
||||||
|
new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);
|
||||||
setupCredentials();
|
setupCredentials();
|
||||||
setupConfigurationProperties();
|
setupConfigurationProperties();
|
||||||
downloadFileUnlessPresent(distroIsoUrl, workingDir, distroIsoName);
|
downloadFileUnlessPresent(distroIsoUrl, workingDir, distroIsoName);
|
||||||
downloadFileUnlessPresent(gaIsoUrl, workingDir, gaIsoName);
|
downloadFileUnlessPresent(gaIsoUrl, workingDir, gaIsoName);
|
||||||
|
|
||||||
installVbox();
|
installVbox();
|
||||||
checkVboxVersionExpected();
|
checkVboxVersionExpected();
|
||||||
if (!new InetSocketAddressConnect().apply(new IPSocket(endpoint.getHost(), endpoint.getPort())))
|
if (!new InetSocketAddressConnect().apply(new IPSocket(endpoint
|
||||||
|
.getHost(), endpoint.getPort())))
|
||||||
startupVboxWebServer();
|
startupVboxWebServer();
|
||||||
|
|
||||||
configureJettyServer();
|
configureJettyServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,32 +233,42 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
logger().info("serving " + resource_handler.getBaseResource());
|
logger().info("serving " + resource_handler.getBaseResource());
|
||||||
|
|
||||||
HandlerList handlers = new HandlerList();
|
HandlerList handlers = new HandlerList();
|
||||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
handlers.setHandlers(new Handler[] { resource_handler,
|
||||||
|
new DefaultHandler() });
|
||||||
server.setHandler(handlers);
|
server.setHandler(handlers);
|
||||||
|
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void installVbox() throws IOException, InterruptedException {
|
void installVbox() {
|
||||||
if (runScriptOnNode(hostId, "VBoxManage -version").getExitCode() != 0) {
|
if (runScriptOnNode(hostId, "VBoxManage --version").getExitCode() != 0) {
|
||||||
logger().debug("installing virtualbox");
|
logger().debug("installing virtualbox");
|
||||||
if (isOSX(hostId))
|
if (isOSX(hostId))
|
||||||
;// TODO
|
;// TODO
|
||||||
else
|
else {
|
||||||
runScriptOnNode(hostId, "apt-get --yes install virtualbox-ose");
|
|
||||||
// TODO other platforms
|
// TODO other platforms
|
||||||
|
runScriptOnNode(hostId, "cat > /etc/apt/sources.list.d/TODO");
|
||||||
|
runScriptOnNode(
|
||||||
|
hostId,
|
||||||
|
"wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -");
|
||||||
|
runScriptOnNode(hostId, "apt-get update");
|
||||||
|
runScriptOnNode(hostId, "apt-get --yes install virtualbox-4.1");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkVboxVersionExpected() throws IOException, InterruptedException {
|
void checkVboxVersionExpected() throws IOException, InterruptedException {
|
||||||
logger().debug("checking virtualbox version");
|
logger().debug("checking virtualbox version");
|
||||||
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
|
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput()
|
||||||
|
.trim(), apiVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param command
|
* @param command
|
||||||
* absolute path to command. For ubuntu 10.04: /usr/bin/vboxwebsrv
|
* absolute path to command. For ubuntu 10.04:
|
||||||
|
* /usr/bin/vboxwebsrv
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
|
@ -233,19 +276,25 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
logger().debug("disabling password access");
|
logger().debug("disabling password access");
|
||||||
runScriptOnNode(hostId, "VBoxManage setproperty websrvauthlibrary null");
|
runScriptOnNode(hostId, "VBoxManage setproperty websrvauthlibrary null");
|
||||||
logger().debug("starting vboxwebsrv");
|
logger().debug("starting vboxwebsrv");
|
||||||
String vboxwebsrv = "vboxwebsrv -t 5 -v";
|
String vboxwebsrv = "vboxwebsrv -t 10000 -v -b";
|
||||||
if (isOSX(hostId))
|
if (isOSX(hostId))
|
||||||
vboxwebsrv = "cd /Applications/VirtualBox.app/Contents/MacOS/&&" + vboxwebsrv;
|
vboxwebsrv = "cd /Applications/VirtualBox.app/Contents/MacOS/&&"
|
||||||
|
+ vboxwebsrv;
|
||||||
// allow jclouds to background the process, this is why we don't specify
|
// allow jclouds to background the process, this is why we don't specify
|
||||||
// -b; logs will go corresponding to task name in this case under
|
// -b;
|
||||||
|
// logs will go corresponding to task name in this case under
|
||||||
// /tmp/vboxwebsrv
|
// /tmp/vboxwebsrv
|
||||||
runScriptOnNode(hostId, vboxwebsrv,
|
runScriptOnNode(
|
||||||
blockOnPort(endpoint.getPort(), 10).blockOnComplete(false).nameTask("vboxwebsrv"));
|
hostId,
|
||||||
|
vboxwebsrv,
|
||||||
|
runAsRoot(false).wrapInInitScript(false)
|
||||||
|
.blockOnPort(endpoint.getPort(), 10)
|
||||||
|
.blockOnComplete(false).nameTask("vboxwebsrv"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isOSX(String id) {
|
protected boolean isOSX(String id) {
|
||||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription()
|
return context.getComputeService().getNodeMetadata(hostId)
|
||||||
.equals("Mac OS X");
|
.getOperatingSystem().getDescription().equals("Mac OS X");
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
|
@ -254,15 +303,27 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
protected void disconnectAndClenaupManager() throws RemoteException, MalformedURLException {
|
protected void disconnectAndClenaupManager() throws RemoteException,
|
||||||
|
MalformedURLException {
|
||||||
manager.disconnect();
|
manager.disconnect();
|
||||||
manager.cleanup();
|
manager.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateVirtualMachine() {
|
public void testCreateVirtualMachine() {
|
||||||
IMachine newVM = manager.getVBox().createMachine(settingsFile, vmName, osTypeId, vmId, forceOverwrite);
|
/*
|
||||||
|
* IMachine machine = manager.getVBox().findMachine(vmName); if(machine
|
||||||
|
* != null) { ISession session = manager.getSessionObject();
|
||||||
|
* machine.lockMachine(session, LockType.Write); IMachine mutable =
|
||||||
|
* session.getMachine(); List<IMedium> media =
|
||||||
|
* machine.unregister(CleanupMode.Full); machine.delete(media);
|
||||||
|
* mutable.saveSettings(); session.unlockMachine();
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
IMachine newVM = manager.getVBox().createMachine(settingsFile, vmName,
|
||||||
|
osTypeId, vmId, forceOverwrite);
|
||||||
manager.getVBox().registerMachine(newVM);
|
manager.getVBox().registerMachine(newVM);
|
||||||
assertEquals(newVM.getName(), vmName);
|
assertNotNull(newVM.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateVirtualMachine")
|
@Test(dependsOnMethods = "testCreateVirtualMachine")
|
||||||
|
@ -275,36 +336,56 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
mutable.setMemorySize(memorySize);
|
mutable.setMemorySize(memorySize);
|
||||||
mutable.saveSettings();
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(), memorySize);
|
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(),
|
||||||
|
memorySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testChangeRAM")
|
@Test(dependsOnMethods = "testChangeRAM")
|
||||||
public void testCreateScsiController() {
|
public void testCreateIdeController() {
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
mutable.addStorageController(controllerSATA, StorageBus.SATA);
|
mutable.addStorageController(controllerIDE, StorageBus.IDE);
|
||||||
mutable.saveSettings();
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
assertEquals(manager.getVBox().findMachine(vmName).getStorageControllers().size(), 2);
|
assertEquals(manager.getVBox().findMachine(vmName)
|
||||||
|
.getStorageControllers().size(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateScsiController")
|
@Test(dependsOnMethods = "testCreateIdeController")
|
||||||
public void testCreateAndAttachHardDisk() {
|
public void testAttachIsoDvd() {
|
||||||
|
IMedium distroMedium = manager.getVBox().openMedium(
|
||||||
|
workingDir + "/" + distroIsoName, DeviceType.DVD,
|
||||||
|
AccessMode.ReadOnly, forceOverwrite);
|
||||||
|
|
||||||
|
ISession session = manager.getSessionObject();
|
||||||
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
|
machine.lockMachine(session, LockType.Write);
|
||||||
|
IMachine mutable = session.getMachine();
|
||||||
|
mutable.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||||
|
mutable.saveSettings(); // write settings to xml
|
||||||
|
session.unlockMachine();
|
||||||
|
assertEquals(distroMedium.getId().equals(""), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testAttachIsoDvd")
|
||||||
|
public void testCreateAndAttachHardDisk() throws InterruptedException {
|
||||||
IMedium hd = null;
|
IMedium hd = null;
|
||||||
if (!new File(clonedDisk).exists()) {
|
if (!new File(clonedDisk).exists()) {
|
||||||
hd = manager.getVBox().createHardDisk(diskFormat, clonedDisk);
|
hd = manager.getVBox().createHardDisk(diskFormat, clonedDisk);
|
||||||
long size = 2 * 1024 * 1024 * 1024 - 1;
|
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
||||||
hd.createBaseStorage(new Long(size), new Long(MediumVariant.VMDK_SPLIT_2_G.ordinal()));
|
IProgress progress = hd.createBaseStorage(new Long(size), new Long(
|
||||||
} else
|
MediumVariant.STANDARD.ordinal()));
|
||||||
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk, AccessMode.ReadWrite, forceOverwrite);
|
progress.wait();
|
||||||
|
}
|
||||||
|
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
mutable.attachDevice(controllerSATA, 0, 0, DeviceType.HardDisk, hd);
|
mutable.attachDevice(controllerIDE, 0, 1, DeviceType.HardDisk, hd);
|
||||||
mutable.saveSettings(); // write settings to xml
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
assertEquals(hd.getId().equals(""), false);
|
assertEquals(hd.getId().equals(""), false);
|
||||||
}
|
}
|
||||||
|
@ -316,40 +397,28 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
|
|
||||||
// network BRIDGED to access HTTP server
|
|
||||||
String hostInterface = null;
|
|
||||||
String command = "VBoxManage list bridgedifs";
|
|
||||||
try {
|
|
||||||
Process child = Runtime.getRuntime().exec(command);
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
|
||||||
String line = "";
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
while ((line = bufferedReader.readLine()) != null && !found) {
|
|
||||||
|
|
||||||
if (line.split(":")[0].contains("Name")) {
|
|
||||||
hostInterface = line.split(":")[1];
|
|
||||||
}
|
|
||||||
if (line.split(":")[0].contains("Status") && line.split(":")[1].contains("Up")) {
|
|
||||||
System.out.println("bridge: " + hostInterface.trim());
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NAT
|
// NAT
|
||||||
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); TODO: this no
|
mutable.getNetworkAdapter(new Long(0)).setAttachmentType(
|
||||||
// longer exists!
|
NetworkAttachmentType.NAT);
|
||||||
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
|
machine.getNetworkAdapter(new Long(0))
|
||||||
machine.getNetworkAdapter(new Long(0)).getNatDriver()
|
.getNatDriver()
|
||||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222, "", 22);
|
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222,
|
||||||
|
"", 22);
|
||||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
||||||
|
|
||||||
mutable.saveSettings();
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
propagate(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testConfigureNIC")
|
||||||
|
public void testConfigureVRDE() {
|
||||||
|
ISession session = manager.getSessionObject();
|
||||||
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
|
machine.lockMachine(session, LockType.Write);
|
||||||
|
IMachine mutable = session.getMachine();
|
||||||
|
mutable.getVRDEServer().setEnabled(new Boolean(true));
|
||||||
|
mutable.saveSettings(); // write settings to xml
|
||||||
|
session.unlockMachine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testConfigureNIC")
|
@Test(dependsOnMethods = "testConfigureNIC")
|
||||||
|
@ -371,7 +440,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
public void testConfigureGuestAdditions() {
|
public void testConfigureGuestAdditions() {
|
||||||
// Configure your system for building kernel modules by running
|
// Configure your system for building kernel modules by running
|
||||||
runScriptOnNode(guestId, "m-a prepare -i");
|
runScriptOnNode(guestId, "m-a prepare -i");
|
||||||
runScriptOnNode(guestId, "mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
|
runScriptOnNode(guestId,
|
||||||
|
"mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
|
||||||
runScriptOnNode(guestId, "/mnt/VBoxLinuxAdditions.run");
|
runScriptOnNode(guestId, "/mnt/VBoxLinuxAdditions.run");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +464,9 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
|
|
||||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
||||||
try {
|
try {
|
||||||
System.out.println("waiting for unlocking session - session state: " + machine.getSessionState());
|
System.out
|
||||||
|
.println("waiting for unlocking session - session state: "
|
||||||
|
+ machine.getSessionState());
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -412,13 +484,15 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
mutable.getNetworkAdapter(new Long(0)).getNatDriver().removeRedirect("guestssh");
|
mutable.getNetworkAdapter(new Long(0)).getNatDriver()
|
||||||
|
.removeRedirect("guestssh");
|
||||||
// detach disk from controller
|
// detach disk from controller
|
||||||
mutable.detachDevice(controllerIDE, 0, 0);
|
mutable.detachDevice(controllerIDE, 0, 0);
|
||||||
mutable.saveSettings();
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
|
|
||||||
for (IStorageController storageController : machine.getStorageControllers()) {
|
for (IStorageController storageController : machine
|
||||||
|
.getStorageControllers()) {
|
||||||
if (storageController.getName().equals(controllerSATA)) {
|
if (storageController.getName().equals(controllerSATA)) {
|
||||||
session = manager.getSessionObject();
|
session = manager.getSessionObject();
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
|
@ -436,8 +510,10 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
runScriptOnNode(guestId, "pidof vboxwebsrv | xargs kill");
|
runScriptOnNode(guestId, "pidof vboxwebsrv | xargs kill");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ExecResponse runScriptOnNode(String nodeId, String command, RunScriptOptions options) {
|
protected ExecResponse runScriptOnNode(String nodeId, String command,
|
||||||
ExecResponse toReturn = context.getComputeService().runScriptOnNode(nodeId, command, options);
|
RunScriptOptions options) {
|
||||||
|
ExecResponse toReturn = context.getComputeService().runScriptOnNode(
|
||||||
|
nodeId, command, options);
|
||||||
assert toReturn.getExitCode() == 0 : toReturn;
|
assert toReturn.getExitCode() == 0 : toReturn;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
@ -446,7 +522,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
return runScriptOnNode(nodeId, command, wrapInInitScript(false));
|
return runScriptOnNode(nodeId, command, wrapInInitScript(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception {
|
private File downloadFileUnlessPresent(URI sourceURL,
|
||||||
|
String destinationDir, String filename) throws Exception {
|
||||||
|
|
||||||
File iso = new File(destinationDir, filename);
|
File iso = new File(destinationDir, filename);
|
||||||
|
|
||||||
|
@ -462,26 +539,36 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
return iso;
|
return iso;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyboardSequence(String keyboardSequence) throws InterruptedException {
|
private void sendKeyboardSequence(String keyboardSequence)
|
||||||
|
throws InterruptedException {
|
||||||
String[] sequenceSplited = keyboardSequence.split(" ");
|
String[] sequenceSplited = keyboardSequence.split(" ");
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String word : sequenceSplited) {
|
for (String word : sequenceSplited) {
|
||||||
String converted = stringToKeycode(word);
|
String converted = stringToKeycode(word);
|
||||||
for (String string : converted.split(" ")) {
|
for (String string : converted.split(" ")) {
|
||||||
|
sb.append("vboxmanage controlvm " + vmName
|
||||||
runScriptOnNode(hostId, "VBoxManage controlvm " + vmName + " keyboardputscancode " + string);
|
+ " keyboardputscancode " + string + "; ");
|
||||||
if (converted.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Return>")))
|
if (string
|
||||||
Thread.sleep(180);
|
.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get("<Return>"))) {
|
||||||
|
runScriptOnNode(hostId, sb.toString(), runAsRoot(false)
|
||||||
|
.wrapInInitScript(false));
|
||||||
|
sb = new StringBuilder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
runScriptOnNode(hostId, sb.toString(), runAsRoot(false)
|
||||||
|
.wrapInInitScript(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String stringToKeycode(String s) {
|
private String stringToKeycode(String s) {
|
||||||
|
|
||||||
StringBuilder keycodes = new StringBuilder();
|
StringBuilder keycodes = new StringBuilder();
|
||||||
for (String specialButton : KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.keySet()) {
|
for (String specialButton : KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.keySet()) {
|
||||||
if (s.startsWith(specialButton)) {
|
if (s.startsWith(specialButton)) {
|
||||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get(specialButton));
|
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get(specialButton));
|
||||||
return keycodes.toString();
|
return keycodes.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,11 +576,15 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < s.length()) {
|
while (i < s.length()) {
|
||||||
String digit = s.substring(i, i + 1);
|
String digit = s.substring(i, i + 1);
|
||||||
String hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP.get(digit);
|
String hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get(digit);
|
||||||
keycodes.append(hex + " ");
|
keycodes.append(hex + " ");
|
||||||
|
if (i != 0 && i % 14 == 0)
|
||||||
|
keycodes.append(" ");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Spacebar>") + " ");
|
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get("<Spacebar>") + " ");
|
||||||
|
|
||||||
return keycodes.toString();
|
return keycodes.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue