mirror of https://github.com/apache/jclouds.git
issue 384: kickstart admin node on macosx -> complete
This commit is contained in:
parent
6092d58046
commit
1c6c85fa51
|
@ -58,6 +58,7 @@ public class TestUtils {
|
||||||
nodes.append(" os_version: 11.04").append("\n");
|
nodes.append(" os_version: 11.04").append("\n");
|
||||||
nodes.append(" group: guest").append("\n");
|
nodes.append(" group: guest").append("\n");
|
||||||
nodes.append(" username: toor").append("\n");
|
nodes.append(" username: toor").append("\n");
|
||||||
|
nodes.append(" sudo_password: password").append("\n");
|
||||||
nodes.append(" credential: password").append("\n");
|
nodes.append(" credential: password").append("\n");
|
||||||
|
|
||||||
contextProperties.setProperty("byon.nodes", nodes.toString());
|
contextProperties.setProperty("byon.nodes", nodes.toString());
|
||||||
|
|
|
@ -41,15 +41,14 @@ import org.eclipse.jetty.server.handler.HandlerList;
|
||||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
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.scriptbuilder.domain.OsFamily;
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
|
||||||
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
||||||
|
import org.jclouds.scriptbuilder.statements.login.DefaultConfiguration;
|
||||||
import org.jclouds.ssh.SshException;
|
import org.jclouds.ssh.SshException;
|
||||||
import org.jclouds.virtualbox.experiment.settings.KeyboardScancodes;
|
import org.jclouds.virtualbox.experiment.settings.KeyboardScancodes;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
|
@ -191,8 +190,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
guestAdditionsDvd = workingDir
|
guestAdditionsDvd = workingDir
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ System.getProperty("test." + provider + ".guestAdditionsDvd",
|
+ System.getProperty("test." + provider + ".guestAdditionsDvd",
|
||||||
"VBoxGuestAdditions_" + majorVersion + "-update-"
|
"VBoxGuestAdditions_" + majorVersion + ".iso");
|
||||||
+ minorVersion + ".iso");
|
|
||||||
|
|
||||||
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
|
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
|
||||||
"http://dl.dropbox.com/u/693111/preseed.cfg");
|
"http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||||
|
@ -200,7 +198,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
keyboardSequence = System
|
keyboardSequence = System
|
||||||
.getProperty(
|
.getProperty(
|
||||||
"test." + provider + ".keyboardSequence",
|
"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 "
|
||||||
+ "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="
|
+ "hostname="
|
||||||
|
@ -295,7 +293,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
vboxwebsrv,
|
vboxwebsrv,
|
||||||
runAsRoot(false).wrapInInitScript(false)
|
runAsRoot(false).wrapInInitScript(false)
|
||||||
.blockOnPort(endpoint.getPort(), 10)
|
.blockOnPort(endpoint.getPort(), 10)
|
||||||
.blockOnComplete(false).nameTask("vboxwebsrv"));
|
.blockOnComplete(false)
|
||||||
|
.nameTask("vboxwebsrv"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isOSX(String id) {
|
protected boolean isOSX(String id) {
|
||||||
|
@ -303,6 +302,11 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
.getOperatingSystem().getDescription().equals("Mac OS X");
|
.getOperatingSystem().getDescription().equals("Mac OS X");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isUbuntu(String id) {
|
||||||
|
return context.getComputeService().getNodeMetadata(id)
|
||||||
|
.getOperatingSystem().getDescription().equals("ubuntu/11.04");
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
protected void setupManager() {
|
protected void setupManager() {
|
||||||
manager.connect(endpoint.toASCIIString(), identity, credential);
|
manager.connect(endpoint.toASCIIString(), identity, credential);
|
||||||
|
@ -373,6 +377,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
||||||
IProgress progress = hd.createBaseStorage(new Long(size), new Long(
|
IProgress progress = hd.createBaseStorage(new Long(size), new Long(
|
||||||
MediumVariant.STANDARD.ordinal()));
|
MediumVariant.STANDARD.ordinal()));
|
||||||
|
} else {
|
||||||
|
// TODO disk already exist: open it
|
||||||
}
|
}
|
||||||
|
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
|
@ -406,17 +412,22 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testConfigureNIC")
|
@Test(dependsOnMethods = "testConfigureNIC")
|
||||||
public void testConfigureVRDE() {
|
public void testAttachGuestAdditions() {
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
|
|
||||||
|
IMedium distroMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD,
|
||||||
|
AccessMode.ReadOnly, forceOverwrite);
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
mutable.getVRDEServer().setEnabled(new Boolean(true));
|
mutable.attachDevice(controllerIDE, 1, 1, DeviceType.DVD, distroMedium);
|
||||||
mutable.saveSettings(); // write settings to xml
|
mutable.saveSettings(); // write settings to xml
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
|
assertEquals(distroMedium.getId().equals(""), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testConfigureNIC")
|
|
||||||
|
@Test(dependsOnMethods = "testAttachGuestAdditions")
|
||||||
public void testStartVirtualMachine() throws InterruptedException {
|
public void testStartVirtualMachine() throws InterruptedException {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
|
@ -430,25 +441,35 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
|
|
||||||
sendKeyboardSequence(keyboardSequence);
|
sendKeyboardSequence(keyboardSequence);
|
||||||
|
|
||||||
// test if the sshd on the guest is ready
|
// test if the sshd on the guest is ready and meanwhile apply AdminAccess
|
||||||
boolean sshDeamonIsRunning = false;
|
boolean sshDeamonIsRunning = false;
|
||||||
while(!sshDeamonIsRunning) {
|
while(!sshDeamonIsRunning) {
|
||||||
try {
|
try {
|
||||||
if(runScriptOnNode(guestId, "echo ciao", runAsRoot(false).wrapInInitScript(false)).getExitCode() == 0)
|
AdminAccess.standard().init(new DefaultConfiguration()).render(OsFamily.UNIX);
|
||||||
|
if(runScriptOnNode(guestId, "id").getExitCode() == 0)
|
||||||
sshDeamonIsRunning = true;
|
sshDeamonIsRunning = true;
|
||||||
} catch(SshException e) {
|
} catch(SshException e) {
|
||||||
System.err.println("connection reset");
|
System.err.println("connection reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testStartVirtualMachine")
|
@Test(dependsOnMethods = "testStartVirtualMachine")
|
||||||
public void testConfigureGuestAdditions() {
|
public void testConfigureGuestAdditions() {
|
||||||
|
// TODO generalize: at the moment we are usign apt-get not the guestadditions.iso attached
|
||||||
|
|
||||||
|
|
||||||
|
//if(isUbuntu(guestId)) {
|
||||||
// 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", wrapInInitScript(true));
|
||||||
|
|
||||||
runScriptOnNode(guestId,
|
runScriptOnNode(guestId,
|
||||||
"mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
|
"mount -o loop /dev/dvd /media/cdrom");
|
||||||
runScriptOnNode(guestId, "/mnt/VBoxLinuxAdditions.run");
|
runScriptOnNode(guestId, "sh /media/cdrom/VBoxLinuxAdditions.run");
|
||||||
|
|
||||||
|
//runScriptOnNode(guestId, "apt-get --yes install virtualbox-ose-guest-utils");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testConfigureGuestAdditions")
|
@Test(dependsOnMethods = "testConfigureGuestAdditions")
|
||||||
|
@ -549,35 +570,46 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
String[] sequenceSplited = keyboardSequence.split(" ");
|
String[] sequenceSplited = keyboardSequence.split(" ");
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String word : sequenceSplited) {
|
for (String line : sequenceSplited) {
|
||||||
String converted = stringToKeycode(word);
|
String converted = stringToKeycode(line);
|
||||||
for (String string : converted.split(" ")) {
|
for (String word : converted.split(" ")) {
|
||||||
sb.append("vboxmanage controlvm " + vmName
|
sb.append("vboxmanage controlvm " + vmName
|
||||||
+ " keyboardputscancode " + string + "; ");
|
+ " keyboardputscancode " + word + "; ");
|
||||||
if (string
|
|
||||||
.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
if (word.endsWith(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Enter>"))) {
|
||||||
.get("<Return>"))) {
|
|
||||||
runScriptOnNode(hostId, sb.toString(), runAsRoot(false)
|
runScriptOnNode(hostId, sb.toString(), runAsRoot(false)
|
||||||
.wrapInInitScript(false));
|
.wrapInInitScript(false));
|
||||||
sb.delete(0, sb.length()-1);
|
sb.delete(0, sb.length()-1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
if (word.endsWith(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Return>"))) {
|
||||||
runScriptOnNode(hostId, sb.toString(), runAsRoot(false)
|
runScriptOnNode(hostId, sb.toString(), runAsRoot(false)
|
||||||
.wrapInInitScript(false));
|
.wrapInInitScript(false));
|
||||||
|
sb.delete(0, sb.length()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
//for (String specialButton : KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.keySet()) {
|
||||||
.keySet()) {
|
//System.out.println("specialbutton " + specialButton);
|
||||||
if (s.startsWith(specialButton)) {
|
if (s.startsWith("<")) {
|
||||||
|
String[] specials = s.split("<");
|
||||||
|
for (int i = 1; i < specials.length; i++) {
|
||||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
.get(specialButton));
|
.get("<" + specials[i]) + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("keycodes: " + keycodes);
|
||||||
return keycodes.toString();
|
return keycodes.toString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < s.length()) {
|
while (i < s.length()) {
|
||||||
|
|
Loading…
Reference in New Issue