mirror of https://github.com/apache/jclouds.git
issue 384: tests passed but still connection problem to guest with bridged NIC
This commit is contained in:
parent
4b62c4a022
commit
716ae1ad54
|
@ -25,10 +25,12 @@ import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScr
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
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;
|
||||||
|
@ -66,6 +68,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.NetworkAdapterType;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
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;
|
||||||
|
@ -119,6 +122,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
private String minorVersion;
|
private String minorVersion;
|
||||||
private URI vboxDmg;
|
private URI vboxDmg;
|
||||||
private String vboxVersionName;
|
private String vboxVersionName;
|
||||||
|
private String snapshotDescription;
|
||||||
|
|
||||||
protected void setupCredentials() {
|
protected void setupCredentials() {
|
||||||
identity = System.getProperty("test." + provider + ".identity",
|
identity = System.getProperty("test." + provider + ".identity",
|
||||||
|
@ -185,6 +189,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
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");
|
||||||
|
|
||||||
|
snapshotDescription = System.getProperty("test." + provider + "snapshotdescription", "jclouds-virtualbox-snaphot");
|
||||||
|
|
||||||
keyboardSequence = System
|
keyboardSequence = System
|
||||||
.getProperty(
|
.getProperty(
|
||||||
"test." + provider + ".keyboardSequence",
|
"test." + provider + ".keyboardSequence",
|
||||||
|
@ -198,6 +204,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
+ "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>");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeGroups(groups = "live")
|
@BeforeGroups(groups = "live")
|
||||||
|
@ -294,7 +301,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
|
|
||||||
protected boolean isUbuntu(String id) {
|
protected boolean isUbuntu(String id) {
|
||||||
return context.getComputeService().getNodeMetadata(id)
|
return context.getComputeService().getNodeMetadata(id)
|
||||||
.getOperatingSystem().getDescription().equals("ubuntu/11.04");
|
.getOperatingSystem().getDescription().contains("ubuntu");
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
|
@ -446,20 +453,18 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
|
|
||||||
@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
|
// TODO generalize
|
||||||
//if(isUbuntu(guestId)) {
|
if(isUbuntu(guestId)) {
|
||||||
// Configure your system for building kernel modules by running
|
|
||||||
runScriptOnNode(guestId, "m-a prepare -i", wrapInInitScript(true));
|
runScriptOnNode(guestId, "m-a prepare -i", wrapInInitScript(true));
|
||||||
|
|
||||||
runScriptOnNode(guestId,
|
runScriptOnNode(guestId,
|
||||||
"mount -o loop /dev/dvd /media/cdrom");
|
"mount -o loop /dev/dvd /media/cdrom");
|
||||||
ExecResponse response = runScriptOnNode(guestId, "sh /media/cdrom/VBoxLinuxAdditions.run");
|
runScriptOnNode(guestId,
|
||||||
response.getExitCode();
|
"sh /media/cdrom/VBoxLinuxAdditions.run");
|
||||||
// for Debian based OS
|
|
||||||
runScriptOnNode(guestId, "rm /etc/udev/rules.d/70-persistent-net.rules");
|
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")
|
@Test(dependsOnMethods = "testConfigureGuestAdditions")
|
||||||
|
@ -469,57 +474,53 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
assertEquals(machine.getState(), MachineState.PoweredOff);
|
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")
|
@Test(dependsOnMethods = "testStopVirtualMachine")
|
||||||
public void cleanUp() throws IOException {
|
public void testChangeNICtoBridged() {
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine adminNode = manager.getVBox().findMachine(vmName);
|
||||||
machine.lockMachine(session, LockType.Write);
|
adminNode.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
mutable.getNetworkAdapter(new Long(0)).getNatDriver()
|
// network
|
||||||
.removeRedirect("guestssh");
|
String hostInterface = null;
|
||||||
// detach disk from controller
|
String command = "vboxmanage list bridgedifs";
|
||||||
mutable.detachDevice(controllerIDE, 0, 0);
|
try {
|
||||||
mutable.saveSettings();
|
Process child = Runtime.getRuntime().exec(command);
|
||||||
session.unlockMachine();
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
||||||
|
String line = "";
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
for (IStorageController storageController : machine
|
while ((line = bufferedReader.readLine()) != null && !found) {
|
||||||
.getStorageControllers()) {
|
if (line.split(":")[0].contains("Name")) {
|
||||||
if (storageController.getName().equals(controllerSATA)) {
|
hostInterface = line.split(":")[1];
|
||||||
session = manager.getSessionObject();
|
}
|
||||||
machine.lockMachine(session, LockType.Write);
|
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.getNetworkAdapter(new Long(0)).setAttachmentType(NetworkAttachmentType.Bridged);
|
||||||
mutable.detachDevice(storageController.getName(), 1, 1);
|
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();
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
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
|
@AfterClass
|
||||||
|
@ -621,4 +622,31 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
prog.waitForCompletion(-1);
|
prog.waitForCompletion(-1);
|
||||||
session.unlockMachine();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
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;
|
||||||
|
@ -47,11 +50,12 @@ import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CloneMode;
|
import org.virtualbox_4_1.CloneMode;
|
||||||
import org.virtualbox_4_1.CloneOptions;
|
import org.virtualbox_4_1.CloneOptions;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_1.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_1.ISession;
|
||||||
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.NetworkAdapterType;
|
||||||
|
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_1.SessionState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
|
@ -143,7 +147,6 @@ public class VirtualboxLiveTest {
|
||||||
|
|
||||||
clonedDisk = System.getProperty("test." + provider + ".clonedDisk", "clone.vdi");
|
clonedDisk = System.getProperty("test." + provider + ".clonedDisk", "clone.vdi");
|
||||||
clonedDiskPath = workingDir + File.separator + clonedDisk;
|
clonedDiskPath = workingDir + File.separator + clonedDisk;
|
||||||
snapshotDescription = System.getProperty("test." + provider + "snapshotdescription", "jclouds-virtualbox-snaphot");
|
|
||||||
numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider
|
numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider
|
||||||
+ ".numberOfVirtualMachine", "3")));
|
+ ".numberOfVirtualMachine", "3")));
|
||||||
}
|
}
|
||||||
|
@ -172,16 +175,6 @@ public class VirtualboxLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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 {
|
public void testStartAndValidateVirtualMachines() throws InterruptedException {
|
||||||
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
||||||
createAndLaunchVirtualMachine(i);
|
createAndLaunchVirtualMachine(i);
|
||||||
|
@ -189,9 +182,9 @@ public class VirtualboxLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAndLaunchVirtualMachine(int i) throws InterruptedException {
|
private void createAndLaunchVirtualMachine(int i) throws InterruptedException {
|
||||||
|
|
||||||
String instanceName = vmName + "_" + i;
|
String instanceName = vmName + "_" + i;
|
||||||
IMachine adminNode = manager.getVBox().findMachine(adminNodeName);
|
IMachine adminNode = manager.getVBox().findMachine(adminNodeName);
|
||||||
|
|
||||||
IMachine clonedVM = manager.getVBox().createMachine(settingsFile, instanceName, osTypeId, vmId, forceOverwrite);
|
IMachine clonedVM = manager.getVBox().createMachine(settingsFile, instanceName, osTypeId, vmId, forceOverwrite);
|
||||||
List<CloneOptions> options = new ArrayList<CloneOptions>();
|
List<CloneOptions> options = new ArrayList<CloneOptions>();
|
||||||
options.add(CloneOptions.Link);
|
options.add(CloneOptions.Link);
|
||||||
|
@ -201,6 +194,7 @@ public class VirtualboxLiveTest {
|
||||||
|
|
||||||
manager.getVBox().registerMachine(clonedVM);
|
manager.getVBox().registerMachine(clonedVM);
|
||||||
|
|
||||||
|
|
||||||
System.out.println("\nLaunching VM named " + clonedVM.getName() + " ...");
|
System.out.println("\nLaunching VM named " + clonedVM.getName() + " ...");
|
||||||
launchVMProcess(clonedVM, manager.getSessionObject());
|
launchVMProcess(clonedVM, manager.getSessionObject());
|
||||||
String ipAddress = null;
|
String ipAddress = null;
|
||||||
|
|
Loading…
Reference in New Issue