issue 384: tests passed but still connection problem to guest with bridged NIC

This commit is contained in:
andreaturli 2011-09-14 23:00:04 +01:00
parent 4b62c4a022
commit 716ae1ad54
2 changed files with 170 additions and 148 deletions

View File

@ -25,10 +25,12 @@ import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScr
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;
@ -66,6 +68,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.NetworkAdapterType;
import org.virtualbox_4_1.NetworkAttachmentType;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.StorageBus;
@ -119,6 +122,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
private String minorVersion;
private URI vboxDmg;
private String vboxVersionName;
private String snapshotDescription;
protected void setupCredentials() {
identity = System.getProperty("test." + provider + ".identity",
@ -185,6 +189,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
"http://dl.dropbox.com/u/693111/preseed.cfg");
snapshotDescription = System.getProperty("test." + provider + "snapshotdescription", "jclouds-virtualbox-snaphot");
keyboardSequence = System
.getProperty(
"test." + provider + ".keyboardSequence",
@ -198,6 +204,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
+ "initrd=/install/initrd.gz -- <Enter>");
}
@BeforeGroups(groups = "live")
@ -294,7 +301,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
protected boolean isUbuntu(String id) {
return context.getComputeService().getNodeMetadata(id)
.getOperatingSystem().getDescription().equals("ubuntu/11.04");
.getOperatingSystem().getDescription().contains("ubuntu");
}
@BeforeMethod
@ -446,20 +453,18 @@ public class VirtualboxAdministrationKickstartLiveTest {
@Test(dependsOnMethods = "testStartVirtualMachine")
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
// TODO generalize
if(isUbuntu(guestId)) {
runScriptOnNode(guestId, "m-a prepare -i", wrapInInitScript(true));
runScriptOnNode(guestId,
"mount -o loop /dev/dvd /media/cdrom");
ExecResponse response = runScriptOnNode(guestId, "sh /media/cdrom/VBoxLinuxAdditions.run");
response.getExitCode();
// for Debian based OS
runScriptOnNode(guestId,
"sh /media/cdrom/VBoxLinuxAdditions.run");
runScriptOnNode(guestId, "rm /etc/udev/rules.d/70-persistent-net.rules");
//}
runScriptOnNode(guestId, "mkdir /etc/udev/rules.d/70-persistent-net.rules");
runScriptOnNode(guestId, "rm -rf /dev/.udev/");
runScriptOnNode(guestId, "rm /lib/udev/rules.d/75-persistent-net-generator.rules");
}
}
@Test(dependsOnMethods = "testConfigureGuestAdditions")
@ -469,57 +474,53 @@ public class VirtualboxAdministrationKickstartLiveTest {
assertEquals(machine.getState(), MachineState.PoweredOff);
}
/**
* @param machine
*/
private void powerDownMachine(IMachine machine) {
try {
ISession machineSession = manager.openMachineSession(machine);
IProgress progress = machineSession.getConsole().powerDown();
progress.waitForCompletion(-1);
machineSession.unlockMachine();
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
try {
System.out
.println("waiting for unlocking session - session state: "
+ machine.getSessionState());
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
@Test(dependsOnMethods = "testStopVirtualMachine")
public void cleanUp() throws IOException {
public void testChangeNICtoBridged() {
ISession session = manager.getSessionObject();
IMachine machine = manager.getVBox().findMachine(vmName);
machine.lockMachine(session, LockType.Write);
IMachine adminNode = manager.getVBox().findMachine(vmName);
adminNode.lockMachine(session, LockType.Write);
IMachine mutable = session.getMachine();
mutable.getNetworkAdapter(new Long(0)).getNatDriver()
.removeRedirect("guestssh");
// detach disk from controller
mutable.detachDevice(controllerIDE, 0, 0);
mutable.saveSettings();
session.unlockMachine();
// network
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;
for (IStorageController storageController : machine
.getStorageControllers()) {
if (storageController.getName().equals(controllerSATA)) {
session = manager.getSessionObject();
machine.lockMachine(session, LockType.Write);
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;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mutable = session.getMachine();
mutable.detachDevice(storageController.getName(), 1, 1);
mutable.getNetworkAdapter(new Long(0)).setAttachmentType(NetworkAttachmentType.Bridged);
mutable.getNetworkAdapter(new Long(0)).setAdapterType(NetworkAdapterType.Am79C973);
mutable.getNetworkAdapter(new Long(0)).setMACAddress(manager.getVBox().getHost().generateMACAddress());
mutable.getNetworkAdapter(new Long(0)).setBridgedInterface(hostInterface.trim());
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
mutable.saveSettings();
session.unlockMachine();
}
@Test(dependsOnMethods = "testChangeNICtoBridged")
public void testTakeAdminNodeSnapshot() {
ISession session = manager.getSessionObject();
IMachine adminNode = manager.getVBox().findMachine(vmName);
adminNode.lockMachine(session, LockType.Write);
if(adminNode.getCurrentSnapshot() == null || !adminNode.getCurrentSnapshot().getDescription().equals(snapshotDescription)) {
manager.getSessionObject().getConsole().takeSnapshot(adminNode.getId(), snapshotDescription);
}
session.unlockMachine();
}
@AfterClass
@ -621,4 +622,31 @@ public class VirtualboxAdministrationKickstartLiveTest {
prog.waitForCompletion(-1);
session.unlockMachine();
}
/**
* @param machine
*/
private void powerDownMachine(IMachine machine) {
try {
ISession machineSession = manager.openMachineSession(machine);
IProgress progress = machineSession.getConsole().powerDown();
progress.waitForCompletion(-1);
machineSession.unlockMachine();
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
try {
System.out
.println("waiting for unlocking session - session state: "
+ machine.getSessionState());
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
}

View File

@ -23,7 +23,10 @@ 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 java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.rmi.RemoteException;
@ -47,11 +50,12 @@ import org.testng.annotations.Test;
import org.virtualbox_4_1.CloneMode;
import org.virtualbox_4_1.CloneOptions;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.NetworkAdapterType;
import org.virtualbox_4_1.NetworkAttachmentType;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.VirtualBoxManager;
@ -143,7 +147,6 @@ public class VirtualboxLiveTest {
clonedDisk = System.getProperty("test." + provider + ".clonedDisk", "clone.vdi");
clonedDiskPath = workingDir + File.separator + clonedDisk;
snapshotDescription = System.getProperty("test." + provider + "snapshotdescription", "jclouds-virtualbox-snaphot");
numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider
+ ".numberOfVirtualMachine", "3")));
}
@ -172,16 +175,6 @@ public class VirtualboxLiveTest {
}
@Test
public void testTakeAdminNodeSnapshot() {
ISession session = manager.getSessionObject();
IMachine adminNode = manager.getVBox().findMachine(adminNodeName);
adminNode.lockMachine(session, LockType.Write);
if(adminNode.getCurrentSnapshot() == null || !adminNode.getCurrentSnapshot().getDescription().equals(snapshotDescription)) {
manager.getSessionObject().getConsole().takeSnapshot(adminNode.getId(), snapshotDescription);
}
}
@Test(dependsOnMethods = "testTakeAdminNodeSnapshot")
public void testStartAndValidateVirtualMachines() throws InterruptedException {
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
createAndLaunchVirtualMachine(i);
@ -189,9 +182,9 @@ public class VirtualboxLiveTest {
}
private void createAndLaunchVirtualMachine(int i) throws InterruptedException {
String instanceName = vmName + "_" + i;
IMachine adminNode = manager.getVBox().findMachine(adminNodeName);
IMachine clonedVM = manager.getVBox().createMachine(settingsFile, instanceName, osTypeId, vmId, forceOverwrite);
List<CloneOptions> options = new ArrayList<CloneOptions>();
options.add(CloneOptions.Link);
@ -201,6 +194,7 @@ public class VirtualboxLiveTest {
manager.getVBox().registerMachine(clonedVM);
System.out.println("\nLaunching VM named " + clonedVM.getName() + " ...");
launchVMProcess(clonedVM, manager.getSessionObject());
String ipAddress = null;