issue 384: fix bridge inteface detection

This commit is contained in:
andreaturli 2011-09-20 22:06:03 +01:00
parent aed4e72e49
commit e49bfd9c59
2 changed files with 48 additions and 10 deletions

View File

@ -370,14 +370,13 @@ public class VirtualboxAdministrationKickstartLiveTest {
@Test(dependsOnMethods = "testAttachIsoDvd") @Test(dependsOnMethods = "testAttachIsoDvd")
public void testCreateAndAttachHardDisk() throws InterruptedException { public void testCreateAndAttachHardDisk() throws InterruptedException {
IMedium hd = null; IMedium hd = null;
if (!new File(adminDisk).exists()) { if (new File(adminDisk).exists()) {
hd = manager.getVBox().createHardDisk(diskFormat, adminDisk); new File(adminDisk).delete();
long size = 4L * 1024L * 1024L * 1024L - 4L;
IProgress progress = hd.createBaseStorage(new Long(size), new Long(
MediumVariant.STANDARD.ordinal()));
} else {
// TODO disk already exist: open it
} }
hd = manager.getVBox().createHardDisk(diskFormat, adminDisk);
long size = 4L * 1024L * 1024L * 1024L - 4L;
IProgress progress = hd.createBaseStorage(new Long(size), new Long(
MediumVariant.STANDARD.ordinal()));
ISession session = manager.getSessionObject(); ISession session = manager.getSessionObject();
IMachine machine = manager.getVBox().findMachine(vmName); IMachine machine = manager.getVBox().findMachine(vmName);
@ -456,11 +455,13 @@ public class VirtualboxAdministrationKickstartLiveTest {
public void testConfigureGuestAdditions() { public void testConfigureGuestAdditions() {
// TODO generalize // TODO generalize
if(isUbuntu(guestId)) { if(isUbuntu(guestId)) {
runScriptOnNode(guestId, "m-a prepare -i", wrapInInitScript(true)); runScriptOnNode(guestId,
"m-a prepare -i");
runScriptOnNode(guestId, runScriptOnNode(guestId,
"mount -o loop /dev/dvd /media/cdrom"); "mount -o loop /dev/dvd /media/cdrom");
runScriptOnNode(guestId, runScriptOnNode(guestId,
"sh /media/cdrom/VBoxLinuxAdditions.run"); "sh /media/cdrom/VBoxLinuxAdditions.run");
runScriptOnNode(guestId, "/etc/init.d/vboxadd setup");
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, "mkdir /etc/udev/rules.d/70-persistent-net.rules");
runScriptOnNode(guestId, "rm -rf /dev/.udev/"); runScriptOnNode(guestId, "rm -rf /dev/.udev/");

View File

@ -148,7 +148,7 @@ 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;
numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider
+ ".numberOfVirtualMachine", "3"))); + ".numberOfVirtualMachine", "1")));
} }
@BeforeGroups(groups = "live") @BeforeGroups(groups = "live")
@ -189,11 +189,48 @@ public class VirtualboxLiveTest {
List<CloneOptions> options = new ArrayList<CloneOptions>(); List<CloneOptions> options = new ArrayList<CloneOptions>();
options.add(CloneOptions.Link); options.add(CloneOptions.Link);
IProgress progress = adminNode.getCurrentSnapshot().getMachine().cloneTo(clonedVM,CloneMode.MachineState , options); IProgress progress = adminNode.getCurrentSnapshot().getMachine().cloneTo(clonedVM,CloneMode.MachineState , options);
//IProgress progress = adminNode.cloneTo(clonedVM,CloneMode.MachineState , options);
if(progress.getCompleted()) if(progress.getCompleted())
logger().debug("clone done"); logger().debug("clone done");
manager.getVBox().registerMachine(clonedVM); manager.getVBox().registerMachine(clonedVM);
ISession session = manager.getSessionObject();
clonedVM.lockMachine(session, LockType.Write);
IMachine mutable = session.getMachine();
// 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;
while ((line = bufferedReader.readLine()) != null && !found) {
System.out.println("line: " + line);
if (line.split(":")[0].contains("Name")) {
hostInterface = line.substring(line.indexOf(":") +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.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();
System.out.println("\nLaunching VM named " + clonedVM.getName() + " ..."); System.out.println("\nLaunching VM named " + clonedVM.getName() + " ...");
launchVMProcess(clonedVM, manager.getSessionObject()); launchVMProcess(clonedVM, manager.getSessionObject());