mirror of https://github.com/apache/jclouds.git
issue 384: VirtualboxAdminTest can clone multiple vms from the admin node in linked mode - still issues with bridged network, so right now NAT is used
This commit is contained in:
parent
78b89d10d2
commit
4b62c4a022
|
@ -354,7 +354,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
machine.lockMachine(session, LockType.Write);
|
machine.lockMachine(session, LockType.Write);
|
||||||
IMachine mutable = session.getMachine();
|
IMachine mutable = session.getMachine();
|
||||||
mutable.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
mutable.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||||
mutable.saveSettings(); // write settings to xml
|
mutable.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
assertEquals(distroMedium.getId().equals(""), false);
|
assertEquals(distroMedium.getId().equals(""), false);
|
||||||
}
|
}
|
||||||
|
@ -442,21 +442,19 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
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
|
// TODO generalize: at the moment we are usign apt-get not the guestadditions.iso attached
|
||||||
|
|
||||||
|
|
||||||
//if(isUbuntu(guestId)) {
|
//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", 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");
|
||||||
runScriptOnNode(guestId, "sh /media/cdrom/VBoxLinuxAdditions.run");
|
ExecResponse response = runScriptOnNode(guestId, "sh /media/cdrom/VBoxLinuxAdditions.run");
|
||||||
|
response.getExitCode();
|
||||||
// for Debian based OS
|
// 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");
|
||||||
|
|
||||||
|
@ -488,12 +486,12 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
+ machine.getSessionState());
|
+ machine.getSessionState());
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,19 +584,13 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.keySet()) {
|
|
||||||
//System.out.println("specialbutton " + specialButton);
|
|
||||||
if (s.startsWith("<")) {
|
if (s.startsWith("<")) {
|
||||||
String[] specials = s.split("<");
|
String[] specials = s.split("<");
|
||||||
for (int i = 1; i < specials.length; i++) {
|
for (int i = 1; i < specials.length; i++) {
|
||||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||||
.get("<" + specials[i]) + " ");
|
.get("<" + specials[i]) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println("keycodes: " + keycodes);
|
|
||||||
return keycodes.toString();
|
return keycodes.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,7 @@ 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,22 +44,16 @@ import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.AccessMode;
|
import org.virtualbox_4_1.CloneMode;
|
||||||
import org.virtualbox_4_1.CloneOptions;
|
import org.virtualbox_4_1.CloneOptions;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
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.MediumType;
|
|
||||||
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.StorageBus;
|
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
import org.virtualbox_4_1.jaxws.MediumVariant;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
@ -90,28 +81,16 @@ public class VirtualboxLiveTest {
|
||||||
protected String controller;
|
protected String controller;
|
||||||
protected String diskFormat;
|
protected String diskFormat;
|
||||||
|
|
||||||
protected String settingsFile; // Fully qualified path where the settings
|
protected String settingsFile;
|
||||||
// file should be created, or NULL for a
|
protected String osTypeId;
|
||||||
// default
|
protected String vmId;
|
||||||
// folder and file based on the name argument (see composeMachineFilename()).
|
protected boolean forceOverwrite;
|
||||||
|
|
||||||
protected String osTypeId; // Guest OS Type ID.
|
|
||||||
protected String vmId; // Machine UUID (optional).
|
|
||||||
protected boolean forceOverwrite; // If true, an existing machine settings
|
|
||||||
// file will be overwritten.
|
|
||||||
|
|
||||||
protected String workingDir;
|
protected String workingDir;
|
||||||
protected String clonedDiskPath;
|
protected String clonedDiskPath;
|
||||||
|
protected String format = "vdi";
|
||||||
// Create disk If the @a format attribute is empty or null then the default
|
|
||||||
// storage format specified by ISystemProperties#defaultHardDiskFormat
|
|
||||||
String format = "vdi";
|
|
||||||
|
|
||||||
protected int numberOfVirtualMachine;
|
protected int numberOfVirtualMachine;
|
||||||
protected String originalDisk;
|
protected String originalDisk;
|
||||||
private String originalDiskPath;
|
|
||||||
private String clonedDisk;
|
private String clonedDisk;
|
||||||
private IMedium clonedHd;
|
|
||||||
private ComputeServiceContext context;
|
private ComputeServiceContext context;
|
||||||
|
|
||||||
private String hostId = "host";
|
private String hostId = "host";
|
||||||
|
@ -120,6 +99,8 @@ public class VirtualboxLiveTest {
|
||||||
private String minorVersion;
|
private String minorVersion;
|
||||||
private String apiVersion;
|
private String apiVersion;
|
||||||
private String adminNodeName;
|
private String adminNodeName;
|
||||||
|
private String snapshotDescription;
|
||||||
|
private String originalDiskPath;
|
||||||
|
|
||||||
protected Logger logger() {
|
protected Logger logger() {
|
||||||
return context.utils().loggerFactory().getLogger("jclouds.compute");
|
return context.utils().loggerFactory().getLogger("jclouds.compute");
|
||||||
|
@ -162,9 +143,9 @@ 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", "1")));
|
+ ".numberOfVirtualMachine", "3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeGroups(groups = "live")
|
@BeforeGroups(groups = "live")
|
||||||
|
@ -191,83 +172,52 @@ public class VirtualboxLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneHardDisk() {
|
public void testTakeAdminNodeSnapshot() {
|
||||||
IMedium hd = manager.getVBox().openMedium(originalDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, forceOverwrite);
|
ISession session = manager.getSessionObject();
|
||||||
if (!new File(clonedDiskPath).exists()) {
|
IMachine adminNode = manager.getVBox().findMachine(adminNodeName);
|
||||||
clonedHd = manager.getVBox().createHardDisk(diskFormat, clonedDiskPath);
|
adminNode.lockMachine(session, LockType.Write);
|
||||||
IProgress cloning = hd.cloneTo(clonedHd, new Long(
|
if(adminNode.getCurrentSnapshot() == null || !adminNode.getCurrentSnapshot().getDescription().equals(snapshotDescription)) {
|
||||||
MediumVariant.STANDARD.ordinal()), null);
|
manager.getSessionObject().getConsole().takeSnapshot(adminNode.getId(), snapshotDescription);
|
||||||
cloning.waitForCompletion(-1);
|
}
|
||||||
} else
|
|
||||||
clonedHd = manager.getVBox().openMedium(clonedDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, forceOverwrite);
|
|
||||||
|
|
||||||
|
|
||||||
clonedHd.setType(MediumType.MultiAttach);
|
|
||||||
assertEquals(clonedHd.getId().equals(""), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCloneHardDisk")
|
@Test(dependsOnMethods = "testTakeAdminNodeSnapshot")
|
||||||
public void testStartVirtualMachines() throws InterruptedException {
|
public void testStartAndValidateVirtualMachines() throws InterruptedException {
|
||||||
//IMedium clonedHd = cloneDisk(MediumType.MultiAttach);
|
|
||||||
List<CloneOptions> options = new ArrayList<CloneOptions>();
|
|
||||||
options.add(CloneOptions.KeepDiskNames);
|
|
||||||
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
||||||
createVirtualMachine(i);
|
createAndLaunchVirtualMachine(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createVirtualMachine(int i) {
|
private void createAndLaunchVirtualMachine(int i) throws InterruptedException {
|
||||||
|
|
||||||
String instanceName = vmName + "_" + i;
|
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);
|
||||||
|
IProgress progress = adminNode.getCurrentSnapshot().getMachine().cloneTo(clonedVM,CloneMode.MachineState , options);
|
||||||
|
if(progress.getCompleted())
|
||||||
|
logger().debug("clone done");
|
||||||
|
|
||||||
IMachine newVM = manager.getVBox().createMachine(settingsFile, instanceName, osTypeId, vmId, forceOverwrite);
|
manager.getVBox().registerMachine(clonedVM);
|
||||||
manager.getVBox().registerMachine(newVM);
|
|
||||||
|
|
||||||
ISession session = manager.getSessionObject();
|
System.out.println("\nLaunching VM named " + clonedVM.getName() + " ...");
|
||||||
IMachine machine = manager.getVBox().findMachine(instanceName);
|
launchVMProcess(clonedVM, manager.getSessionObject());
|
||||||
|
String ipAddress = null;
|
||||||
|
while (ipAddress == null || ipAddress.equals("")) {
|
||||||
machine.lockMachine(session, LockType.Write);
|
|
||||||
IMachine mutable = session.getMachine();
|
|
||||||
// network
|
|
||||||
String hostInterface = null;
|
|
||||||
String command = "vboxmanage list bridgedifs";
|
|
||||||
try {
|
try {
|
||||||
Process child = Runtime.getRuntime().exec(command);
|
ipAddress = clonedVM.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP");
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
Thread.sleep(1000);
|
||||||
String line = "";
|
} catch (InterruptedException e) {
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
mutable.getNetworkAdapter(new Long(0)).setAttachmentType(
|
}
|
||||||
NetworkAttachmentType.Bridged);
|
System.out.println(ipAddress + " is the IP address of " + clonedVM.getName());
|
||||||
mutable.getNetworkAdapter(new Long(0)).setAdapterType(NetworkAdapterType.Am79C973);
|
|
||||||
mutable.getNetworkAdapter(new Long(0)).setBridgedInterface(hostInterface.trim());
|
//TODO
|
||||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
// IPSocket socket = new IPSocket(ipAddress, 22);
|
||||||
mutable.saveSettings();
|
// checkSSH(IPSocket socket)
|
||||||
|
|
||||||
// disk
|
|
||||||
mutable.addStorageController(controller, StorageBus.IDE);
|
|
||||||
mutable.saveSettings();
|
|
||||||
IMedium distroMedium = manager.getVBox().openMedium(
|
|
||||||
clonedDiskPath, DeviceType.HardDisk,
|
|
||||||
AccessMode.ReadWrite, forceOverwrite);
|
|
||||||
mutable.attachDevice(controller, 0, 0, DeviceType.HardDisk, distroMedium);
|
|
||||||
mutable.saveSettings();
|
|
||||||
session.unlockMachine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchVMProcess(IMachine machine, ISession session) {
|
private void launchVMProcess(IMachine machine, ISession session) {
|
||||||
|
@ -291,34 +241,8 @@ public class VirtualboxLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testStartVirtualMachines")
|
@Test(dependsOnMethods = "testStartAndValidateVirtualMachines")
|
||||||
public void testSshLogin() {
|
public void testStopVirtualMachines() {
|
||||||
String ipAddress = null;
|
|
||||||
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
|
||||||
String instanceName = vmName + "_" + i;
|
|
||||||
IMachine machine = manager.getVBox().findMachine(instanceName);
|
|
||||||
|
|
||||||
System.out.println("\nLaunching VM named " + machine.getName() + " ...");
|
|
||||||
launchVMProcess(machine, manager.getSessionObject());
|
|
||||||
|
|
||||||
while (ipAddress == null || ipAddress.equals("")) {
|
|
||||||
try {
|
|
||||||
ipAddress = machine.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP");
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("VM " + instanceName + " started with IP " + ipAddress);
|
|
||||||
IPSocket socket = new IPSocket(ipAddress, 22);
|
|
||||||
|
|
||||||
System.out.println("Check SSH for " + instanceName + " ...");
|
|
||||||
checkSSH(socket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testSshLogin")
|
|
||||||
public void testStopVirtualMachine() {
|
|
||||||
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
||||||
String instanceName = vmName + "_" + i;
|
String instanceName = vmName + "_" + i;
|
||||||
IMachine machine = manager.getVBox().findMachine(instanceName);
|
IMachine machine = manager.getVBox().findMachine(instanceName);
|
||||||
|
|
Loading…
Reference in New Issue