mirror of https://github.com/apache/jclouds.git
adding virtualbox issue 384 - fix hd creation
This commit is contained in:
parent
dc070417a9
commit
280c8205f0
|
@ -30,6 +30,7 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
import org.jclouds.predicates.SocketOpen;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
|
@ -60,7 +61,6 @@ import com.google.common.io.InputSupplier;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
|
||||||
@Test(groups = "live", testName = "virtualbox.VirtualboxAdministrationKickstartTest")
|
@Test(groups = "live", testName = "virtualbox.VirtualboxAdministrationKickstartTest")
|
||||||
public class VirtualboxAdministrationKickstartTest {
|
public class VirtualboxAdministrationKickstartTest {
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
protected String settingsFile; // Fully qualified path where the settings
|
protected String settingsFile; // Fully qualified path where the settings
|
||||||
protected String osTypeId; // Guest OS Type ID.
|
protected String osTypeId; // Guest OS Type ID.
|
||||||
protected String vmId; // Machine UUID (optional).
|
protected String vmId; // Machine UUID (optional).
|
||||||
protected boolean forceOverwrite;
|
protected boolean forceOverwrite;
|
||||||
protected String diskFormat;
|
protected String diskFormat;
|
||||||
|
|
||||||
protected String workingDir;
|
protected String workingDir;
|
||||||
|
@ -104,7 +104,6 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
private String preseedUrl;
|
private String preseedUrl;
|
||||||
|
|
||||||
protected Server server = null;
|
protected Server server = null;
|
||||||
private InetSocketAddress testPort;
|
|
||||||
private String vboxManageCommand;
|
private String vboxManageCommand;
|
||||||
private String sshHost;
|
private String sshHost;
|
||||||
private String sshPort;
|
private String sshPort;
|
||||||
|
@ -112,63 +111,41 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
private String sshPass;
|
private String sshPass;
|
||||||
private String sshKeyFile;
|
private String sshKeyFile;
|
||||||
|
|
||||||
|
|
||||||
protected void setupCredentials() {
|
protected void setupCredentials() {
|
||||||
identity = System.getProperty("test." + provider + ".identity",
|
identity = System.getProperty("test." + provider + ".identity", "administrator");
|
||||||
"administrator");
|
credential = System.getProperty("test." + provider + ".credential", "12345");
|
||||||
credential = System.getProperty("test." + provider + ".credential",
|
endpoint = System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/");
|
||||||
"12345");
|
|
||||||
endpoint = System.getProperty("test." + provider + ".endpoint",
|
|
||||||
"http://localhost:18083/");
|
|
||||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setupConfigurationProperties() {
|
protected void setupConfigurationProperties() {
|
||||||
|
|
||||||
sshHost = System.getProperty("test.ssh.host", "localhost");
|
|
||||||
sshPort = System.getProperty("test.ssh.port", "22");
|
|
||||||
sshUser = System.getProperty("test.ssh.username", "toor");
|
|
||||||
sshPass = System.getProperty("test.ssh.password", "password");
|
|
||||||
sshKeyFile = System.getProperty("test.ssh.keyfile");
|
|
||||||
|
|
||||||
|
sshHost = System.getProperty("test.ssh.host", "localhost");
|
||||||
|
sshPort = System.getProperty("test.ssh.port", "22");
|
||||||
|
sshUser = System.getProperty("test.ssh.username", "toor");
|
||||||
|
sshPass = System.getProperty("test.ssh.password", "password");
|
||||||
|
sshKeyFile = System.getProperty("test.ssh.keyfile");
|
||||||
|
|
||||||
admin_pwd = System.getProperty("test." + provider + ".admin_pwd",
|
admin_pwd = System.getProperty("test." + provider + ".admin_pwd", "password");
|
||||||
"password");
|
|
||||||
|
|
||||||
controllerIDE = System.getProperty("test." + provider
|
controllerIDE = System.getProperty("test." + provider + ".controllerIde", "IDE Controller");
|
||||||
+ ".controllerIde", "IDE Controller");
|
controllerSATA = System.getProperty("test." + provider + ".controllerSata", "SATA Controller");
|
||||||
controllerSATA = System.getProperty("test." + provider
|
|
||||||
+ ".controllerSata", "SATA Controller");
|
|
||||||
// Create disk If the @a format attribute is empty or null then the
|
|
||||||
// default storage format specified by
|
|
||||||
// ISystemProperties#defaultHardDiskFormat
|
|
||||||
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
||||||
|
|
||||||
// VBOX
|
// VBOX
|
||||||
settingsFile = null; // Fully qualified path where the settings file
|
settingsFile = null;
|
||||||
osTypeId = System.getProperty("test." + provider + ".osTypeId", ""); // Guest
|
osTypeId = System.getProperty("test." + provider + ".osTypeId", "");
|
||||||
// OS
|
vmId = System.getProperty("test." + provider + ".vmId", null);
|
||||||
// Type
|
forceOverwrite = true;
|
||||||
// ID.
|
vmName = System.getProperty("test." + provider + ".vmname", "jclouds-virtualbox-kickstart-admin");
|
||||||
vmId = System.getProperty("test." + provider + ".vmId", null); // Machine
|
|
||||||
// UUID
|
|
||||||
// (optional).
|
|
||||||
forceOverwrite = true; // If true, an existing machine settings file
|
|
||||||
// will be overwritten.
|
|
||||||
vmName = System.getProperty("test." + provider + ".vmname",
|
|
||||||
"jclouds-virtualbox-kickstart-admin");
|
|
||||||
|
|
||||||
workingDir = System.getProperty("user.home")
|
workingDir = System.getProperty("user.home")
|
||||||
+ File.separator
|
+ File.separator + System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
||||||
+ System.getProperty("test." + provider + ".workingDir",
|
if (new File(workingDir).mkdir())
|
||||||
"jclouds-virtualbox-test");
|
;
|
||||||
if (new File(workingDir).mkdir());
|
vdiName = System.getProperty("test." + provider + ".vdiName", "centos-5.2-x86.7z");
|
||||||
vdiName = System.getProperty("test." + provider + ".vdiName",
|
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||||
"centos-5.2-x86.7z");
|
gaIsoUrl = System.getProperty("test." + provider + ".gaIsoUrl", "http://download.virtualbox.org/virtualbox/4.0.2/VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName",
|
|
||||||
"VBoxGuestAdditions_4.0.2-update-69551.iso");
|
|
||||||
gaIsoUrl = System.getProperty("test." + provider + ".gaIsoUrl",
|
|
||||||
"http://download.virtualbox.org/virtualbox/4.0.2/VBoxGuestAdditions_4.0.2-update-69551.iso");
|
|
||||||
|
|
||||||
distroIsoName = System.getProperty("test." + provider
|
distroIsoName = System.getProperty("test." + provider
|
||||||
+ ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
+ ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
||||||
|
@ -176,48 +153,37 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
.getProperty("test." + provider + ".distroIsoUrl",
|
.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");
|
||||||
|
|
||||||
installVboxOse = System.getProperty("test." + provider + ".installvboxose", "sudo -S apt-get --yes install virtualbox-ose");
|
installVboxOse = System.getProperty("test." + provider
|
||||||
|
+ ".installvboxose",
|
||||||
|
"sudo -S apt-get --yes install virtualbox-ose");
|
||||||
|
|
||||||
originalDisk = workingDir
|
originalDisk = workingDir + File.separator + "VDI" + File.separator + System.getProperty("test." + provider + ".originalDisk",
|
||||||
+ File.separator
|
|
||||||
+ "VDI"
|
|
||||||
+ File.separator
|
|
||||||
+ System.getProperty("test." + provider + ".originalDisk",
|
|
||||||
"centos-5.2-x86.vdi");
|
"centos-5.2-x86.vdi");
|
||||||
clonedDisk = workingDir
|
clonedDisk = workingDir + File.separator + System.getProperty("test." + provider + ".clonedDisk",
|
||||||
+ File.separator
|
|
||||||
+ System.getProperty("test." + provider + ".clonedDisk",
|
|
||||||
"template.vdi");
|
"template.vdi");
|
||||||
guestAdditionsDvd = workingDir
|
guestAdditionsDvd = workingDir + File.separator + System.getProperty("test." + provider + ".guestAdditionsDvd",
|
||||||
+ File.separator
|
|
||||||
+ System.getProperty("test." + provider + ".guestAdditionsDvd",
|
|
||||||
"VBoxGuestAdditions_4.0.2-update-69551.iso");
|
"VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||||
|
|
||||||
distroDvd = workingDir
|
distroDvd = workingDir + File.separator + System.getProperty("test." + provider + ".distroDvd",
|
||||||
+ File.separator
|
|
||||||
+ System.getProperty("test." + provider + ".distroDvd",
|
|
||||||
distroIsoName);
|
distroIsoName);
|
||||||
|
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
|
||||||
|
"http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||||
|
|
||||||
preseedUrl = System
|
keyboardSequence = System.getProperty("test." + provider + ".keyboardSequence",
|
||||||
.getProperty(
|
|
||||||
"test." + provider + ".preseedurl", "http://dl.dropbox.com/u/693111/preseed.cfg");
|
|
||||||
keyboardSequence = System
|
|
||||||
.getProperty(
|
|
||||||
"test." + provider + ".keyboardSequence",
|
|
||||||
"<Esc> <Esc> <Enter> "
|
"<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 "
|
||||||
//+ "/install/vmlinuz noapic preseed/url=" + preseedUrl + " "
|
|
||||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||||
+ "hostname=" + vmName + " "
|
+ "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>");
|
||||||
|
|
||||||
vboxwebsrvStartCommand = System.getProperty("test." + provider
|
vboxwebsrvStartCommand = System.getProperty("test." + provider
|
||||||
+ ".vboxwebsrvStartCommand", "/usr/bin/vboxwebsrv");
|
+ ".vboxwebsrvStartCommand", "/usr/bin/vboxwebsrv");
|
||||||
vboxManageCommand = System
|
vboxManageCommand = System.getProperty("test." + provider
|
||||||
.getProperty(
|
+ ".vboxmanage", "VBoxManage");
|
||||||
"test." + provider + ".vboxmanage", "VBoxManage");
|
|
||||||
if (!new File(distroDvd).exists()) {
|
if (!new File(distroDvd).exists()) {
|
||||||
try {
|
try {
|
||||||
downloadFile(distroIsoUrl, workingDir, distroIsoName, null);
|
downloadFile(distroIsoUrl, workingDir, distroIsoName, null);
|
||||||
|
@ -241,7 +207,9 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
new Log4JLoggingModule());
|
new Log4JLoggingModule());
|
||||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||||
socketTester = new RetryablePredicate<IPSocket>(
|
socketTester = new RetryablePredicate<IPSocket>(
|
||||||
new InetSocketAddressConnect(), 3600, 1, TimeUnit.SECONDS);
|
injector.getInstance(SocketOpen.class), 130, 10,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
|
||||||
injector.injectMembers(socketTester);
|
injector.injectMembers(socketTester);
|
||||||
|
|
||||||
setupCredentials();
|
setupCredentials();
|
||||||
|
@ -250,8 +218,8 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
installVbox();
|
installVbox();
|
||||||
// startup vbox web server
|
// startup vbox web server
|
||||||
startupVboxWebServer(vboxwebsrvStartCommand);
|
startupVboxWebServer(vboxwebsrvStartCommand);
|
||||||
|
|
||||||
// configure jetty HTTP server
|
// configure and startup jetty HTTP server
|
||||||
try {
|
try {
|
||||||
configureJettyServer();
|
configureJettyServer();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -264,17 +232,18 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
|
|
||||||
ResourceHandler resource_handler = new ResourceHandler();
|
ResourceHandler resource_handler = new ResourceHandler();
|
||||||
resource_handler.setDirectoriesListed(true);
|
resource_handler.setDirectoriesListed(true);
|
||||||
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
|
resource_handler.setWelcomeFiles(new String[] { "index.html" });
|
||||||
|
|
||||||
resource_handler.setResourceBase(".");
|
resource_handler.setResourceBase(".");
|
||||||
Log.info("serving " + resource_handler.getBaseResource());
|
Log.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();
|
||||||
//server.join();
|
// server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installVbox() throws IOException, InterruptedException {
|
private void installVbox() throws IOException, InterruptedException {
|
||||||
|
@ -282,12 +251,13 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
try {
|
try {
|
||||||
client.exec("echo " + sshPass + " | " + installVboxOse);
|
client.exec("echo " + sshPass + " | " + installVboxOse);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("It is impossible to install virtualbox with this command " + installVboxOse);
|
System.out
|
||||||
|
.println("It is impossible to install virtualbox with this command "
|
||||||
|
+ installVboxOse);
|
||||||
} finally {
|
} finally {
|
||||||
if (client != null)
|
if (client != null)
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -313,22 +283,6 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private SshClient setupSshClient() throws FileNotFoundException, IOException {
|
|
||||||
int port = Integer.parseInt(sshPort);
|
|
||||||
Injector i = Guice.createInjector(new SshjSshClientModule());
|
|
||||||
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
|
|
||||||
SshClient connection;
|
|
||||||
if (sshKeyFile != null && !sshKeyFile.trim().equals("")) {
|
|
||||||
connection = factory.create(new IPSocket(sshHost, port),
|
|
||||||
new Credentials(sshUser, Strings2.toStringAndClose(new FileInputStream(sshKeyFile))));
|
|
||||||
} else {
|
|
||||||
connection = factory.create(new IPSocket(sshHost, port), new Credentials(sshUser, sshPass));
|
|
||||||
}
|
|
||||||
connection.connect();
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
protected void setupManager() {
|
protected void setupManager() {
|
||||||
manager.connect(endpoint, identity, credential);
|
manager.connect(endpoint, identity, credential);
|
||||||
|
@ -363,34 +317,6 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testChangeRAM")
|
@Test(dependsOnMethods = "testChangeRAM")
|
||||||
public void testCreateIDEController() {
|
|
||||||
ISession session = manager.getSessionObject();
|
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
|
||||||
machine.lockMachine(session, LockType.Write);
|
|
||||||
IMachine mutable = session.getMachine();
|
|
||||||
mutable.addStorageController(controllerIDE, StorageBus.IDE);
|
|
||||||
mutable.saveSettings();
|
|
||||||
session.unlockMachine();
|
|
||||||
assertEquals(manager.getVBox().findMachine(vmName)
|
|
||||||
.getStorageControllers().size(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateIDEController")
|
|
||||||
public void testAttachIsoDvd() {
|
|
||||||
IMedium distroHD = manager.getVBox().openMedium(distroDvd,
|
|
||||||
DeviceType.DVD, AccessMode.ReadOnly);
|
|
||||||
|
|
||||||
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, distroHD);
|
|
||||||
mutable.saveSettings(); // write settings to xml
|
|
||||||
session.unlockMachine();
|
|
||||||
assertEquals(distroHD.getId().equals(""), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testAttachIsoDvd")
|
|
||||||
public void testCreateScsiController() {
|
public void testCreateScsiController() {
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
|
@ -405,23 +331,15 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateScsiController")
|
@Test(dependsOnMethods = "testCreateScsiController")
|
||||||
public void testCreateAndAttachHardDisk() {
|
public void testCreateAndAttachHardDisk() {
|
||||||
/*
|
|
||||||
* IMedium IVirtualBox::createHardDisk(String format, String location)
|
|
||||||
* If the format attribute is empty or null then the default
|
|
||||||
* storage format speciï¬<EFBFBD>ed by ISystemProperties::defaultHardDiskFormat will be used for creating
|
|
||||||
* a storage unit of the medium.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
IMedium hd = manager.getVBox().createHardDisk(null, workingDir + File.separator + "disk.vdi");
|
|
||||||
IProgress progress = hd.createBaseStorage(new Long(8*1024), new Long(MediumVariant.STANDARD.ordinal()));
|
|
||||||
*/
|
|
||||||
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 = 120*1024*1024;
|
long size = 2 * 1024 * 1024 * 1024 - 1;
|
||||||
hd.createBaseStorage(new Long(size), new Long(MediumVariant.FIXED.ordinal()));
|
hd.createBaseStorage(new Long(size), new Long(
|
||||||
|
MediumVariant.VMDK_SPLIT_2_G.ordinal()));
|
||||||
} else
|
} else
|
||||||
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk, AccessMode.ReadWrite);
|
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk,
|
||||||
|
AccessMode.ReadWrite);
|
||||||
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);
|
||||||
|
@ -432,59 +350,52 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
assertEquals(hd.getId().equals(""), false);
|
assertEquals(hd.getId().equals(""), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testCreateAndAttachHardDisk")
|
||||||
@Test(dependsOnMethods = "testCreateAndAttachHardDisk")
|
public void testConfigureNIC() {
|
||||||
public void testConfigureNIC() {
|
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();
|
|
||||||
|
|
||||||
|
|
||||||
// network BRIDGED to access HTTP server
|
// network BRIDGED to access HTTP server
|
||||||
String hostInterface = null;
|
String hostInterface = null;
|
||||||
String command = vboxManageCommand + " list bridgedifs";
|
String command = vboxManageCommand + " list bridgedifs";
|
||||||
try {
|
try {
|
||||||
Process child = Runtime.getRuntime().exec(command);
|
Process child = Runtime.getRuntime().exec(command);
|
||||||
BufferedReader bufferedReader = new BufferedReader(
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
new InputStreamReader(child.getInputStream()));
|
new InputStreamReader(child.getInputStream()));
|
||||||
String line = "";
|
String line = "";
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
while ( (line = bufferedReader.readLine()) != null && !found){
|
while ((line = bufferedReader.readLine()) != null && !found) {
|
||||||
|
|
||||||
if(line.split(":")[0].contains("Name") ){
|
if (line.split(":")[0].contains("Name")) {
|
||||||
hostInterface = line.split(":")[1];
|
hostInterface = line.split(":")[1];
|
||||||
}
|
}
|
||||||
if( line.split(":")[0].contains("Status") && line.split(":")[1].contains("Up") ){
|
if (line.split(":")[0].contains("Status")
|
||||||
|
&& line.split(":")[1].contains("Up")) {
|
||||||
System.out.println("bridge: " + hostInterface.trim());
|
System.out.println("bridge: " + hostInterface.trim());
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bridged
|
// NAT
|
||||||
/*
|
|
||||||
mutable.getNetworkAdapter(new Long(0)).attachToBridgedInterface();
|
|
||||||
mutable.getNetworkAdapter(new Long(0)).setHostInterface(hostInterface.trim());
|
|
||||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// NAT
|
|
||||||
mutable.getNetworkAdapter(new Long(0)).attachToNAT();
|
mutable.getNetworkAdapter(new Long(0)).attachToNAT();
|
||||||
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
|
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
|
||||||
machine.getNetworkAdapter(new Long(0)).getNatDriver().addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222, "", 22);
|
machine.getNetworkAdapter(new Long(0))
|
||||||
|
.getNatDriver()
|
||||||
|
.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) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
propagate(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testConfigureNIC")
|
@Test(dependsOnMethods = "testConfigureNIC")
|
||||||
public void testStartVirtualMachine() {
|
public void testStartVirtualMachine() {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
|
@ -494,20 +405,26 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
propagate(e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendKeyboardSequence(keyboardSequence);
|
sendKeyboardSequence(keyboardSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testStartVirtualMachine")
|
@Test(dependsOnMethods = "testStartVirtualMachine")
|
||||||
public void testConfigureGuestAdditions() throws FileNotFoundException, IOException {
|
public void testConfigureGuestAdditions() throws FileNotFoundException,
|
||||||
|
IOException {
|
||||||
|
IPSocket socket = new IPSocket(sshHost, 2222);
|
||||||
|
|
||||||
|
System.out.printf("%d: %s awaiting ssh service to start%n",
|
||||||
|
System.currentTimeMillis(), socket);
|
||||||
|
assert socketTester.apply(socket);
|
||||||
|
System.out.printf("%d: %s ssh service started%n",
|
||||||
|
System.currentTimeMillis(), socket);
|
||||||
// configure GA
|
// configure GA
|
||||||
SshClient client = setupSshClient();
|
SshClient client = setupSshClient();
|
||||||
try {
|
try {
|
||||||
//Configure your system for building kernel modules by running
|
// Configure your system for building kernel modules by running
|
||||||
ExecResponse exec = client.exec("echo " + sshPass + " | " + "sudo -S m-a prepare -i");
|
ExecResponse exec = client.exec("echo " + sshPass + " | " + "sudo -S m-a prepare -i");
|
||||||
System.out.println(exec);
|
System.out.println(exec);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -517,8 +434,8 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ExecResponse exec = client
|
ExecResponse exec = client.exec("echo " + sshPass + " | "
|
||||||
.exec("echo " + sshPass + " | " + "sudo -S mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
|
+ "sudo -S mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
|
||||||
System.out.println(exec);
|
System.out.println(exec);
|
||||||
exec = client.exec("echo " + sshPass + " | " + "sudo -S sh /mnt/VBoxLinuxAdditions.run");
|
exec = client.exec("echo " + sshPass + " | " + "sudo -S sh /mnt/VBoxLinuxAdditions.run");
|
||||||
System.out.println(exec);
|
System.out.println(exec);
|
||||||
|
@ -547,8 +464,7 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
|
|
||||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
||||||
try {
|
try {
|
||||||
System.out
|
System.out.println("waiting for unlocking session - session state: "
|
||||||
.println("waiting for unlocking session - session state: "
|
|
||||||
+ machine.getSessionState());
|
+ machine.getSessionState());
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -559,7 +475,6 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testStopVirtualMachine")
|
@Test(dependsOnMethods = "testStopVirtualMachine")
|
||||||
|
@ -640,7 +555,7 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
}
|
}
|
||||||
return iso;
|
return iso;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyboardSequence(String keyboardSequence) {
|
private void sendKeyboardSequence(String keyboardSequence) {
|
||||||
String[] sequenceSplited = keyboardSequence.split(" ");
|
String[] sequenceSplited = keyboardSequence.split(" ");
|
||||||
SshClient client = null;
|
SshClient client = null;
|
||||||
|
@ -649,8 +564,15 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
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(" ")) {
|
||||||
ExecResponse response = client.exec(vboxManageCommand + " controlvm " + vmName + " keyboardputscancode " + string);
|
|
||||||
|
ExecResponse response = client.exec(vboxManageCommand
|
||||||
|
+ " controlvm " + vmName + " keyboardputscancode "
|
||||||
|
+ string);
|
||||||
System.out.println(response.getOutput());
|
System.out.println(response.getOutput());
|
||||||
|
if (converted
|
||||||
|
.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get("<Return>")))
|
||||||
|
Thread.sleep(180);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -664,26 +586,29 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
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
|
||||||
if(s.startsWith(specialButton)) {
|
.keySet()) {
|
||||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get(specialButton));
|
if (s.startsWith(specialButton)) {
|
||||||
|
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get(specialButton));
|
||||||
return keycodes.toString();
|
return keycodes.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0, j = 0;
|
|
||||||
while(i < s.length()) {
|
|
||||||
String digit = s.substring(i, i+1);
|
|
||||||
String hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP.get(digit);
|
|
||||||
keycodes.append(hex + " ");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Spacebar>") + " ");
|
|
||||||
|
|
||||||
return keycodes.toString();
|
int i = 0;
|
||||||
|
while (i < s.length()) {
|
||||||
|
String digit = s.substring(i, i + 1);
|
||||||
|
String hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get(digit);
|
||||||
|
keycodes.append(hex + " ");
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
|
.get("<Spacebar>") + " ");
|
||||||
|
|
||||||
|
return keycodes.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param machine
|
* @param machine
|
||||||
|
@ -694,4 +619,24 @@ public class VirtualboxAdministrationKickstartTest {
|
||||||
prog.waitForCompletion(-1);
|
prog.waitForCompletion(-1);
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private SshClient setupSshClient() throws FileNotFoundException,
|
||||||
|
IOException {
|
||||||
|
int port = Integer.parseInt(sshPort);
|
||||||
|
Injector i = Guice.createInjector(new SshjSshClientModule());
|
||||||
|
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
|
||||||
|
SshClient connection;
|
||||||
|
if (sshKeyFile != null && !sshKeyFile.trim().equals("")) {
|
||||||
|
connection = factory
|
||||||
|
.create(new IPSocket(sshHost, port),
|
||||||
|
new Credentials(sshUser, Strings2
|
||||||
|
.toStringAndClose(new FileInputStream(
|
||||||
|
sshKeyFile))));
|
||||||
|
} else {
|
||||||
|
connection = factory.create(new IPSocket(sshHost, port),
|
||||||
|
new Credentials(sshUser, sshPass));
|
||||||
|
}
|
||||||
|
connection.connect();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue