Merge pull request #415 from dralves/jclouds-vbox-0conf

fetching master at startup so that we make sure that isos are downloaded...
This commit is contained in:
Adrian Cole 2012-03-09 16:56:16 -08:00
commit 4cc5e03ae8
7 changed files with 32 additions and 88 deletions

View File

@ -40,11 +40,9 @@
<test.virtualbox.build-version>4.1.8r75467</test.virtualbox.build-version> <test.virtualbox.build-version>4.1.8r75467</test.virtualbox.build-version>
<test.virtualbox.identity>administrator</test.virtualbox.identity> <test.virtualbox.identity>administrator</test.virtualbox.identity>
<test.virtualbox.credential>12345</test.virtualbox.credential> <test.virtualbox.credential>12345</test.virtualbox.credential>
<test.virtualbox.image-id>ubuntu-11.04-server-i386</test.virtualbox.image-id> <test.virtualbox.image-id>default-ubuntu-11.04-i386</test.virtualbox.image-id>
<test.virtualbox.image.login-user>toor:password</test.virtualbox.image.login-user> <test.virtualbox.image.login-user>toor:password</test.virtualbox.image.login-user>
<test.virtualbox.image.authenticate-sudo>true</test.virtualbox.image.authenticate-sudo> <test.virtualbox.image.authenticate-sudo>true</test.virtualbox.image.authenticate-sudo>
<test.virtualbox.image.authenticate-sudo>true</test.virtualbox.image.authenticate-sudo>
<test.virtualbox.image.descriptor.yaml>target/test-classes/testImages.yaml</test.virtualbox.image.descriptor.yaml>
</properties> </properties>
<dependencies> <dependencies>
@ -147,7 +145,6 @@
<test.virtualbox.image-id>${test.virtualbox.image-id}</test.virtualbox.image-id> <test.virtualbox.image-id>${test.virtualbox.image-id}</test.virtualbox.image-id>
<test.virtualbox.image.login-user>${test.virtualbox.image.login-user}</test.virtualbox.image.login-user> <test.virtualbox.image.login-user>${test.virtualbox.image.login-user}</test.virtualbox.image.login-user>
<test.virtualbox.image.authenticate-sudo>${test.virtualbox.image.authenticate-sudo}</test.virtualbox.image.authenticate-sudo> <test.virtualbox.image.authenticate-sudo>${test.virtualbox.image.authenticate-sudo}</test.virtualbox.image.authenticate-sudo>
<test.virtualbox.image.descriptor.yaml>${test.virtualbox.image.descriptor.yaml}</test.virtualbox.image.descriptor.yaml>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -70,6 +70,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
@Provider Supplier<URI> providerSupplier, @Identity String identity, @Credential String credential) { @Provider Supplier<URI> providerSupplier, @Identity String identity, @Credential String credential) {
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
this.socketTester = checkNotNull(socketTester, "socketTester"); this.socketTester = checkNotNull(socketTester, "socketTester");
this.socketTester.seconds(1L);
this.host = checkNotNull(host, "host"); this.host = checkNotNull(host, "host");
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed"); this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed");
this.identity = checkNotNull(identity, "identity"); this.identity = checkNotNull(identity, "identity");
@ -96,8 +97,8 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
manager = managerForNode.apply(host); manager = managerForNode.apply(host);
manager.connect(provider.toASCIIString(), identity, credential); manager.connect(provider.toASCIIString(), identity, credential);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
if (manager.getSessionObject().getState() == SessionState.Unlocked) if (manager.getSessionObject().getState() != SessionState.Unlocked)
logger.warn("manager is not in unlocked state " + manager); logger.warn("manager is not in unlocked state " + manager.getSessionObject().getState());
} }
@Override @Override

View File

@ -19,6 +19,8 @@
package org.jclouds.virtualbox; package org.jclouds.virtualbox;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
@ -32,13 +34,17 @@ import org.jclouds.byon.config.CacheNodeStoreModule;
import org.jclouds.compute.BaseVersionedServiceLiveTest; import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.virtualbox.compute.VirtualBoxComputeServiceAdapter;
import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.IsoSpec;
import org.jclouds.virtualbox.domain.Master;
import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia; import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
import org.jclouds.virtualbox.util.MachineUtils; import org.jclouds.virtualbox.util.MachineUtils;
@ -72,16 +78,16 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
} }
protected ComputeServiceContext context; protected ComputeServiceContext context;
@Inject @Inject
protected Supplier<VirtualBoxManager> manager; protected Supplier<VirtualBoxManager> manager;
@Inject @Inject
void eagerlyStartManager(Supplier<VirtualBoxManager> manager){ void eagerlyStartManager(Supplier<VirtualBoxManager> manager) {
this.manager = manager; this.manager = manager;
manager.get(); manager.get();
} }
@Inject @Inject
protected MachineUtils machineUtils; protected MachineUtils machineUtils;
@ -89,7 +95,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
@Inject @Inject
@Preconfiguration @Preconfiguration
protected LoadingCache<IsoSpec, URI> preconfigurationUri; protected LoadingCache<IsoSpec, URI> preconfigurationUri;
protected String hostVersion; protected String hostVersion;
protected String operatingSystemIso; protected String operatingSystemIso;
protected String guestAdditionsIso; protected String guestAdditionsIso;
@ -101,6 +107,8 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
protected Supplier<NodeMetadata> host; protected Supplier<NodeMetadata> host;
@Inject @Inject
protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate; protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
@Inject
protected LoadingCache<Image, Master> mastersCache;
@Override @Override
protected void setupCredentials() { protected void setupCredentials() {
@ -135,13 +143,18 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule(), hostModule), overrides); ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule(), hostModule), overrides);
context.utils().injector().injectMembers(this); context.utils().injector().injectMembers(this);
imageId = "ubuntu-11.04-server-i386"; imageId = "ubuntu-11.04-server-i386";
isosDir = workingDir + File.separator + "isos"; isosDir = workingDir + File.separator + "isos";
hostVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0); hostVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0);
operatingSystemIso = String.format("%s/%s.iso", isosDir, imageId); operatingSystemIso = String.format("%s/%s.iso", isosDir, imageId);
guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion); guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion);
// try and get a master from the cache, this will initialize the config/download isos and
// prepare everything IF a master is not available, subsequent calls should be pretty fast
Template template = context.getComputeService().templateBuilder().build();
checkNotNull(mastersCache.apply(template.getImage()));
} }
protected void undoVm(VmSpec vmSpecification) { protected void undoVm(VmSpec vmSpecification) {
@ -173,7 +186,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
} }
} }
} }
public String adminDisk(String vmName) { public String adminDisk(String vmName) {
return workingDir + File.separator + vmName + ".vdi"; return workingDir + File.separator + vmName + ".vdi";
} }

View File

@ -40,10 +40,11 @@ import com.google.common.collect.Iterables;
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
@Inject
private VirtualBoxComputeServiceAdapter adapter;
private NodeAndInitialCredentials<IMachine> machine; private NodeAndInitialCredentials<IMachine> machine;
@Inject
protected VirtualBoxComputeServiceAdapter adapter;
@Test @Test
public void testCreatedNodeHasExpectedNameAndWeCanConnectViaSsh() { public void testCreatedNodeHasExpectedNameAndWeCanConnectViaSsh() {

View File

@ -40,7 +40,7 @@ import com.google.common.collect.Iterables;
public class ImageFromYamlStringTest { public class ImageFromYamlStringTest {
public static final Image TEST1 = new ImageBuilder() public static final Image TEST1 = new ImageBuilder()
.id("myTestId") .id("default-ubuntu-11.04-i386")
.name("ubuntu-11.04-server-i386") .name("ubuntu-11.04-server-i386")
.description("ubuntu 11.04 server (i386)") .description("ubuntu 11.04 server (i386)")
.operatingSystem( .operatingSystem(
@ -51,7 +51,7 @@ public class ImageFromYamlStringTest {
public void testNodesParse() throws Exception { public void testNodesParse() throws Exception {
final StringBuilder yamlFileLines = new StringBuilder(); final StringBuilder yamlFileLines = new StringBuilder();
for (Object line : IOUtils.readLines(new InputStreamReader(getClass().getResourceAsStream("/testImages.yaml")))) { for (Object line : IOUtils.readLines(new InputStreamReader(getClass().getResourceAsStream("/default-images.yaml")))) {
yamlFileLines.append(line).append("\n"); yamlFileLines.append(line).append("\n");
} }

View File

@ -44,8 +44,8 @@ import com.google.common.base.Function;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
@Test(groups = "unit", singleThreaded = true, testName = "StartVBoxIfNotAlreadyRunningTest") @Test(groups = "live", singleThreaded = true, testName = "StartVBoxIfNotAlreadyRunningLiveTest")
public class StartVBoxIfNotAlreadyRunningTest { public class StartVBoxIfNotAlreadyRunningLiveTest {
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test

View File

@ -1,68 +0,0 @@
images:
- id: myTestId
name: ubuntu-11.04-server-i386
description: ubuntu 11.04 server (i386)
os_arch: x86
os_family: ubuntu
os_description: ubuntu
os_version: 11.04
iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
keystroke_sequence: |
<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
fb=false debconf/frontend=noninteractive
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
initrd=/install/initrd.gz -- <Enter>
preseed_cfg: |
## Options to set on the command line
d-i debian-installer/locale string en_US.utf8
d-i console-setup/ask_detect boolean false
d-i console-setup/layout string USA
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
# Continue without a default route
# Not working , specify a dummy in the DHCP
d-i time/zone string UTC
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i kbd-chooser/method select American English
d-i netcfg/wireless_wep string
d-i base-installer/kernel/override-image string linux-server
# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
d-i debconf debconf/frontend select Noninteractive
d-i pkgsel/install-language-support boolean false
tasksel tasksel/first multiselect standard, ubuntu-server
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
# Write the changes to disks and configure LVM?
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
## Default user, we can get away with a recipe to change this
d-i passwd/user-fullname string toor
d-i passwd/username string toor
d-i passwd/user-password password password
d-i passwd/user-password-again password password
d-i user-setup/encrypt-home boolean false
d-i user-setup/allow-password-weak boolean true
# Individual additional packages to install
d-i pkgsel/include string openssh-server ntp
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
d-i pkgsel/upgrade select full-upgrade
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i finish-install/reboot_in_progress note
#For the update
d-i pkgsel/update-policy select none
# debconf-get-selections --install
#Use mirror
choose-mirror-bin mirror/http/proxy string