Issue 384: switched to vbox 4.1, cleaned up shell commands with byon, fixed so starts to work on osx

This commit is contained in:
Adrian Cole 2011-07-27 02:31:10 -07:00
parent d991f3a83c
commit 5243790801
6 changed files with 439 additions and 427 deletions

View File

@ -1,128 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2011 Cloud Conscious, LLC <info@cloudconscious.com>
====================================================================
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.html
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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>virtualbox</artifactId>
<name>jclouds components for a virtualbox provider</name>
<properties>
<test.virtualbox.endpoint>test:///default</test.virtualbox.endpoint>
<test.virtualbox.apiversion>1.0</test.virtualbox.apiversion>
<test.virtualbox.identity>FIXME</test.virtualbox.identity>
<test.virtualbox.credential>FIXME</test.virtualbox.credential>
</properties>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.clojars.tbatchelli</groupId>
<artifactId>vboxjws</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.jponge</groupId>
<artifactId>lzma-java</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.virtualbox.endpoint>${test.virtualbox.endpoint}</test.virtualbox.endpoint>
<test.virtualbox.apiversion>${test.virtualbox.apiversion}</test.virtualbox.apiversion>
<test.virtualbox.identity>${test.virtualbox.identity}</test.virtualbox.identity>
<test.virtualbox.credential>${test.virtualbox.credential}</test.virtualbox.credential>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>virtualbox</artifactId>
<name>jcloud virtualbox api</name>
<description>jclouds components to access an implementation of virtualbox</description>
<packaging>bundle</packaging>
<properties>
<test.virtualbox.endpoint>http://localhost:18083/</test.virtualbox.endpoint>
<test.virtualbox.apiversion>4.1.0r73009</test.virtualbox.apiversion>
<test.virtualbox.identity>administrator</test.virtualbox.identity>
<test.virtualbox.credential>12345</test.virtualbox.credential>
</properties>
<repositories>
<repository>
<id>temporary</id>
<url>https://jclouds.googlecode.com/svn/repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.virtualbox</groupId>
<artifactId>vboxjws</artifactId>
<version>${test.virtualbox.apiversion}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>byon</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.jponge</groupId>
<artifactId>lzma-java</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.29</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.virtualbox.endpoint</name>
<value>${test.virtualbox.endpoint}</value>
</property>
<property>
<name>test.virtualbox.apiversion</name>
<value>${test.virtualbox.apiversion}</value>
</property>
<property>
<name>test.virtualbox.identity</name>
<value>${test.virtualbox.identity}</value>
</property>
<property>
<name>test.virtualbox.credential</name>
<value>${test.virtualbox.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>org.jclouds.virtualbox.*;version="${project.version}"</Export-Package>
<Import-Package>org.jclouds.*;version="${project.version}",*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,50 @@
package org.jclouds.virtualbox.experiment;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
public class TestUtils {
public static ComputeServiceContext computeServiceForLocalhost() throws FileNotFoundException, IOException {
Properties contextProperties = new Properties();
StringBuilder nodes = new StringBuilder();
nodes.append("nodes:\n");
nodes.append(" - id: host\n");
nodes.append(" name: host installing virtualbox\n");
nodes.append(" hostname: localhost\n");
nodes.append(" os_family: ").append(OsFamily.LINUX).append("\n");
nodes.append(" os_description: ").append(System.getProperty("os.name")).append("\n");
nodes.append(" os_version: ").append(System.getProperty("os.version")).append("\n");
nodes.append(" group: ").append("ssh").append("\n");
nodes.append(" username: ").append(System.getProperty("user.name")).append("\n");
nodes.append(" credential_url: file://").append(System.getProperty("user.home")).append("/.ssh/id_rsa")
.append("\n");
nodes.append("\n");
nodes.append(" - id: guest\n");
nodes.append(" name: new guest\n");
nodes.append(" hostname: localhost\n");
nodes.append(" login_port: 2222\n");
nodes.append(" os_family: ubuntu").append("\n");
nodes.append(" os_description: ubuntu/11.04").append("\n");
nodes.append(" os_version: 11.04").append("\n");
nodes.append(" group: guest").append("\n");
nodes.append(" username: toor").append("\n");
nodes.append(" credential: password").append("\n");
contextProperties.setProperty("byon.nodes", nodes.toString());
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule()), contextProperties);
}
}

