mirror of https://github.com/apache/jclouds.git
fixed headers and formatting
This commit is contained in:
parent
d8dee64cf7
commit
21821231cb
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.virtualbox.experiment;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
|
@ -9,13 +27,13 @@ import org.eclipse.jetty.util.log.Log;
|
|||
|
||||
public class FileServer {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Server server = new Server(args.length == 0?8080:Integer.parseInt(args[0]));
|
||||
Server server = new Server(args.length == 0 ? 8080 : Integer.parseInt(args[0]));
|
||||
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
resource_handler.setDirectoriesListed(true);
|
||||
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
|
||||
resource_handler.setWelcomeFiles(new String[] { "index.html" });
|
||||
|
||||
resource_handler.setResourceBase(args.length == 2?args[1]:".");
|
||||
resource_handler.setResourceBase(args.length == 2 ? args[1] : ".");
|
||||
Log.info("serving " + resource_handler.getBaseResource());
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.virtualbox.experiment;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
|
|
@ -1,4 +1,23 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.virtualbox.experiment;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.blockOnPort;
|
||||
|
@ -88,10 +107,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
private String controllerIDE;
|
||||
private String controllerSATA;
|
||||
private String keyboardSequence;
|
||||
private String vdiName;
|
||||
private String preseedUrl;
|
||||
|
||||
protected Server server = null;
|
||||
private ComputeServiceContext context;
|
||||
private String hostId = "host";
|
||||
private String guestId = "guest";
|
||||
|
@ -103,8 +120,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
credential = System.getProperty("test." + provider + ".credential", "12345");
|
||||
endpoint = URI.create(System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/"));
|
||||
apiVersion = System.getProperty("test." + provider + ".apiversion", "4.1.0r73009");
|
||||
majorVersion = Iterables.get(Splitter.on('r').split(apiVersion),0);
|
||||
minorVersion = Iterables.get(Splitter.on('r').split(apiVersion),1);
|
||||
majorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 0);
|
||||
minorVersion = Iterables.get(Splitter.on('r').split(apiVersion), 1);
|
||||
}
|
||||
|
||||
protected Logger logger() {
|
||||
|
@ -124,37 +141,33 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
forceOverwrite = true;
|
||||
vmName = System.getProperty("test." + provider + ".vmname", "jclouds-virtualbox-kickstart-admin");
|
||||
|
||||
workingDir = System.getProperty("user.home")
|
||||
+ File.separator + System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
||||
workingDir = System.getProperty("user.home") + File.separator
|
||||
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
||||
if (new File(workingDir).mkdir())
|
||||
;
|
||||
vdiName = System.getProperty("test." + provider + ".vdiName", "centos-5.2-x86.7z");
|
||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_"+majorVersion+"-update-"+minorVersion+".iso");
|
||||
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl", "http://download.virtualbox.org/virtualbox/"+majorVersion+"/VBoxGuestAdditions_"+majorVersion+"-update-"+minorVersion+".iso"));
|
||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion
|
||||
+ "-update-" + minorVersion + ".iso");
|
||||
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl",
|
||||
"http://download.virtualbox.org/virtualbox/" + majorVersion + "/VBoxGuestAdditions_" + majorVersion
|
||||
+ "-update-" + minorVersion + ".iso"));
|
||||
|
||||
distroIsoName = System.getProperty("test." + provider
|
||||
+ ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
||||
distroIsoUrl = URI.create(System
|
||||
.getProperty("test." + provider + ".distroIsoUrl",
|
||||
distroIsoName = System.getProperty("test." + provider + ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
||||
distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl",
|
||||
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"));
|
||||
|
||||
originalDisk = workingDir + File.separator + "VDI" + File.separator + System.getProperty("test." + provider + ".originalDisk",
|
||||
"centos-5.2-x86.vdi");
|
||||
clonedDisk = workingDir + File.separator + System.getProperty("test." + provider + ".clonedDisk",
|
||||
"template.vdi");
|
||||
guestAdditionsDvd = workingDir + File.separator + System.getProperty("test." + provider + ".guestAdditionsDvd",
|
||||
"VBoxGuestAdditions_"+majorVersion+"-update-"+minorVersion+".iso");
|
||||
originalDisk = workingDir + File.separator + "VDI" + File.separator
|
||||
+ System.getProperty("test." + provider + ".originalDisk", "centos-5.2-x86.vdi");
|
||||
clonedDisk = workingDir + File.separator + System.getProperty("test." + provider + ".clonedDisk", "template.vdi");
|
||||
guestAdditionsDvd = workingDir
|
||||
+ File.separator
|
||||
+ System.getProperty("test." + provider + ".guestAdditionsDvd", "VBoxGuestAdditions_" + majorVersion
|
||||
+ "-update-" + minorVersion + ".iso");
|
||||
|
||||
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
|
||||
"http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||
preseedUrl = System.getProperty("test." + provider + ".preseedurl", "http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||
|
||||
keyboardSequence = System.getProperty("test." + provider + ".keyboardSequence",
|
||||
"<Esc> <Esc> <Enter> "
|
||||
keyboardSequence = System.getProperty("test." + provider + ".keyboardSequence", "<Esc> <Esc> <Enter> "
|
||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||
+ "hostname="
|
||||
+ vmName
|
||||
+ " "
|
||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " "
|
||||
+ "fb=false debconf/frontend=noninteractive "
|
||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
||||
|
@ -164,8 +177,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
@BeforeGroups(groups = "live")
|
||||
protected void setupClient() throws Exception {
|
||||
context = TestUtils.computeServiceForLocalhost();
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 130, 10,
|
||||
TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);
|
||||
setupCredentials();
|
||||
setupConfigurationProperties();
|
||||
downloadFileUnlessPresent(distroIsoUrl, workingDir, distroIsoName);
|
||||
|
@ -189,8 +201,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
logger().info("serving " + resource_handler.getBaseResource());
|
||||
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { resource_handler,
|
||||
new DefaultHandler() });
|
||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
|
||||
server.start();
|
||||
|
@ -227,13 +238,15 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
if (isOSX(hostId))
|
||||
vboxwebsrv = "cd /Applications/VirtualBox.app/Contents/MacOS/&&" + vboxwebsrv;
|
||||
// allow jclouds to background the process, this is why we don't specify
|
||||
// -b; logs will go corresponding to task name in this case under /tmp/vboxwebsrv
|
||||
// -b; logs will go corresponding to task name in this case under
|
||||
// /tmp/vboxwebsrv
|
||||
runScriptOnNode(hostId, vboxwebsrv,
|
||||
blockOnPort(endpoint.getPort(), 10).blockOnComplete(false).nameTask("vboxwebsrv"));
|
||||
}
|
||||
|
||||
protected boolean isOSX(String id) {
|
||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals("Mac OS X");
|
||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription()
|
||||
.equals("Mac OS X");
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
|
@ -242,15 +255,13 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
}
|
||||
|
||||
@AfterMethod
|
||||
protected void disconnectAndClenaupManager() throws RemoteException,
|
||||
MalformedURLException {
|
||||
protected void disconnectAndClenaupManager() throws RemoteException, MalformedURLException {
|
||||
manager.disconnect();
|
||||
manager.cleanup();
|
||||
}
|
||||
|
||||
public void testCreateVirtualMachine() {
|
||||
IMachine newVM = manager.getVBox().createMachine(settingsFile, vmName,
|
||||
osTypeId, vmId, forceOverwrite);
|
||||
IMachine newVM = manager.getVBox().createMachine(settingsFile, vmName, osTypeId, vmId, forceOverwrite);
|
||||
manager.getVBox().registerMachine(newVM);
|
||||
assertEquals(newVM.getName(), vmName);
|
||||
}
|
||||
|
@ -265,8 +276,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
mutable.setMemorySize(memorySize);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(),
|
||||
memorySize);
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(), memorySize);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testChangeRAM")
|
||||
|
@ -278,8 +288,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
mutable.addStorageController(controllerSATA, StorageBus.SATA);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(manager.getVBox().findMachine(vmName)
|
||||
.getStorageControllers().size(), 2);
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getStorageControllers().size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateScsiController")
|
||||
|
@ -288,11 +297,9 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
if (!new File(clonedDisk).exists()) {
|
||||
hd = manager.getVBox().createHardDisk(diskFormat, clonedDisk);
|
||||
long size = 2 * 1024 * 1024 * 1024 - 1;
|
||||
hd.createBaseStorage(new Long(size), new Long(
|
||||
MediumVariant.VMDK_SPLIT_2_G.ordinal()));
|
||||
hd.createBaseStorage(new Long(size), new Long(MediumVariant.VMDK_SPLIT_2_G.ordinal()));
|
||||
} else
|
||||
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk,
|
||||
AccessMode.ReadWrite, forceOverwrite);
|
||||
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk, AccessMode.ReadWrite, forceOverwrite);
|
||||
ISession session = manager.getSessionObject();
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
|
@ -315,8 +322,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
String command = "VBoxManage list bridgedifs";
|
||||
try {
|
||||
Process child = Runtime.getRuntime().exec(command);
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(child.getInputStream()));
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
||||
String line = "";
|
||||
boolean found = false;
|
||||
|
||||
|
@ -325,20 +331,18 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
if (line.split(":")[0].contains("Name")) {
|
||||
hostInterface = line.split(":")[1];
|
||||
}
|
||||
if (line.split(":")[0].contains("Status")
|
||||
&& line.split(":")[1].contains("Up")) {
|
||||
if (line.split(":")[0].contains("Status") && line.split(":")[1].contains("Up")) {
|
||||
System.out.println("bridge: " + hostInterface.trim());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
// NAT
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); TODO: this no longer exists!
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); TODO: this no
|
||||
// longer exists!
|
||||
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
|
||||
machine.getNetworkAdapter(new Long(0))
|
||||
.getNatDriver()
|
||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1",
|
||||
2222, "", 22);
|
||||
machine.getNetworkAdapter(new Long(0)).getNatDriver()
|
||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222, "", 22);
|
||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
||||
|
||||
mutable.saveSettings();
|
||||
|
@ -391,8 +395,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
|
||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
||||
try {
|
||||
System.out.println("waiting for unlocking session - session state: "
|
||||
+ machine.getSessionState());
|
||||
System.out.println("waiting for unlocking session - session state: " + machine.getSessionState());
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -410,15 +413,13 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
IMachine mutable = session.getMachine();
|
||||
mutable.getNetworkAdapter(new Long(0)).getNatDriver()
|
||||
.removeRedirect("guestssh");
|
||||
mutable.getNetworkAdapter(new Long(0)).getNatDriver().removeRedirect("guestssh");
|
||||
// detach disk from controller
|
||||
mutable.detachDevice(controllerIDE, 0, 0);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
||||
for (IStorageController storageController : machine
|
||||
.getStorageControllers()) {
|
||||
for (IStorageController storageController : machine.getStorageControllers()) {
|
||||
if (storageController.getName().equals(controllerSATA)) {
|
||||
session = manager.getSessionObject();
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
|
@ -438,7 +439,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
|
||||
protected ExecResponse runScriptOnNode(String nodeId, String command, RunScriptOptions options) {
|
||||
ExecResponse toReturn = context.getComputeService().runScriptOnNode(nodeId, command, options);
|
||||
assert toReturn.getExitCode() == 0: toReturn;
|
||||
assert toReturn.getExitCode() == 0 : toReturn;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
@ -446,8 +447,7 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
return runScriptOnNode(nodeId, command, wrapInInitScript(false));
|
||||
}
|
||||
|
||||
private File downloadFileUnlessPresent(URI sourceURL, String destinationDir,
|
||||
String filename) throws Exception {
|
||||
private File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception {
|
||||
|
||||
File iso = new File(destinationDir, filename);
|
||||
|
||||
|
@ -469,11 +469,8 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
String converted = stringToKeycode(word);
|
||||
for (String string : converted.split(" ")) {
|
||||
|
||||
runScriptOnNode(hostId , "VBoxManage controlvm " + vmName + " keyboardputscancode "
|
||||
+ string);
|
||||
if (converted
|
||||
.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||
.get("<Return>")))
|
||||
runScriptOnNode(hostId, "VBoxManage controlvm " + vmName + " keyboardputscancode " + string);
|
||||
if (converted.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Return>")))
|
||||
Thread.sleep(180);
|
||||
}
|
||||
}
|
||||
|
@ -483,11 +480,9 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
private String stringToKeycode(String s) {
|
||||
|
||||
StringBuilder keycodes = new StringBuilder();
|
||||
for (String specialButton : KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||
.keySet()) {
|
||||
for (String specialButton : KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.keySet()) {
|
||||
if (s.startsWith(specialButton)) {
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||
.get(specialButton));
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get(specialButton));
|
||||
return keycodes.toString();
|
||||
}
|
||||
}
|
||||
|
@ -495,13 +490,11 @@ public class VirtualboxAdministrationKickstartLiveTest {
|
|||
int i = 0;
|
||||
while (i < s.length()) {
|
||||
String digit = s.substring(i, i + 1);
|
||||
String hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP
|
||||
.get(digit);
|
||||
String hex = KeyboardScancodes.NORMAL_KEYBOARD_BUTTON_MAP.get(digit);
|
||||
keycodes.append(hex + " ");
|
||||
i++;
|
||||
}
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
|
||||
.get("<Spacebar>") + " ");
|
||||
keycodes.append(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP.get("<Spacebar>") + " ");
|
||||
|
||||
return keycodes.toString();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.virtualbox.experiment;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -63,12 +81,15 @@ public class VirtualboxAdministrationLiveTest {
|
|||
protected Predicate<IPSocket> socketTester;
|
||||
protected SshClient.Factory sshFactory;
|
||||
|
||||
protected String settingsFile; // Fully qualified path where the settings file should be created, or NULL for a default
|
||||
protected String settingsFile; // Fully qualified path where the settings
|
||||
// file should be created, or NULL for a
|
||||
// default
|
||||
// folder and file based on the name argument (see composeMachineFilename()).
|
||||
|
||||
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 boolean forceOverwrite; // If true, an existing machine settings
|
||||
// file will be overwritten.
|
||||
|
||||
protected String osUsername;
|
||||
protected String osPassword;
|
||||
|
@ -83,7 +104,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
private String vdiUrl;
|
||||
private String gaIsoUrl;
|
||||
private String vboxwebsrvStartCommand;
|
||||
// private Process pr;
|
||||
// private Process pr;
|
||||
private String vdiName;
|
||||
private String gaIsoName;
|
||||
private String admin_pwd;
|
||||
|
@ -99,11 +120,14 @@ public class VirtualboxAdministrationLiveTest {
|
|||
*
|
||||
* @param workingDir
|
||||
* @param vdiUrl
|
||||
* @param proxy Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 5865));
|
||||
* @param proxy
|
||||
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new
|
||||
* InetSocketAddress("localhost", 5865));
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private File downloadFile(String sourceURL, String destinationDir, String vboxGuestAdditionsName, Proxy proxy) throws Exception {
|
||||
private File downloadFile(String sourceURL, String destinationDir, String vboxGuestAdditionsName, Proxy proxy)
|
||||
throws Exception {
|
||||
|
||||
String absolutePathName = destinationDir + File.separator + vboxGuestAdditionsName;
|
||||
File iso = new File(absolutePathName);
|
||||
|
@ -111,7 +135,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
final URL isoURL = new URL(sourceURL);
|
||||
final HttpURLConnection uc = (HttpURLConnection) isoURL.openConnection(); // isoURL.openConnection(proxy);
|
||||
uc.connect();
|
||||
if(!iso.exists()) {
|
||||
if (!iso.exists()) {
|
||||
System.out.println("Start download " + sourceURL + " to " + absolutePathName);
|
||||
Files.copy(new InputSupplier<InputStream>() {
|
||||
|
||||
|
@ -139,40 +163,61 @@ public class VirtualboxAdministrationLiveTest {
|
|||
osUsername = System.getProperty("test." + provider + ".osusername", "root");
|
||||
osPassword = System.getProperty("test." + provider + ".ospassword", "toortoor");
|
||||
controller = System.getProperty("test." + provider + ".controller", "IDE Controller");
|
||||
// Create disk If the @a format attribute is empty or null then the default storage format specified by ISystemProperties#defaultHardDiskFormat
|
||||
// Create disk If the @a format attribute is empty or null then the
|
||||
// default storage format specified by
|
||||
// ISystemProperties#defaultHardDiskFormat
|
||||
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
||||
|
||||
//VBOX
|
||||
settingsFile = null; // Fully qualified path where the settings file should be created, or NULL for a default
|
||||
// folder and file based on the name argument (see composeMachineFilename()).
|
||||
// VBOX
|
||||
settingsFile = null; // Fully qualified path where the settings file
|
||||
// should be created, or NULL for a default
|
||||
// folder and file based on the name argument (see
|
||||
// composeMachineFilename()).
|
||||
|
||||
osTypeId = System.getProperty("test." + provider + ".osTypeId", ""); // Guest OS Type ID.
|
||||
vmId = System.getProperty("test." + provider + ".vmId", null); // Machine UUID (optional).
|
||||
forceOverwrite = true; // If true, an existing machine settings file will be overwritten.
|
||||
osTypeId = System.getProperty("test." + provider + ".osTypeId", ""); // Guest
|
||||
// OS
|
||||
// Type
|
||||
// ID.
|
||||
vmId = System.getProperty("test." + provider + ".vmId", null); // Machine
|
||||
// UUID
|
||||
// (optional).
|
||||
forceOverwrite = true; // If true, an existing machine settings file will
|
||||
// be overwritten.
|
||||
vmName = System.getProperty("test." + provider + ".vmname", "jclouds-virtualbox-admin");
|
||||
|
||||
workingDir = System.getProperty("user.home") + File.separator + System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test") ;
|
||||
if(new File(workingDir).mkdir());
|
||||
workingDir = System.getProperty("user.home") + File.separator
|
||||
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
|
||||
if (new File(workingDir).mkdir())
|
||||
;
|
||||
vdiName = System.getProperty("test." + provider + ".vdiName", "centos-5.2-x86.7z");
|
||||
vdiUrl = System.getProperty("test." + provider + ".vdiUrl", "http://leaseweb.dl.sourceforge.net/project/virtualboximage/CentOS/5.2/centos-5.2-x86.7z");
|
||||
vdiUrl = System.getProperty("test." + provider + ".vdiUrl",
|
||||
"http://leaseweb.dl.sourceforge.net/project/virtualboximage/CentOS/5.2/centos-5.2-x86.7z");
|
||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||
gaIsoUrl = System.getProperty("test." + provider + ".gaIsoUrl", "http://download.virtualbox.org/virtualbox/4.0.2/VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||
vboxwebsrvStartCommand = System.getProperty("test." + provider + ".vboxwebsrvStartCommand","/usr/bin/vboxwebsrv");
|
||||
originalDisk = workingDir + File.separator + "VDI" +File.separator + System.getProperty("test." + provider + ".originalDisk", "centos-5.2-x86.vdi");
|
||||
gaIsoUrl = System.getProperty("test." + provider + ".gaIsoUrl",
|
||||
"http://download.virtualbox.org/virtualbox/4.0.2/VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||
vboxwebsrvStartCommand = System
|
||||
.getProperty("test." + provider + ".vboxwebsrvStartCommand", "/usr/bin/vboxwebsrv");
|
||||
originalDisk = workingDir + File.separator + "VDI" + File.separator
|
||||
+ System.getProperty("test." + provider + ".originalDisk", "centos-5.2-x86.vdi");
|
||||
clonedDisk = workingDir + File.separator + System.getProperty("test." + provider + ".clonedDisk", "template.vdi");
|
||||
guestAdditionsDvdName = workingDir + File.separator + System.getProperty("test." + provider + ".guestAdditionsDvdName", "VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||
guestAdditionsDvdName = workingDir
|
||||
+ File.separator
|
||||
+ System.getProperty("test." + provider + ".guestAdditionsDvdName",
|
||||
"VBoxGuestAdditions_4.0.2-update-69551.iso");
|
||||
|
||||
install7zip = System.getProperty("test." + provider + ".install7zip", "sudo -S apt-get --yes install p7zip");
|
||||
run7zip = System.getProperty("test." + provider + ".run7zip", "p7zip -d ");
|
||||
installVboxOse = System.getProperty("test." + provider + ".installvboxose", "sudo -S apt-get --yes install virtualbox-ose");
|
||||
if(!new File(originalDisk).exists()) {
|
||||
installVboxOse = System.getProperty("test." + provider + ".installvboxose",
|
||||
"sudo -S apt-get --yes install virtualbox-ose");
|
||||
if (!new File(originalDisk).exists()) {
|
||||
IPSocket socket = new IPSocket("127.0.0.1", 22);
|
||||
socketTester.apply(socket);
|
||||
SshClient client = sshFactory.create(socket, new Credentials(hostUsername, hostPassword));
|
||||
try {
|
||||
File vdi7z = downloadFile(vdiUrl, workingDir, vdiName, null);
|
||||
client.connect();
|
||||
ExecResponse exec = client.exec("echo " + admin_pwd + " | " + install7zip + "; cd " + workingDir + "; " + run7zip + vdi7z.getName());
|
||||
ExecResponse exec = client.exec("echo " + admin_pwd + " | " + install7zip + "; cd " + workingDir + "; "
|
||||
+ run7zip + vdi7z.getName());
|
||||
System.out.println(exec);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -182,7 +227,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
if(!new File(guestAdditionsDvdName).exists()) {
|
||||
if (!new File(guestAdditionsDvdName).exists()) {
|
||||
try {
|
||||
File gaIso = downloadFile(gaIsoUrl, workingDir, gaIsoName, null);
|
||||
} catch (Exception e) {
|
||||
|
@ -197,11 +242,10 @@ public class VirtualboxAdministrationLiveTest {
|
|||
hostUsername = System.getProperty("test." + provider + ".hostusername", "toor");
|
||||
hostPassword = System.getProperty("test." + provider + ".hostpassword", "password");
|
||||
|
||||
injector = Guice.createInjector(new SshjSshClientModule(),
|
||||
new SLF4JLoggingModule(), new BouncyCastleCryptoModule());
|
||||
injector = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule(),
|
||||
new BouncyCastleCryptoModule());
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(
|
||||
new InetSocketAddressConnect(), 3600, 1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 3600, 1, TimeUnit.SECONDS);
|
||||
injector.injectMembers(socketTester);
|
||||
|
||||
setupCredentials();
|
||||
|
@ -231,13 +275,14 @@ public class VirtualboxAdministrationLiveTest {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param command absolute path to command. For ubuntu 10.04: /usr/bin/vboxwebsrv
|
||||
* @param command
|
||||
* absolute path to command. For ubuntu 10.04: /usr/bin/vboxwebsrv
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void startupVboxWebServer(String command) throws IOException, InterruptedException {
|
||||
// Disable login credential: $
|
||||
//rt.exec("VBoxManage setproperty websrvauthlibrary null");
|
||||
// rt.exec("VBoxManage setproperty websrvauthlibrary null");
|
||||
IPSocket socket = new IPSocket("127.0.0.1", 22);
|
||||
socketTester.apply(socket);
|
||||
SshClient client = sshFactory.create(socket, new Credentials(hostUsername, hostPassword));
|
||||
|
@ -255,22 +300,19 @@ public class VirtualboxAdministrationLiveTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@BeforeMethod
|
||||
protected void setupManager() {
|
||||
manager.connect(endpoint, identity, credential);
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
protected void disconnectAndClenaupManager() throws RemoteException,
|
||||
MalformedURLException {
|
||||
protected void disconnectAndClenaupManager() throws RemoteException, MalformedURLException {
|
||||
manager.disconnect();
|
||||
manager.cleanup();
|
||||
}
|
||||
|
||||
public void testCreateVirtualMachine() {
|
||||
IMachine newVM = manager.getVBox().createMachine(settingsFile, vmName,
|
||||
osTypeId, vmId, forceOverwrite);
|
||||
IMachine newVM = manager.getVBox().createMachine(settingsFile, vmName, osTypeId, vmId, forceOverwrite);
|
||||
manager.getVBox().registerMachine(newVM);
|
||||
assertEquals(newVM.getName(), vmName);
|
||||
}
|
||||
|
@ -285,8 +327,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
mutable.setMemorySize(memorySize);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(manager.getVBox().findMachine(vmName)
|
||||
.getMemorySize(), memorySize);
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getMemorySize(), memorySize);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testChangeRAM")
|
||||
|
@ -298,22 +339,19 @@ public class VirtualboxAdministrationLiveTest {
|
|||
mutable.addStorageController(controller, StorageBus.IDE);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
assertEquals(manager.getVBox().findMachine(vmName)
|
||||
.getStorageControllers().size(), 1);
|
||||
assertEquals(manager.getVBox().findMachine(vmName).getStorageControllers().size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateDiskController")
|
||||
public void testCloneAndAttachHardDisk() {
|
||||
IMedium hd = manager.getVBox().openMedium(originalDisk,
|
||||
DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
|
||||
IMedium hd = manager.getVBox().openMedium(originalDisk, DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
|
||||
IMedium clonedHd = null;
|
||||
if(!new File(clonedDisk).exists()) {
|
||||
if (!new File(clonedDisk).exists()) {
|
||||
clonedHd = manager.getVBox().createHardDisk(diskFormat, clonedDisk);
|
||||
IProgress cloning = hd.cloneTo(clonedHd, new Long(MediumVariant.VMDK_SPLIT_2_G.ordinal()), null);
|
||||
cloning.waitForCompletion(-1);
|
||||
} else
|
||||
clonedHd = manager.getVBox().openMedium(clonedDisk,
|
||||
DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
|
||||
clonedHd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
|
||||
|
||||
ISession session = manager.getSessionObject();
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
|
@ -335,7 +373,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
/*
|
||||
* NAT
|
||||
*/
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); not in 4.1
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); not in 4.1
|
||||
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
|
||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
||||
mutable.saveSettings();
|
||||
|
@ -343,8 +381,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
mutable = session.getMachine();
|
||||
machine.getNetworkAdapter(new Long(0))
|
||||
.getNatDriver()
|
||||
machine.getNetworkAdapter(new Long(0)).getNatDriver()
|
||||
.addRedirect("guestssh", NATProtocol.TCP, "127.0.0.1", 2222, "", 22);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
@ -355,10 +392,9 @@ public class VirtualboxAdministrationLiveTest {
|
|||
ISession session = manager.getSessionObject();
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
|
||||
IMedium guestAdditionsDVD = manager.getVBox().openMedium(guestAdditionsDvdName,
|
||||
DeviceType.DVD, AccessMode.ReadOnly, forceOverwrite);
|
||||
for (IStorageController storageController : machine
|
||||
.getStorageControllers()) {
|
||||
IMedium guestAdditionsDVD = manager.getVBox().openMedium(guestAdditionsDvdName, DeviceType.DVD,
|
||||
AccessMode.ReadOnly, forceOverwrite);
|
||||
for (IStorageController storageController : machine.getStorageControllers()) {
|
||||
// for DVD we choose IDE
|
||||
if (storageController.getName().equals(controller)) {
|
||||
|
||||
|
@ -366,8 +402,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
IMachine mutable = session.getMachine();
|
||||
|
||||
// IDE secondary slave [1:1]
|
||||
mutable.attachDevice(storageController.getName(),
|
||||
new Integer(1), new Integer(1), DeviceType.DVD,
|
||||
mutable.attachDevice(storageController.getName(), new Integer(1), new Integer(1), DeviceType.DVD,
|
||||
guestAdditionsDVD);
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
@ -409,7 +444,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
client.disconnect();
|
||||
}
|
||||
|
||||
//manually restart
|
||||
// manually restart
|
||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||
powerDownMachine(machine);
|
||||
launchVMProcess(machine, manager.getSessionObject());
|
||||
|
@ -418,7 +453,8 @@ public class VirtualboxAdministrationLiveTest {
|
|||
client = sshFactory.create(socket, new Credentials(osUsername, osPassword));
|
||||
try {
|
||||
client.connect();
|
||||
ExecResponse exec = client.exec("mkdir -p /media/cdrom; mount /dev/cdrom /media/cdrom; sh /media/cdrom/VBoxLinuxAdditions.run --nox11 force");
|
||||
ExecResponse exec = client
|
||||
.exec("mkdir -p /media/cdrom; mount /dev/cdrom /media/cdrom; sh /media/cdrom/VBoxLinuxAdditions.run --nox11 force");
|
||||
System.out.println(exec);
|
||||
exec = client.exec("echo '/usr/sbin/VBoxService' >> /etc/rc.d/rc.local");
|
||||
System.out.println(exec);
|
||||
|
@ -445,7 +481,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
progress.waitForCompletion(-1);
|
||||
machineSession.unlockMachine();
|
||||
|
||||
while(!machine.getSessionState().equals(SessionState.Unlocked)){
|
||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
||||
try {
|
||||
System.out.println("waiting for unlocking session - session state: " + machine.getSessionState());
|
||||
Thread.sleep(1000);
|
||||
|
@ -472,8 +508,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
||||
for (IStorageController storageController : machine
|
||||
.getStorageControllers()) {
|
||||
for (IStorageController storageController : machine.getStorageControllers()) {
|
||||
if (storageController.getName().equals(controller)) {
|
||||
session = manager.getSessionObject();
|
||||
machine.lockMachine(session, LockType.Write);
|
||||
|
@ -487,7 +522,7 @@ public class VirtualboxAdministrationLiveTest {
|
|||
}
|
||||
|
||||
@AfterClass
|
||||
void stopVboxWebServer() throws IOException{
|
||||
void stopVboxWebServer() throws IOException {
|
||||
// stop vbox web server
|
||||
IPSocket socket = new IPSocket("127.0.0.1", 22);
|
||||
socketTester.apply(socket);
|
||||
|
@ -502,5 +537,6 @@ public class VirtualboxAdministrationLiveTest {
|
|||
} finally {
|
||||
if (client != null)
|
||||
client.disconnect();
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.virtualbox.experiment;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -63,12 +81,15 @@ public class VirtualboxLiveTest {
|
|||
protected String controller;
|
||||
protected String diskFormat;
|
||||
|
||||
protected String settingsFile; // Fully qualified path where the settings file should be created, or NULL for a default
|
||||
protected String settingsFile; // Fully qualified path where the settings
|
||||
// file should be created, or NULL for a
|
||||
// default
|
||||
// folder and file based on the name argument (see composeMachineFilename()).
|
||||
|
||||
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 boolean forceOverwrite; // If true, an existing machine settings
|
||||
// file will be overwritten.
|
||||
|
||||
protected String workingDir;
|
||||
protected String originalDiskPath;
|
||||
|
@ -78,16 +99,24 @@ public class VirtualboxLiveTest {
|
|||
// storage format specified by ISystemProperties#defaultHardDiskFormat
|
||||
String format = "vdi";
|
||||
|
||||
protected int numberOfVirtualMachine ;
|
||||
protected int numberOfVirtualMachine;
|
||||
|
||||
@BeforeClass
|
||||
protected void setupConfigurationProperties() {
|
||||
//VBOX
|
||||
settingsFile = null; // Fully qualified path where the settings file should be created, or NULL for a default
|
||||
// folder and file based on the name argument (see composeMachineFilename()).
|
||||
osTypeId = System.getProperty("test." + provider + ".osTypeId", ""); // Guest OS Type ID.
|
||||
vmId = System.getProperty("test." + provider + ".vmId", null); // Machine UUID (optional).
|
||||
forceOverwrite = true; // If true, an existing machine settings file will be overwritten.
|
||||
// VBOX
|
||||
settingsFile = null; // Fully qualified path where the settings file
|
||||
// should be created, or NULL for a default
|
||||
// folder and file based on the name argument (see
|
||||
// composeMachineFilename()).
|
||||
osTypeId = System.getProperty("test." + provider + ".osTypeId", ""); // Guest
|
||||
// OS
|
||||
// Type
|
||||
// ID.
|
||||
vmId = System.getProperty("test." + provider + ".vmId", null); // Machine
|
||||
// UUID
|
||||
// (optional).
|
||||
forceOverwrite = true; // If true, an existing machine settings file will
|
||||
// be overwritten.
|
||||
|
||||
// OS specific information
|
||||
vmName = checkNotNull(System.getProperty("test." + provider + ".vmname"));
|
||||
|
@ -96,31 +125,26 @@ public class VirtualboxLiveTest {
|
|||
controller = System.getProperty("test." + provider + ".controller", "IDE Controller");
|
||||
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
|
||||
|
||||
workingDir = checkNotNull(
|
||||
System.getProperty("test." + provider + ".workingDir"));
|
||||
workingDir = checkNotNull(System.getProperty("test." + provider + ".workingDir"));
|
||||
|
||||
originalDiskPath = workingDir
|
||||
+ File.separator
|
||||
+ checkNotNull(System.getProperty("test." + provider
|
||||
+ ".originalDisk"));
|
||||
originalDiskPath = workingDir + File.separator
|
||||
+ checkNotNull(System.getProperty("test." + provider + ".originalDisk"));
|
||||
|
||||
numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider + ".numberOfVirtualMachine")));
|
||||
numberOfVirtualMachine = Integer.parseInt(checkNotNull(System.getProperty("test." + provider
|
||||
+ ".numberOfVirtualMachine")));
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
protected void setupCredentials() throws RemoteException,
|
||||
MalformedURLException {
|
||||
protected void setupCredentials() throws RemoteException, MalformedURLException {
|
||||
identity = System.getProperty("test." + provider + ".identity", "administrator");
|
||||
credential = System.getProperty("test." + provider + ".credential", "12345");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
|
||||
injector = Guice.createInjector(new SshjSshClientModule(),
|
||||
new SLF4JLoggingModule(), new BouncyCastleCryptoModule());
|
||||
injector = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule(),
|
||||
new BouncyCastleCryptoModule());
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(
|
||||
new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
|
||||
injector.injectMembers(socketTester);
|
||||
}
|
||||
|
||||
|
@ -130,8 +154,7 @@ public class VirtualboxLiveTest {
|
|||
}
|
||||
|
||||
@AfterMethod
|
||||
protected void disconnectAndClenaupManager() throws RemoteException,
|
||||
MalformedURLException {
|
||||
protected void disconnectAndClenaupManager() throws RemoteException, MalformedURLException {
|
||||
manager.disconnect();
|
||||
manager.cleanup();
|
||||
}
|
||||
|
@ -165,17 +188,16 @@ public class VirtualboxLiveTest {
|
|||
String command = "vboxmanage list bridgedifs";
|
||||
try {
|
||||
Process child = Runtime.getRuntime().exec(command);
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(child.getInputStream()));
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(child.getInputStream()));
|
||||
String line = "";
|
||||
boolean found = false;
|
||||
|
||||
while ( (line = bufferedReader.readLine()) != null && !found){
|
||||
while ((line = bufferedReader.readLine()) != null && !found) {
|
||||
|
||||
if(line.split(":")[0].contains("Name") ){
|
||||
if (line.split(":")[0].contains("Name")) {
|
||||
hostInterface = line.split(":")[1];
|
||||
}
|
||||
if( line.split(":")[0].contains("Status") && line.split(":")[1].contains("Up") ){
|
||||
if (line.split(":")[0].contains("Status") && line.split(":")[1].contains("Up")) {
|
||||
System.out.println("bridge: " + hostInterface.trim());
|
||||
found = true;
|
||||
}
|
||||
|
@ -185,16 +207,16 @@ public class VirtualboxLiveTest {
|
|||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO: lookup translations for 4.1 for the below
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToBridgedInterface();
|
||||
// mutable.getNetworkAdapter(new Long(0)).setHostInterface(hostInterface.trim());
|
||||
// TODO: lookup translations for 4.1 for the below
|
||||
// mutable.getNetworkAdapter(new Long(0)).attachToBridgedInterface();
|
||||
// mutable.getNetworkAdapter(new
|
||||
// Long(0)).setHostInterface(hostInterface.trim());
|
||||
mutable.getNetworkAdapter(new Long(0)).setEnabled(true);
|
||||
|
||||
mutable.saveSettings();
|
||||
session.unlockMachine();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param instanceName
|
||||
* @return
|
||||
|
@ -202,20 +224,24 @@ public class VirtualboxLiveTest {
|
|||
private IMedium cloneDisk(MediumType mediumType) {
|
||||
|
||||
String clonedDisk = System.getProperty("test." + provider + ".clonedDisk");
|
||||
String instanceClonedDisk = clonedDisk.split("\\.")[0] + "." +clonedDisk.split("\\.")[1];
|
||||
String instanceClonedDisk = clonedDisk.split("\\.")[0] + "." + clonedDisk.split("\\.")[1];
|
||||
clonedDiskPath = workingDir + File.separator + instanceClonedDisk;
|
||||
|
||||
// use template disk in multiattach mode
|
||||
IMedium clonedHd = manager.getVBox().openMedium(originalDiskPath, DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
|
||||
IMedium clonedHd = manager.getVBox().openMedium(originalDiskPath, DeviceType.HardDisk, AccessMode.ReadOnly,
|
||||
forceOverwrite);
|
||||
|
||||
System.out.println("cloned HD state: " + clonedHd.getState());
|
||||
/*
|
||||
An image in multiattach mode can be attached to more than one virtual machine at the same time,
|
||||
even if these machines are running simultaneously. For each virtual machine to which such an image is attached, a differencing image
|
||||
is created. As a result, data that is written to such a virtual disk by one machine is not
|
||||
seen by the other machines to which the image is attached; each machine creates its own write history of the multiattach image.
|
||||
* An image in multiattach mode can be attached to more than one virtual
|
||||
* machine at the same time, even if these machines are running
|
||||
* simultaneously. For each virtual machine to which such an image is
|
||||
* attached, a differencing image is created. As a result, data that is
|
||||
* written to such a virtual disk by one machine is not seen by the other
|
||||
* machines to which the image is attached; each machine creates its own
|
||||
* write history of the multiattach image.
|
||||
*/
|
||||
while(clonedHd.getState().equals(MediumState.NOT_CREATED)) {
|
||||
while (clonedHd.getState().equals(MediumState.NOT_CREATED)) {
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -235,8 +261,7 @@ public class VirtualboxLiveTest {
|
|||
|
||||
protected void checkSSH(IPSocket socket) {
|
||||
socketTester.apply(socket);
|
||||
SshClient client = sshFactory.create(socket, new Credentials(
|
||||
osUsername, osPassword));
|
||||
SshClient client = sshFactory.create(socket, new Credentials(osUsername, osPassword));
|
||||
try {
|
||||
client.connect();
|
||||
ExecResponse exec = client.exec("touch /tmp/hello_" + System.currentTimeMillis());
|
||||
|
@ -252,14 +277,14 @@ public class VirtualboxLiveTest {
|
|||
@Test(dependsOnMethods = "testStartVirtualMachines")
|
||||
public void testSshLogin() {
|
||||
String ipAddress = null;
|
||||
for (int i = 1; i < numberOfVirtualMachine +1; i++) {
|
||||
for (int i = 1; i < numberOfVirtualMachine + 1; i++) {
|
||||
String instanceName = vmName + "_" + i;
|
||||
IMachine machine = manager.getVBox().findMachine(instanceName);
|
||||
|
||||
System.out.println("\nLaunch VM named " + machine.getName() + " ...");
|
||||
launchVMProcess(machine, manager.getSessionObject());
|
||||
|
||||
while(ipAddress==null || ipAddress.equals("")){
|
||||
while (ipAddress == null || ipAddress.equals("")) {
|
||||
try {
|
||||
ipAddress = machine.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/0/V4/IP");
|
||||
Thread.sleep(1000);
|
||||
|
@ -287,8 +312,7 @@ public class VirtualboxLiveTest {
|
|||
progress.waitForCompletion(-1);
|
||||
machineSession.unlockMachine();
|
||||
|
||||
|
||||
while(!machine.getSessionState().equals(SessionState.Unlocked)){
|
||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
||||
try {
|
||||
System.out.println("waiting for unlocking session - session state: " + machine.getSessionState());
|
||||
Thread.sleep(1000);
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.virtualbox.experiment.settings;
|
||||
|
||||
import java.util.Collections;
|
||||
|
|
Loading…
Reference in New Issue