From e49bfd9c59c91ca847283d3b45cf9c9e0c372d84 Mon Sep 17 00:00:00 2001 From: andreaturli Date: Tue, 20 Sep 2011 22:06:03 +0100 Subject: [PATCH] issue 384: fix bridge inteface detection --- ...ualboxAdministrationKickstartLiveTest.java | 17 ++++---- .../experiment/VirtualboxLiveTest.java | 41 ++++++++++++++++++- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxAdministrationKickstartLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxAdministrationKickstartLiveTest.java index a7ebcf3685..8b64c28b4b 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxAdministrationKickstartLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxAdministrationKickstartLiveTest.java @@ -370,14 +370,13 @@ public class VirtualboxAdministrationKickstartLiveTest { @Test(dependsOnMethods = "testAttachIsoDvd") public void testCreateAndAttachHardDisk() throws InterruptedException { IMedium hd = null; - if (!new File(adminDisk).exists()) { - 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())); - } else { - // TODO disk already exist: open it + if (new File(adminDisk).exists()) { + new File(adminDisk).delete(); } + 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(); IMachine machine = manager.getVBox().findMachine(vmName); @@ -456,11 +455,13 @@ public class VirtualboxAdministrationKickstartLiveTest { public void testConfigureGuestAdditions() { // TODO generalize if(isUbuntu(guestId)) { - runScriptOnNode(guestId, "m-a prepare -i", wrapInInitScript(true)); + runScriptOnNode(guestId, + "m-a prepare -i"); runScriptOnNode(guestId, "mount -o loop /dev/dvd /media/cdrom"); runScriptOnNode(guestId, "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, "mkdir /etc/udev/rules.d/70-persistent-net.rules"); runScriptOnNode(guestId, "rm -rf /dev/.udev/"); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxLiveTest.java index 6e5f74c4e3..71daf52500 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/VirtualboxLiveTest.java @@ -148,7 +148,7 @@ public class VirtualboxLiveTest { clonedDisk = System.getProperty("test." + provider + ".clonedDisk", "clone.vdi"); clonedDiskPath = workingDir + File.separator + clonedDisk; numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider - + ".numberOfVirtualMachine", "3"))); + + ".numberOfVirtualMachine", "1"))); } @BeforeGroups(groups = "live") @@ -189,12 +189,49 @@ public class VirtualboxLiveTest { List options = new ArrayList(); options.add(CloneOptions.Link); IProgress progress = adminNode.getCurrentSnapshot().getMachine().cloneTo(clonedVM,CloneMode.MachineState , options); + //IProgress progress = adminNode.cloneTo(clonedVM,CloneMode.MachineState , options); + if(progress.getCompleted()) logger().debug("clone done"); 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() + " ..."); launchVMProcess(clonedVM, manager.getSessionObject()); String ipAddress = null;