View File

@ -1,20 +1,18 @@
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;
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
import static org.testng.Assert.assertEquals;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.net.URI;
import java.rmi.RemoteException;
import java.util.concurrent.TimeUnit;
@ -23,43 +21,39 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.log.Log;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.util.Strings2;
import org.jclouds.virtualbox.experiment.settings.KeyboardScancodes;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.virtualbox_4_0.AccessMode;
import org.virtualbox_4_0.DeviceType;
import org.virtualbox_4_0.IMachine;
import org.virtualbox_4_0.IMedium;
import org.virtualbox_4_0.IProgress;
import org.virtualbox_4_0.ISession;
import org.virtualbox_4_0.IStorageController;
import org.virtualbox_4_0.LockType;
import org.virtualbox_4_0.MachineState;
import org.virtualbox_4_0.NATProtocol;
import org.virtualbox_4_0.SessionState;
import org.virtualbox_4_0.StorageBus;
import org.virtualbox_4_0.VirtualBoxManager;
import org.virtualbox_4_0.jaxws.MediumVariant;
import org.virtualbox_4_1.AccessMode;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.IStorageController;
import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.NATProtocol;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VirtualBoxManager;
import org.virtualbox_4_1.jaxws.MediumVariant;
import com.google.common.base.Predicate;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables;
@Test(groups = "live", testName = "virtualbox.VirtualboxAdministrationKickstartTest")
public class VirtualboxAdministrationKickstartTest {
@ -67,15 +61,13 @@ public class VirtualboxAdministrationKickstartTest {
protected String provider = "virtualbox";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected URI endpoint;
protected String apiVersion;
protected String vmName;
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
protected Injector injector;
protected Predicate<IPSocket> socketTester;
protected SshClient.Factory sshFactory;
protected String settingsFile; // Fully qualified path where the settings
protected String osTypeId; // Guest OS Type ID.
@ -88,46 +80,39 @@ public class VirtualboxAdministrationKickstartTest {
protected String clonedDisk;
protected String guestAdditionsDvd;
private String gaIsoUrl;
private String vboxwebsrvStartCommand;
private URI gaIsoUrl;
private String gaIsoName;
private String installVboxOse;
private String distroIsoUrl;
private URI distroIsoUrl;
private String distroIsoName;
private String distroDvd;
private String controllerIDE;
private String controllerSATA;
private String keyboardSequence;
private String admin_pwd;
private String vdiName;
private String preseedUrl;
protected Server server = null;
private String vboxManageCommand;
private String sshHost;
private String sshPort;
private String sshUser;
private String sshPass;
private String sshKeyFile;
protected void setupCredentials() {
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");
}
private ComputeServiceContext context;
private String hostId = "host";
private String guestId = "guest";
private String majorVersion;
private String minorVersion;
protected void setupCredentials() {
identity = System.getProperty("test." + provider + ".identity", "administrator");
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);
}
protected Logger logger() {
return context.utils().loggerFactory().getLogger("jclouds.compute");
}
protected void setupConfigurationProperties() {
sshHost = System.getProperty("test.ssh.host", "localhost");
sshPort = System.getProperty("test.ssh.port", "22");
sshUser = System.getProperty("test.ssh.username", "toor");
sshPass = System.getProperty("test.ssh.password", "password");
sshKeyFile = System.getProperty("test.ssh.keyfile");
admin_pwd = System.getProperty("test." + provider + ".admin_pwd", "password");
controllerIDE = System.getProperty("test." + provider + ".controllerIde", "IDE Controller");
controllerSATA = System.getProperty("test." + provider + ".controllerSata", "SATA Controller");
diskFormat = System.getProperty("test." + provider + ".diskformat", "");
@ -144,28 +129,22 @@ public class VirtualboxAdministrationKickstartTest {
if (new File(workingDir).mkdir())
;
vdiName = System.getProperty("test." + provider + ".vdiName", "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");
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 = System
distroIsoUrl = URI.create(System
.getProperty("test." + provider + ".distroIsoUrl",
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso");
installVboxOse = System.getProperty("test." + provider
+ ".installvboxose",
"sudo -S apt-get --yes install virtualbox-ose");
"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_4.0.2-update-69551.iso");
"VBoxGuestAdditions_"+majorVersion+"-update-"+minorVersion+".iso");
distroDvd = workingDir + File.separator + System.getProperty("test." + provider + ".distroDvd",
distroIsoName);
preseedUrl = System.getProperty("test." + provider + ".preseedurl",
"http://dl.dropbox.com/u/693111/preseed.cfg");
@ -180,51 +159,23 @@ public class VirtualboxAdministrationKickstartTest {
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
+ "initrd=/install/initrd.gz -- <Enter>");
vboxwebsrvStartCommand = System.getProperty("test." + provider
+ ".vboxwebsrvStartCommand", "/usr/bin/vboxwebsrv");
vboxManageCommand = System.getProperty("test." + provider
+ ".vboxmanage", "VBoxManage");
if (!new File(distroDvd).exists()) {
try {
downloadFile(distroIsoUrl, workingDir, distroIsoName, null);
} catch (Exception e) {
e.printStackTrace();
}
}
if (!new File(guestAdditionsDvd).exists()) {
try {
downloadFile(gaIsoUrl, workingDir, gaIsoName, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@BeforeGroups(groups = "live")
protected void setupClient() throws IOException, InterruptedException {
injector = Guice.createInjector(new SshjSshClientModule(),
new Log4JLoggingModule());
sshFactory = injector.getInstance(SshClient.Factory.class);
socketTester = new RetryablePredicate<IPSocket>(
injector.getInstance(SocketOpen.class), 130, 10,
protected void setupClient() throws Exception {
context = TestUtils.computeServiceForLocalhost();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 130, 10,
TimeUnit.SECONDS);
injector.injectMembers(socketTester);
setupCredentials();
setupConfigurationProperties();
downloadFileUnlessPresent(distroIsoUrl, workingDir, distroIsoName);
downloadFileUnlessPresent(gaIsoUrl, workingDir, gaIsoName);
installVbox();
// startup vbox web server
startupVboxWebServer(vboxwebsrvStartCommand);
checkVboxVersionExpected();
if (!new InetSocketAddressConnect().apply(new IPSocket(endpoint.getHost(), endpoint.getPort())))
startupVboxWebServer();
// configure and startup jetty HTTP server
try {
configureJettyServer();
} catch (Exception e) {
propagate(e);
}
configureJettyServer();
}
private void configureJettyServer() throws Exception {
@ -235,57 +186,59 @@ public class VirtualboxAdministrationKickstartTest {
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase(".");
Log.info("serving " + resource_handler.getBaseResource());
logger().info("serving " + resource_handler.getBaseResource());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler,
new DefaultHandler() });
server.setHandler(handlers);
// server.start();
// server.join();
server.start();
}
private void installVbox() throws IOException, InterruptedException {
SshClient client = setupSshClient();
try {
client.exec("echo " + sshPass + " | " + installVboxOse);
} catch (Exception e) {
System.out
.println("It is impossible to install virtualbox with this command "
+ installVboxOse);
} finally {
if (client != null)
client.disconnect();
}
}
void installVbox() throws IOException, InterruptedException {
if (runScriptOnNode(hostId, "VBoxManage -version").getExitCode() != 0) {
logger().debug("installing virtualbox");
if (isOSX(hostId))
;// TODO
else
runScriptOnNode(hostId, "apt-get --yes install virtualbox-ose");
// TODO other platforms
}
}
/**
*
* @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");
SshClient client = setupSshClient();
try {
ExecResponse response = client.exec(command + " -t 0 -b");
} catch (Exception e) {
propagate(e);
} finally {
if (client != null)
client.disconnect();
}
}
void checkVboxVersionExpected() throws IOException, InterruptedException {
logger().debug("checking virtualbox version");
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
}
/**
*
* @param command
* absolute path to command. For ubuntu 10.04: /usr/bin/vboxwebsrv
* @throws IOException
* @throws InterruptedException
*/
void startupVboxWebServer() {
logger().debug("disabling password access");
runScriptOnNode(hostId, "VBoxManage setproperty websrvauthlibrary null");
logger().debug("starting vboxwebsrv");
String vboxwebsrv = "vboxwebsrv -t 5 -v";
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
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");
}
@BeforeMethod
protected void setupManager() {
manager.connect(endpoint, identity, credential);
manager.connect(endpoint.toASCIIString(), identity, credential);
}
@AfterMethod
@ -339,7 +292,7 @@ public class VirtualboxAdministrationKickstartTest {
MediumVariant.VMDK_SPLIT_2_G.ordinal()));
} else
hd = manager.getVBox().openMedium(clonedDisk, DeviceType.HardDisk,
AccessMode.ReadWrite);
AccessMode.ReadWrite, forceOverwrite);
ISession session = manager.getSessionObject();
IMachine machine = manager.getVBox().findMachine(vmName);
machine.lockMachine(session, LockType.Write);
@ -359,7 +312,7 @@ public class VirtualboxAdministrationKickstartTest {
// network BRIDGED to access HTTP server
String hostInterface = null;
String command = vboxManageCommand + " list bridgedifs";
String command = "VBoxManage list bridgedifs";
try {
Process child = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(
@ -380,7 +333,7 @@ public class VirtualboxAdministrationKickstartTest {
}
// NAT
mutable.getNetworkAdapter(new Long(0)).attachToNAT();
// mutable.getNetworkAdapter(new Long(0)).attachToNAT(); TODO: this no longer exists!
mutable.getNetworkAdapter(new Long(0)).setNATNetwork("");
machine.getNetworkAdapter(new Long(0))
.getNatDriver()
@ -397,7 +350,7 @@ public class VirtualboxAdministrationKickstartTest {
}
@Test(dependsOnMethods = "testConfigureNIC")
public void testStartVirtualMachine() {
public void testStartVirtualMachine() throws InterruptedException {
IMachine machine = manager.getVBox().findMachine(vmName);
ISession session = manager.getSessionObject();
launchVMProcess(machine, session);
@ -412,37 +365,11 @@ public class VirtualboxAdministrationKickstartTest {
}
@Test(dependsOnMethods = "testStartVirtualMachine")
public void testConfigureGuestAdditions() throws FileNotFoundException,
IOException {
IPSocket socket = new IPSocket(sshHost, 2222);
System.out.printf("%d: %s awaiting ssh service to start%n",
System.currentTimeMillis(), socket);
assert socketTester.apply(socket);
System.out.printf("%d: %s ssh service started%n",
System.currentTimeMillis(), socket);
// configure GA
SshClient client = setupSshClient();
try {
// Configure your system for building kernel modules by running
ExecResponse exec = client.exec("echo " + sshPass + " | " + "sudo -S m-a prepare -i");
System.out.println(exec);
} finally {
if (client != null) {
client.disconnect();
}
}
try {
ExecResponse exec = client.exec("echo " + sshPass + " | "
+ "sudo -S mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
System.out.println(exec);
exec = client.exec("echo " + sshPass + " | " + "sudo -S sh /mnt/VBoxLinuxAdditions.run");
System.out.println(exec);
} finally {
if (client != null)
client.disconnect();
}
public void testConfigureGuestAdditions() {
// Configure your system for building kernel modules by running
runScriptOnNode(guestId, "m-a prepare -i");
runScriptOnNode(guestId, "mount -o loop /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt");
runScriptOnNode(guestId, "/mnt/VBoxLinuxAdditions.run");
}
@Test(dependsOnMethods = "testConfigureGuestAdditions")
@ -506,81 +433,51 @@ public class VirtualboxAdministrationKickstartTest {
@AfterClass
void stopVboxWebServer() throws IOException {
// stop vbox web server
SshClient client = setupSshClient();
try {
ExecResponse exec = client.exec("pidof vboxwebsrv | xargs kill");
System.out.println(exec.getOutput());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (client != null)
client.disconnect();
}
runScriptOnNode(guestId, "pidof vboxwebsrv | xargs kill");
}
/**
*
* @param workingDir
* @param vdiUrl
* @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 {
protected ExecResponse runScriptOnNode(String nodeId, String command, RunScriptOptions options) {
ExecResponse toReturn = context.getComputeService().runScriptOnNode(nodeId, command, options);
assert toReturn.getExitCode() == 0: toReturn;
return toReturn;
}
protected ExecResponse runScriptOnNode(String nodeId, String command) {
return runScriptOnNode(nodeId, command, wrapInInitScript(false));
}
String absolutePathName = destinationDir + File.separator
+ vboxGuestAdditionsName;
File iso = new File(absolutePathName);
private File downloadFileUnlessPresent(URI sourceURL, String destinationDir,
String filename) throws Exception {
final URL isoURL = new URL(sourceURL);
final HttpURLConnection uc = (HttpURLConnection) isoURL
.openConnection(); // isoURL.openConnection(proxy);
uc.connect();
File iso = new File(destinationDir, filename);
if (!iso.exists()) {
System.out.println("Start download " + sourceURL + " to "
+ absolutePathName);
Files.copy(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return uc.getInputStream();
}
}, iso);
InputStream is = context.utils().http().get(sourceURL);
checkNotNull(is, "%s not found", sourceURL);
try {
ByteStreams.copy(is, new FileOutputStream(iso));
} finally {
Closeables.closeQuietly(is);
}
}
return iso;
}
private void sendKeyboardSequence(String keyboardSequence) {
private void sendKeyboardSequence(String keyboardSequence) throws InterruptedException {
String[] sequenceSplited = keyboardSequence.split(" ");
SshClient client = null;
try {
client = setupSshClient();
for (String word : sequenceSplited) {
String converted = stringToKeycode(word);
for (String string : converted.split(" ")) {
ExecResponse response = client.exec(vboxManageCommand
+ " controlvm " + vmName + " keyboardputscancode "
runScriptOnNode(hostId , "VBoxManage controlvm " + vmName + " keyboardputscancode "
+ string);
System.out.println(response.getOutput());
if (converted
.contains(KeyboardScancodes.SPECIAL_KEYBOARD_BUTTON_MAP
.get("<Return>")))
Thread.sleep(180);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (client != null)
client.disconnect();
}
}
private String stringToKeycode(String s) {
@ -619,24 +516,4 @@ public class VirtualboxAdministrationKickstartTest {
prog.waitForCompletion(-1);
session.unlockMachine();
}
private SshClient setupSshClient() throws FileNotFoundException,
IOException {
int port = Integer.parseInt(sshPort);
Injector i = Guice.createInjector(new SshjSshClientModule());
SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection;
if (sshKeyFile != null && !sshKeyFile.trim().equals("")) {
connection = factory
.create(new IPSocket(sshHost, port),
new Credentials(sshUser, Strings2
.toStringAndClose(new FileInputStream(
sshKeyFile))));
} else {
connection = factory.create(new IPSocket(sshHost, port),
new Credentials(sshUser, sshPass));
}
connection.connect();
return connection;
}
}

View File

@ -14,7 +14,8 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
@ -25,20 +26,20 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.virtualbox_4_0.AccessMode;
import org.virtualbox_4_0.DeviceType;
import org.virtualbox_4_0.IMachine;
import org.virtualbox_4_0.IMedium;
import org.virtualbox_4_0.IProgress;
import org.virtualbox_4_0.ISession;
import org.virtualbox_4_0.IStorageController;
import org.virtualbox_4_0.LockType;
import org.virtualbox_4_0.MachineState;
import org.virtualbox_4_0.NATProtocol;
import org.virtualbox_4_0.SessionState;
import org.virtualbox_4_0.StorageBus;
import org.virtualbox_4_0.VirtualBoxManager;
import org.virtualbox_4_0.jaxws.MediumVariant;
import org.virtualbox_4_1.AccessMode;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.IStorageController;
import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.NATProtocol;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VirtualBoxManager;
import org.virtualbox_4_1.jaxws.MediumVariant;
import com.google.common.base.Predicate;
import com.google.common.io.Files;
@ -196,8 +197,8 @@ public class VirtualboxAdministrationTest {
hostUsername = System.getProperty("test." + provider + ".hostusername", "toor");
hostPassword = System.getProperty("test." + provider + ".hostpassword", "password");
injector = Guice.createInjector(new SshjSshClientModule(),
new Log4JLoggingModule());
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);
@ -304,7 +305,7 @@ public class VirtualboxAdministrationTest {
@Test(dependsOnMethods = "testCreateDiskController")
public void testCloneAndAttachHardDisk() {
IMedium hd = manager.getVBox().openMedium(originalDisk,
DeviceType.HardDisk, AccessMode.ReadOnly);
DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
IMedium clonedHd = null;
if(!new File(clonedDisk).exists()) {
clonedHd = manager.getVBox().createHardDisk(diskFormat, clonedDisk);
@ -312,7 +313,7 @@ public class VirtualboxAdministrationTest {
cloning.waitForCompletion(-1);
} else
clonedHd = manager.getVBox().openMedium(clonedDisk,
DeviceType.HardDisk, AccessMode.ReadOnly);
DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
ISession session = manager.getSessionObject();
IMachine machine = manager.getVBox().findMachine(vmName);
@ -334,7 +335,7 @@ public class VirtualboxAdministrationTest {
/*
* NAT
*/
mutable.getNetworkAdapter(new Long(0)).attachToNAT();
// 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();
@ -355,7 +356,7 @@ public class VirtualboxAdministrationTest {
IMachine machine = manager.getVBox().findMachine(vmName);
IMedium guestAdditionsDVD = manager.getVBox().openMedium(guestAdditionsDvdName,
DeviceType.DVD, AccessMode.ReadOnly);
DeviceType.DVD, AccessMode.ReadOnly, forceOverwrite);
for (IStorageController storageController : machine
.getStorageControllers()) {
// for DVD we choose IDE

View File

@ -13,7 +13,8 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
@ -23,19 +24,19 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.virtualbox_4_0.AccessMode;
import org.virtualbox_4_0.DeviceType;
import org.virtualbox_4_0.IMachine;
import org.virtualbox_4_0.IMedium;
import org.virtualbox_4_0.IProgress;
import org.virtualbox_4_0.ISession;
import org.virtualbox_4_0.LockType;
import org.virtualbox_4_0.MachineState;
import org.virtualbox_4_0.MediumType;
import org.virtualbox_4_0.SessionState;
import org.virtualbox_4_0.StorageBus;
import org.virtualbox_4_0.VirtualBoxManager;
import org.virtualbox_4_0.jaxws.MediumState;
import org.virtualbox_4_1.AccessMode;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.MediumType;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VirtualBoxManager;
import org.virtualbox_4_1.jaxws.MediumState;
import com.google.common.base.Predicate;
import com.google.inject.Guice;
@ -115,8 +116,8 @@ public class VirtualboxLiveTest {
endpoint = System.getProperty("test." + provider + ".endpoint", "http://localhost:18083/");
apiversion = System.getProperty("test." + provider + ".apiversion");
injector = Guice.createInjector(new SshjSshClientModule(),
new Log4JLoggingModule());
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);
@ -184,8 +185,9 @@ public class VirtualboxLiveTest {
// TODO Auto-generated catch block
e.printStackTrace();
}
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();
@ -204,7 +206,7 @@ public class VirtualboxLiveTest {
clonedDiskPath = workingDir + File.separator + instanceClonedDisk;
// use template disk in multiattach mode
IMedium clonedHd = manager.getVBox().openMedium(originalDiskPath, DeviceType.HardDisk, AccessMode.ReadOnly);
IMedium clonedHd = manager.getVBox().openMedium(originalDiskPath, DeviceType.HardDisk, AccessMode.ReadOnly, forceOverwrite);
System.out.println("cloned HD state: " + clonedHd.getState());
/*

View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<configuration scan="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} - %msg%n</pattern>
</encoder>
</appender>
<!-- turn OFF all logging (children can override) -->
<root level="OFF">
<appender-ref ref="STDOUT"/>
</root>
<logger name="jclouds.compute" level="debug"/>
<logger name="jclouds.headers" level="debug"/>
<logger name="jclouds.ssh" level="debug"/>
</configuration>