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.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.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
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.MachineState;
|
||||
import org.virtualbox_4_1.NATProtocol;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
@ -116,10 +116,14 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
private String minorVersion;
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = System.getProperty("test." + provider + ".identity", "administrator");
|
||||
credential = System.getProperty("test." + provider + ".credential", "12345");
|
||||
endpoint = URI.create(System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/"));
|
||||
apiVersion = System.getProperty("test." + provider + ".apiversion", "4.1.2r73507");
|
||||
identity = System.getProperty("test." + provider + ".identity",
|
||||
"administrator");
|
||||
credential = System.getProperty("test." + provider + ".credential",
|
||||
"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);
|
||||
minorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 1);
|
||||
}
|
||||
|
@ -130,8 +134,10 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
|
||||
protected void setupConfigurationProperties() {
|
||||
|
||||
controllerIDE = System.getProperty("test." + provider + ".controllerIde", "IDE Controller");
|
||||
controllerSATA = System.getProperty("test." + provider + ".controllerSata", "SATA Controller");
|
||||
controllerIDE = System.getProperty("test." + provider
|
||||
+ ".controllerIde", "IDE Controller");
|
||||
controllerSATA = System.getProperty("test." + provider
|
||||
+ ".controllerSata", "SATA Controller");
|
||||
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
||||
|
||||
// VBOX
|
||||
|
@ -139,34 +145,59 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
osTypeId = System.getProperty("test." + provider + ".osTypeId", "");
|
||||
vmId = System.getProperty("test." + provider + ".vmId", null);
|
||||
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
|
||||
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
||||
workingDir = System.getProperty("user.home")
|
||||
+ File.separator
|
||||
+ System.getProperty("test." + provider + ".workingDir",
|
||||
"jclouds-virtualbox-test");
|
||||
if (new File(workingDir).mkdir())
|
||||
;
|
||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion
|
||||
+ "-update-" + minorVersion + ".iso");
|
||||
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl",
|
||||
"http://download.virtualbox.org/virtualbox/" + majorVersion + "/VBoxGuestAdditions_" + majorVersion + ".iso"));
|
||||
// gaIsoName = System.getProperty("test." + provider + ".gaIsoName",
|
||||
// "VBoxGuestAdditions_" + majorVersion + "-update-" + minorVersion +
|
||||
// ".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");
|
||||
distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl",
|
||||
distroIsoName = System.getProperty("test." + provider
|
||||
+ ".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"));
|
||||
|
||||
originalDisk = workingDir + File.separator + "VDI" + File.separator
|
||||
+ System.getProperty("test." + provider + ".originalDisk", "centos-5.2-x86.vdi");
|
||||
clonedDisk = workingDir + File.separator + System.getProperty("test." + provider + ".clonedDisk", "template.vdi");
|
||||
originalDisk = workingDir
|
||||
+ File.separator
|
||||
+ "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
|
||||
+ File.separator
|
||||
+ System.getProperty("test." + provider + ".guestAdditionsDvd", "VBoxGuestAdditions_" + majorVersion
|
||||
+ "-update-" + minorVersion + ".iso");
|
||||
+ System.getProperty("test." + provider + ".guestAdditionsDvd",
|
||||
"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 "
|
||||
+ "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 "
|
||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
||||
|
@ -176,16 +207,18 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
@BeforeGroups(groups = "live")
|
||||
protected void setupClient() throws Exception {
|
||||
context = TestUtils.computeServiceForLocalhost();
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(
|
||||
new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);
|
||||
setupCredentials();
|
||||
setupConfigurationProperties();
|
||||
downloadFileUnlessPresent(distroIsoUrl, workingDir, distroIsoName);
|
||||
downloadFileUnlessPresent(gaIsoUrl, workingDir, gaIsoName);
|
||||
|
||||
installVbox();
|
||||
checkVboxVersionExpected();
|
||||
if (!new InetSocketAddressConnect().apply(new IPSocket(endpoint.getHost(), endpoint.getPort())))
|
||||
if (!new InetSocketAddressConnect().apply(new IPSocket(endpoint
|
||||
.getHost(), endpoint.getPort())))
|
||||
startupVboxWebServer();
|
||||
|
||||
configureJettyServer();
|
||||
}
|
||||
|
||||
|
@ -200,32 +233,42 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
logger().info("serving " + resource_handler.getBaseResource());
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||
handlers.setHandlers(new Handler[] { resource_handler,
|
||||
new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
void installVbox() throws IOException, InterruptedException {
|
||||
if (runScriptOnNode(hostId, "VBoxManage -version").getExitCode() != 0) {
|
||||
void installVbox() {
|
||||
if (runScriptOnNode(hostId, "VBoxManage --version").getExitCode() != 0) {
|
||||
logger().debug("installing virtualbox");
|
||||
if (isOSX(hostId))
|
||||
;// TODO
|
||||
else
|
||||
runScriptOnNode(hostId, "apt-get --yes install virtualbox-ose");
|
||||
else {
|
||||
// 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 {
|
||||
logger().debug("checking virtualbox version");
|
||||
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
|
||||
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput()
|
||||
.trim(), apiVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 InterruptedException
|
||||
*/
|
||||
|
@ -233,19 +276,25 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
logger().debug("disabling password access");
|
||||
runScriptOnNode(hostId, "VBoxManage setproperty websrvauthlibrary null");
|
||||
logger().debug("starting vboxwebsrv");
|
||||
String vboxwebsrv = "vboxwebsrv -t 5 -v";
|
||||
String vboxwebsrv = "vboxwebsrv -t 10000 -v -b";
|
||||
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
|
||||
// -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
|
||||
runScriptOnNode(hostId, vboxwebsrv,
|
||||
blockOnPort(endpoint.getPort(), 10).blockOnComplete(false).nameTask("vboxwebsrv"));
|
||||
runScriptOnNode(
|
||||
hostId,
|
||||
vboxwebsrv,
|
||||
runAsRoot(false).wrapInInitScript(false)
|
||||
.blockOnPort(endpoint.getPort(), 10)
|
||||
.blockOnComplete(false).nameTask("vboxwebsrv"));
|
||||
}
|
||||
|
||||
protected boolean isOSX(String id) {
|
||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription()
|
||||
.equals("Mac OS X");
|
||||
return context.getComputeService().getNodeMetadata(hostId)
|
||||
.getOperatingSystem().getDescription().equals("Mac OS X");
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
|
@ -254,15 +303,27 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
}
|
||||
|
||||
@AfterMethod
|
||||
protected void disconnectAndClenaupManager() throws RemoteException, MalformedURLException {
|
||||
protected void disconnectAndClenaupManager() throws RemoteException,
|
||||
MalformedURLException {
|
||||
manager.disconnect();
|
||||
manager.cleanup();
|
||||
}
|
||||
|
||||
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);
|
||||
assertEquals(newVM.getName(), vmName);
|
||||
assertNotNull(newVM.getName());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateVirtualMachine")
|
||||
|
@ -275,36 +336,56 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
mutable.setMemorySize(memorySize);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(), memorySize);
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(),
|
||||
memorySize);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testChangeRAM")
|
||||
public void testCreateScsiController() {
|
||||
public void testCreateIdeController() {
|
||||
ISession session = manager.getSessionObject();
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
IMachine mutable = session.getMachine();
|
||||
mutable.addStorageController(controllerSATA, StorageBus.SATA);
|
||||
mutable.addStorageController(controllerIDE, StorageBus.IDE);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getStorageControllers().size(), 2);
|
||||
assertEquals(manager.getVBox().findMachine(vmName)
|
||||
.getStorageControllers().size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateScsiController")
|
||||
public void testCreateAndAttachHardDisk() {
|
||||
@Test(dependsOnMethods = "testCreateIdeController")
|
||||
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;
|
||||
if (!new File(clonedDisk).exists()) {
|
||||
hd = manager.getVBox().createHardDisk(diskFormat, clonedDisk);
|
||||
long size = 2 * 1024 * 1024 * 1024 - 1;
|
||||
hd.createBaseStorage(new Long(size), new Long(MediumVariant.VMDK_SPLIT_2_G.ordinal()));
|
||||
} else
|
||||
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk, AccessMode.ReadWrite, forceOverwrite);
|
||||
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
||||
IProgress progress = hd.createBaseStorage(new Long(size), new Long(
|
||||
MediumVariant.STANDARD.ordinal()));
|
||||
progress.wait();
|
||||
}
|
||||
|
||||
ISession session = manager.getSessionObject();
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
IMachine mutable = session.getMachine();
|
||||
mutable.attachDevice(controllerSATA, 0, 0, DeviceType.HardDisk, hd);
|
||||
mutable.saveSettings(); // write settings to xml
|
||||
mutable.attachDevice(controllerIDE, 0, 1, DeviceType.HardDisk, hd);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(hd.getId().equals(""), false);
|
||||
}
|
||||
|
@ -316,40 +397,28 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
machine.lockMachine(session, LockType.Write);
|
||||
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
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); TODO: this no
|
||||
// longer exists!
|
||||
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
|
||||
machine.getNetworkAdapter(new Long(0)).getNatDriver()
|
||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222, "", 22);
|
||||
mutable.getNetworkAdapter(new Long(0)).setAttachmentType(
|
||||
NetworkAttachmentType.NAT);
|
||||
machine.getNetworkAdapter(new Long(0))
|
||||
.getNatDriver()
|
||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222,
|
||||
"", 22);
|
||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
||||
|
||||
mutable.saveSettings();
|
||||
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")
|
||||
|
@ -371,7 +440,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
public void testConfigureGuestAdditions() {
|
||||
// Configure your system for building kernel modules by running
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -394,7 +464,9 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
|
||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
||||
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);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -412,13 +484,15 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
IMachine mutable = session.getMachine();
|
||||
mutable.getNetworkAdapter(new Long(0)).getNatDriver().removeRedirect("guestssh");
|
||||
mutable.getNetworkAdapter(new Long(0)).getNatDriver()
|
||||
.removeRedirect("guestssh");
|
||||
// detach disk from controller
|
||||
mutable.detachDevice(controllerIDE, 0, 0);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
||||
for (IStorageController storageController : machine.getStorageControllers()) {
|
||||
for (IStorageController storageController : machine
|
||||
.getStorageControllers()) {
|
||||
if (storageController.getName().equals(controllerSATA)) {
|
||||
session = manager.getSessionObject();
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
|
@ -436,8 +510,10 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
runScriptOnNode(guestId, "pidof vboxwebsrv | xargs kill");
|
||||
}
|
||||
|
||||
protected ExecResponse runScriptOnNode(String nodeId, String command, RunScriptOptions options) {
|
||||
ExecResponse toReturn = context.getComputeService().runScriptOnNode(nodeId, command, options);
|
||||
protected ExecResponse runScriptOnNode(String nodeId, String command,
|
||||
RunScriptOptions options) {
|
||||
ExecResponse toReturn = context.getComputeService().runScriptOnNode(
|
||||
nodeId, command, options);
|
||||
assert toReturn.getExitCode() == 0 : toReturn;
|
||||
return toReturn;
|
||||
}
|
||||
|
@ -446,7 +522,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
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);
|
||||
|
||||
|
@ -462,26 +539,36 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
return iso;
|
||||
}
|
||||
|
||||
private void sendKeyboardSequence(String keyboardSequence) throws InterruptedException {
|
||||
private void sendKeyboardSequence(String keyboardSequence)
|
||||
throws InterruptedException {
|
||||
String[] sequenceSplited = keyboardSequence.split(" ");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String word : sequenceSplited) {
|
||||
String converted = stringToKeycode(word);
|
||||
for (String string : converted.split(" ")) {
|
||||
|
||||
runScriptOnNode(hostId, "VBoxManage controlvm " + vmName + " keyboardputscancode " + string);
|
||||
if (converted.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Return>")))
|
||||
Thread.sleep(180);
|
||||
sb.append("vboxmanage controlvm " + vmName
|
||||
+ " keyboardputscancode " + string + "; ");
|
||||
if (string
|
||||
.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) {
|
||||
|
||||
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)) {
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get(specialButton));
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||
.get(specialButton));
|
||||
return keycodes.toString();
|
||||
}
|
||||
}
|
||||
|
@ -489,11 +576,15 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
int i = 0;
|
||||
while (i < s.length()) {
|
||||
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 + " ");
|
||||
if (i != 0 && i % 14 == 0)
|
||||
keycodes.append(" ");
|
||||
i++;
|
||||
}
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Spacebar>") + " ");
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||
.get("<Spacebar>") + " ");
|
||||
|
||||
return keycodes.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue