From ac0e5f5e67ca8bdda571a0d01b22596bf94b0102 Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Sat, 10 Nov 2012 18:16:00 +0200 Subject: [PATCH] added support for vbox 4.2.6; added hostname support; added generic md5 support; dralves`s comments addressed adrian`s comments addressed dralver`s comments addressed second round of comments addressed fix CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest formatting swept check* updated jclouds-sshj pom.xml with latest bouncycastle version --- .gitignore | 1 + drivers/sshj/pom.xml | 6 + labs/virtualbox/.DS_Store | Bin 0 -> 6148 bytes labs/virtualbox/pom.xml | 19 +- .../org/jclouds/virtualbox/VirtualBox.java | 2 +- .../virtualbox/VirtualBoxApiMetadata.java | 19 +- .../compute/LoadMachineFromVirtualBox.java | 6 +- .../VirtualBoxComputeServiceAdapter.java | 18 +- .../extensions/VirtualBoxImageExtension.java | 22 +- ...VirtualBoxComputeServiceContextModule.java | 24 +- .../jclouds/virtualbox/domain/BridgedIf.java | 6 +- .../jclouds/virtualbox/domain/CloneSpec.java | 11 +- .../virtualbox/domain/DeviceDetails.java | 7 +- .../jclouds/virtualbox/domain/ErrorCode.java | 6 +- .../jclouds/virtualbox/domain/HardDisk.java | 11 +- .../jclouds/virtualbox/domain/IsoImage.java | 6 +- .../jclouds/virtualbox/domain/IsoSpec.java | 4 +- .../org/jclouds/virtualbox/domain/Master.java | 2 +- .../jclouds/virtualbox/domain/MasterSpec.java | 9 +- .../jclouds/virtualbox/domain/NatAdapter.java | 2 +- .../virtualbox/domain/NetworkAdapter.java | 6 +- .../domain/NetworkInterfaceCard.java | 4 +- .../virtualbox/domain/NetworkSpec.java | 2 +- .../virtualbox/domain/RedirectRule.java | 2 +- .../virtualbox/domain/StorageController.java | 16 +- .../org/jclouds/virtualbox/domain/VmSpec.java | 12 +- .../AddIDEControllerIfNotExists.java | 6 +- .../functions/ApplyMemoryToMachine.java | 2 +- .../AttachBridgedAdapterToMachine.java | 9 +- .../functions/AttachHostOnlyAdapter.java | 12 +- ...chMediumToMachineIfNotAlreadyAttached.java | 7 +- ...NATAdapterToMachineIfNotAlreadyExists.java | 20 +- .../functions/AttachNicToMachine.java | 6 +- .../functions/BridgedIfStringToBridgedIf.java | 2 +- ...MachineFromIMachineIfNotAlreadyExists.java | 28 +- .../functions/CreateAndInstallVm.java | 27 +- ...isterMachineFromIsoIfNotAlreadyExists.java | 28 +- .../CreateMediumIfNotAlreadyExists.java | 23 +- .../DetachDistroMediumFromMachine.java | 4 +- .../functions/IMachineToHardware.java | 6 +- .../virtualbox/functions/IMachineToImage.java | 8 +- .../functions/IMachineToIpAddress.java | 9 +- .../functions/IMachineToNodeMetadata.java | 45 ++- .../functions/IMachineToSshClient.java | 104 +++--- .../functions/IMachineToVmSpec.java | 12 +- .../functions/IpAddressesLoadingCache.java | 25 +- .../LaunchMachineIfNotAlreadyRunning.java | 12 +- .../functions/MastersLoadingCache.java | 343 ++++++++---------- .../virtualbox/functions/NodeCreator.java | 24 +- .../virtualbox/functions/SendScancodes.java | 7 +- .../virtualbox/functions/StringToKeyCode.java | 1 - .../TakeSnapshotIfNotAlreadyAttached.java | 16 +- .../admin/StartVBoxIfNotAlreadyRunning.java | 86 +++-- ...isterMachineIfExistsAndDeleteItsMedia.java | 10 +- ...MachineIfExistsAndForceDeleteItsMedia.java | 12 +- .../predicates/IMachinePredicates.java | 8 +- .../predicates/IMediumPredicates.java | 4 +- .../statements/EnableNetworkInterface.java | 1 - .../statements/InstallGuestAdditions.java | 4 +- .../jclouds/virtualbox/statements/Md5.java | 50 +++ .../virtualbox/statements/SetHostname.java | 55 +++ .../virtualbox/util/IMediumAttachments.java | 4 +- .../virtualbox/util/MachineController.java | 249 ++++++------- .../util/MachineNameOrIdAndNicSlot.java | 36 +- .../jclouds/virtualbox/util/MachineUtils.java | 53 ++- .../jclouds/virtualbox/util/NetworkUtils.java | 303 +++++++--------- .../src/main/resources/default-images.yaml | 12 +- .../functions/cleanupUdevIfNeeded.sh | 3 - .../BaseVirtualBoxClientLiveTest.java | 39 +- .../virtualbox/PreseedCfgServerTest.java | 1 + ...rtualBoxComputeServiceAdapterLiveTest.java | 4 +- .../VirtualBoxComputeServiceAdapterTest.java | 30 +- .../compute/VirtualBoxExperimentLiveTest.java | 6 +- .../jclouds/virtualbox/domain/VmSpecTest.java | 5 +- .../AddIDEControllerIfNotExistsTest.java | 8 +- .../functions/ApplyMemoryToMachineTest.java | 4 +- .../AttachBridgedAdapterToMachineTest.java | 10 +- ...diumToMachineIfNotAlreadyAttachedTest.java | 16 +- ...dapterToMachineIfNotAlreadyExistsTest.java | 26 +- ...romIMachineIfNotAlreadyExistsLiveTest.java | 8 +- .../functions/CreateAndInstallVmLiveTest.java | 14 +- ...hineFromIsoIfNotAlreadyExistsLiveTest.java | 14 +- ...rMachineFromIsoIfNotAlreadyExistsTest.java | 186 +++++----- ...reateMediumIfNotAlreadyExistsLiveTest.java | 13 +- .../CreateMediumIfNotAlreadyExistsTest.java | 38 +- .../DetachDistroMediumFromMachineTest.java | 4 +- .../functions/IMachineToHardwareTest.java | 8 +- .../functions/IMachineToImageTest.java | 10 +- .../functions/IMachineToNodeMetadataTest.java | 67 +++- .../functions/IMachineToVmSpecTest.java | 14 +- .../LaunchMachineIfNotAlreadyRunningTest.java | 10 +- .../TakeSnapshotIfNotAlreadyAttachedTest.java | 16 +- .../admin/ImageFromYamlStringTest.java | 2 +- .../StartVBoxIfNotAlreadyRunningLiveTest.java | 54 +-- ...rMachineIfExistsAndDeleteItsMediaTest.java | 32 +- .../GuestAdditionsInstallerLiveTest.java | 50 +-- .../IMachinePredicatesLiveTest.java | 8 +- .../InstallGuestAdditionsLiveTest.java | 13 +- .../statements/InstallGuestAdditionsTest.java | 79 ++++ .../statements/SetIpAddressTest.java | 2 +- .../util/MachineControllerLiveTest.java | 76 ++-- .../virtualbox/util/MachineUtilsLiveTest.java | 33 +- .../src/test/resources/default-images.yaml | 66 +++- .../virtualbox/src/test/resources/logback.xml | 4 +- 104 files changed, 1495 insertions(+), 1374 deletions(-) create mode 100644 labs/virtualbox/.DS_Store create mode 100644 labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/Md5.java create mode 100644 labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/SetHostname.java create mode 100644 labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsTest.java diff --git a/.gitignore b/.gitignore index 5b734bc1be..e47dc4d89a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ bin/ TAGS .metadata/ atlassian-ide-plugin.xml +.DS_Store diff --git a/drivers/sshj/pom.xml b/drivers/sshj/pom.xml index f3c5509127..4f6ab25918 100644 --- a/drivers/sshj/pom.xml +++ b/drivers/sshj/pom.xml @@ -56,6 +56,12 @@ + + + org.bouncycastle + bcpkix-jdk15on + 1.47 + org.jclouds jclouds-compute diff --git a/labs/virtualbox/.DS_Store b/labs/virtualbox/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2e62dd299cce87090630d336b22c3cc1008ca14a GIT binary patch literal 6148 zcmeHKJ5Iwu5Pd@e1f@wyxg`yeasv}NNE9^T0+5erj2s0=qVzF16bIlo@MdR;V&fX2 zXhzz7vpXNpKFRw5Ak*Dy0*n9**c3&T4$I0JfSs|<#Q-a7-%fHSaX zK=+5hrkEwH4dd3qEeNIQAu9s$w2??`=wIMAOu~4FgN_t|5g>yb6zbs*GXyK6b z_>lDFpT~>DuQPv$?vTvTduPBIXfn{V;YiQ_8Go71M}9NJN6vsVaAXWfKYz%lTvR$+ ze=SeX+Q9b6rlNkeDirFCO8^JDk6cEh*@Noz%M#XxnnmYhIMFWxkr3~kfj?m28(?Bh AwEzGB literal 0 HcmV?d00001 diff --git a/labs/virtualbox/pom.xml b/labs/virtualbox/pom.xml index 7bc4bfd50d..391c160914 100644 --- a/labs/virtualbox/pom.xml +++ b/labs/virtualbox/pom.xml @@ -35,9 +35,10 @@ bundle + 4.2.6 http://localhost:18083/ - 4.1.4 - 4.1.20r80170 + 4.2.6 + ${virtualbox.version} ${user.name} CHANGE_ME osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64,loginUser=toor:password,authenticateSudo=true @@ -49,7 +50,7 @@ * - + org.jclouds @@ -59,7 +60,7 @@ org.virtualbox vboxjws - ${test.virtualbox.api-version} + ${virtualbox.version} org.jclouds.api @@ -86,6 +87,11 @@ jclouds-slf4j ${project.version} + + ch.qos.logback + logback-classic + test + org.jclouds jclouds-core @@ -100,11 +106,6 @@ test-jar test - - ch.qos.logback - logback-classic - test - org.testng testng diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBox.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBox.java index 1e8c95328b..f5beaeb6c8 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBox.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBox.java @@ -19,7 +19,7 @@ package org.jclouds.virtualbox; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.VirtualBoxManager; public class VirtualBox { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java index 662eadb6f5..265351110f 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxApiMetadata.java @@ -20,12 +20,11 @@ package org.jclouds.virtualbox; import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_MEMORY; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGES_DESCRIPTOR; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_MEMORY; - import java.io.File; import java.net.URI; @@ -65,15 +64,16 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata { properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, " " + "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL " - + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + "HOSTNAME " + + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + + "hostname=" + "HOSTNAME " + "fb=false debconf/frontend=noninteractive " - + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " + + "console-setup/ask_detect=false keyboard-configuration/layoutcode=us " + "initrd=/install/initrd.gz -- "); String workingDir = System.getProperty("test.virtualbox.workingDir", VIRTUALBOX_DEFAULT_DIR); properties.put(VIRTUALBOX_WORKINGDIR, workingDir); - String ram = System.getProperty(VIRTUALBOX_GUEST_MEMORY, "1024"); + String ram = System.getProperty(VIRTUALBOX_GUEST_MEMORY, "512"); properties.put(VIRTUALBOX_GUEST_MEMORY, ram); String yamlDescriptor = System.getProperty("test.virtualbox.image.descriptor.yaml", VIRTUALBOX_WORKINGDIR @@ -81,7 +81,7 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata { properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor); properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg"); - properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64"); + properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64"); return properties; } @@ -96,10 +96,9 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata { .defaultIdentity(System.getProperty("user.name")) .defaultCredential("CHANGE_ME") .defaultEndpoint("http://localhost:18083/") - .documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon")) - // later version not in maven, yet - .version("4.1.4") - .buildVersion("4.1.8r75467") + .documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/labs/virtualbox")) + .version("4.2.4") + .buildVersion("4.2.4") .defaultProperties(VirtualBoxApiMetadata.defaultProperties()) .view(ComputeServiceContext.class) .defaultModules(ImmutableSet.>of(HardcodeLocalhostAsNodeMetadataSupplier.class, VirtualBoxComputeServiceContextModule.class)); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java index b84b3550ea..dd198b6e92 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java @@ -31,9 +31,9 @@ import javax.inject.Inject; import org.jclouds.byon.Node; import org.jclouds.compute.domain.OsFamily; -import org.virtualbox_4_1.IGuestOSType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IGuestOSType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.cache.CacheLoader; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java index decac77dae..972b6d935a 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java @@ -47,12 +47,12 @@ import org.jclouds.virtualbox.domain.NodeSpec; import org.jclouds.virtualbox.domain.YamlImage; import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndForceDeleteItsMedia; import org.jclouds.virtualbox.util.MachineController; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -90,7 +90,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter> cloneCreator, Function imachineToImage, MachineController machineController) { - this.manager = checkNotNull(manager, "manager"); + this.manager = checkNotNull(manager, "virtualbox manager can't be null"); this.imagesToYamlImages = imagesMapper.get(); this.mastersLoader = mastersLoader; this.cloneCreator = cloneCreator; @@ -254,10 +254,10 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter groups = ImmutableList.of(); + String group = ""; + String settingsFile = manager.get().getVBox().composeMachineFilename(template.getName(), group , flags , workingDir); IMachine clonedMachine = manager.get().getVBox() - .createMachine(settingsFile, template.getName(), source.getOSTypeId(), template.getName(), true); + .createMachine(settingsFile, template.getName(), groups, source.getOSTypeId(), flags); List options = Lists.newArrayList(); if (isLinkedClone) @@ -136,7 +140,7 @@ public class VirtualBoxImageExtension implements ImageExtension { IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options); progress.waitForCompletion(-1); - logger.debug(String.format("Machine %s is cloned correctly", clonedMachine.getName())); + logger.debug(String.format("<< master(%s) is cloned correctly to vm(%s)", source.getName(), clonedMachine.getName())); // registering manager.get().getVBox().registerMachine(clonedMachine); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index 2a0e6ed4b7..9a1dd5d5c1 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -62,10 +62,10 @@ import org.jclouds.virtualbox.functions.admin.ImagesToYamlImagesFromYamlDescript import org.jclouds.virtualbox.functions.admin.PreseedCfgServer; import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; import org.jclouds.virtualbox.predicates.SshResponds; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.LockType; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.LockType; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -104,15 +104,15 @@ public class VirtualBoxComputeServiceContextModule extends bind(new TypeLiteral>() { }).to(IMachineToImage.class); bind(new TypeLiteral>() { - }).to((Class) PreseedCfgServer.class); + }).to(Class.class.cast(PreseedCfgServer.class)); bind(new TypeLiteral>() { - }).to((Class) FileDownloadFromURI.class); + }).to(Class.class.cast(FileDownloadFromURI.class)); bind(new TypeLiteral>() { - }).to((Class) StartVBoxIfNotAlreadyRunning.class); + }).to(Class.class.cast(StartVBoxIfNotAlreadyRunning.class)); // the yaml config to image mapper bind(new TypeLiteral>>() { - }).to((Class) ImagesToYamlImagesFromYamlDescriptor.class); + }).to(Class.class.cast(ImagesToYamlImagesFromYamlDescriptor.class)); // the yaml config provider bind(YamlImagesFromFileConfig.class); @@ -126,15 +126,15 @@ public class VirtualBoxComputeServiceContextModule extends // the master creating function bind(new TypeLiteral>() { - }).to((Class) CreateAndInstallVm.class); + }).to(Class.class.cast(CreateAndInstallVm.class)); // the machine cloning function bind(new TypeLiteral>>() { - }).to((Class) NodeCreator.class); + }).to(Class.class.cast(NodeCreator.class)); bind(new TypeLiteral>() { - }).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class); + }).to(Class.class.cast(CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class)); // the jetty server provider bind(new TypeLiteral() { - }).to((Class) PreseedCfgServer.class).asEagerSingleton(); + }).to(Class.class.cast(PreseedCfgServer.class)).asEagerSingleton(); bind(new TypeLiteral>() { }).to(IMachineToSshClient.class); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/BridgedIf.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/BridgedIf.java index a3b2d80b40..f5248513fb 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/BridgedIf.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/BridgedIf.java @@ -115,15 +115,15 @@ public class BridgedIf { public BridgedIf(String name, String guid, String dhcp, String ipAddress, String networkMask, String ipv6Address, String iv6NetworkMask, String mediumType, String status) { - this.name = checkNotNull(name, "bridgedIf name"); + this.name = checkNotNull(name, "bridgedIf name can't be null"); this.guid = guid; this.dhcp = dhcp; - this.ipAddress = checkNotNull(ipAddress, "bridgedIf ipAddress"); + this.ipAddress = checkNotNull(ipAddress, "bridgedIf ipAddress can't be null"); this.networkMask = networkMask; this.ipv6Address = ipv6Address; this.ipv6NetworkMask = iv6NetworkMask; this.mediumType = mediumType; - this.status = checkNotNull(status, "bridgedIf status"); + this.status = checkNotNull(status, "bridgedIf status can't be null"); } public String getName() { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/CloneSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/CloneSpec.java index b4727e4681..0266ad92bf 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/CloneSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/CloneSpec.java @@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain; import static com.google.common.base.Preconditions.checkNotNull; -import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_2.IMachine; import com.google.common.base.Objects; @@ -74,12 +74,9 @@ public class CloneSpec { } public CloneSpec(VmSpec vmSpec, NetworkSpec networkSpec, IMachine master, boolean isLinked) { - checkNotNull(vmSpec, "vmSpec"); - checkNotNull(networkSpec, "networkSpec"); - checkNotNull(master, "master"); - this.vmSpec = vmSpec; - this.networkSpec = networkSpec; - this.master = master; + this.vmSpec = checkNotNull(vmSpec, "vmSpec can't be null"); + this.networkSpec = checkNotNull(networkSpec, "networkSpec can't be null"); + this.master = checkNotNull(master, "master can't be null"); this.isLinked = isLinked; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/DeviceDetails.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/DeviceDetails.java index cf19e236b3..e0508dbb12 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/DeviceDetails.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/DeviceDetails.java @@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain; import static com.google.common.base.Preconditions.checkNotNull; -import org.virtualbox_4_1.DeviceType; +import org.virtualbox_4_2.DeviceType; import com.google.common.base.Objects; @@ -43,10 +43,9 @@ public class DeviceDetails { private final DeviceType deviceType; public DeviceDetails(int port, int deviceSlot, DeviceType deviceType) { - checkNotNull(deviceType, "deviceType"); this.port = port; this.deviceSlot = deviceSlot; - this.deviceType = deviceType; + this.deviceType = checkNotNull(deviceType, "deviceType can't be null"); } public int getPort() { @@ -87,7 +86,7 @@ public class DeviceDetails { } public DeviceDetails build() { - checkNotNull(deviceType, "deviceType"); + checkNotNull(deviceType, "deviceType can't be null"); return new DeviceDetails(port, deviceSlot, deviceType); } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java index 1670188076..2dec25293b 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java @@ -21,8 +21,8 @@ package org.jclouds.virtualbox.domain; import java.util.Map; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.jaxws.RuntimeFaultMsg; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.jaxws.RuntimeFaultMsg; import com.google.common.collect.ImmutableMap; @@ -76,7 +76,7 @@ public enum ErrorCode { this.code = code; } - private static final Map TABLE; + private final static Map TABLE; static { ImmutableMap.Builder builder = ImmutableMap.builder(); for (ErrorCode errorCode : ErrorCode.values()) { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java index fa387572ed..1eb7b06d64 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/HardDisk.java @@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain; import static com.google.common.base.Preconditions.checkNotNull; -import org.virtualbox_4_1.DeviceType; +import org.virtualbox_4_2.DeviceType; import com.google.common.base.Objects; @@ -46,12 +46,9 @@ public class HardDisk { private final boolean autoDelete; public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, boolean autoDelete) { - checkNotNull(deviceDetails, "deviceDetails"); - checkNotNull(diskPath, "diskPath"); - checkNotNull(diskFormat, "diskFormat"); - this.diskPath = diskPath; - this.diskFormat = diskFormat; - this.deviceDetails = deviceDetails; + this.diskPath = checkNotNull(diskPath, "diskPath can't be null"); + this.diskFormat = checkNotNull(diskFormat, "diskFormat can't be null"); + this.deviceDetails = checkNotNull(deviceDetails, "deviceDetails can't be null"); this.name = diskPath.substring(diskPath.lastIndexOf("/") + 1); this.autoDelete = autoDelete; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoImage.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoImage.java index 3fe415ef81..bf5c0b51e6 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoImage.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoImage.java @@ -33,10 +33,8 @@ public class IsoImage { private String sourcePath; public IsoImage(DeviceDetails deviceDetails, String sourcePath) { - checkNotNull(deviceDetails, "deviceDetails"); - checkNotNull(sourcePath, "sourcePath"); - this.deviceDetails = deviceDetails; - this.sourcePath = sourcePath; + this.deviceDetails = checkNotNull(deviceDetails, "deviceDetails can't be null"); + this.sourcePath = checkNotNull(sourcePath, "sourcePath can't be null"); } public DeviceDetails getDeviceDetails() { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoSpec.java index 79c82696f0..c12f8abb52 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/IsoSpec.java @@ -32,8 +32,8 @@ public class IsoSpec { private final String sourcePath; public IsoSpec(String sourcePath, String installationKeySequence) { - this.sourcePath = checkNotNull(sourcePath, "sourcePath"); - this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence"); + this.sourcePath = checkNotNull(sourcePath, "sourcePath can't be null"); + this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence can't be null"); } public static Builder builder() { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/Master.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/Master.java index 00fef3a058..7eab12a12f 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/Master.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/Master.java @@ -19,7 +19,7 @@ package org.jclouds.virtualbox.domain; -import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_2.IMachine; public class Master { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/MasterSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/MasterSpec.java index 6574a957ea..5b012c2ec5 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/MasterSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/MasterSpec.java @@ -74,12 +74,9 @@ public class MasterSpec { } private MasterSpec(VmSpec vmSpec, IsoSpec isoSpec, NetworkSpec networkSpec, LoginCredentials loginCredentials) { - checkNotNull(vmSpec, "vmSpec"); - checkNotNull(isoSpec, "isoSpec"); - checkNotNull(networkSpec, "networkSpec"); - this.vmSpec = vmSpec; - this.isoSpec = isoSpec; - this.networkSpec = networkSpec; + this.vmSpec = checkNotNull(vmSpec, "vmSpec can't be null"); + this.isoSpec = checkNotNull(isoSpec, "isoSpec can't be null"); + this.networkSpec = checkNotNull(networkSpec, "networkSpec can't be null"); this.loginCredentials = loginCredentials; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NatAdapter.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NatAdapter.java index 095a515ab6..cc7ab91c17 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NatAdapter.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NatAdapter.java @@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Collections; import java.util.Set; -import org.virtualbox_4_1.NATProtocol; +import org.virtualbox_4_2.NATProtocol; import com.google.common.base.Objects; import com.google.common.collect.Sets; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkAdapter.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkAdapter.java index 32940460b1..6d70174bb2 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkAdapter.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkAdapter.java @@ -25,8 +25,8 @@ import java.util.Collections; import java.util.Set; import org.jclouds.javax.annotation.Nullable; -import org.virtualbox_4_1.NATProtocol; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.NATProtocol; +import org.virtualbox_4_2.NetworkAttachmentType; import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; @@ -48,7 +48,7 @@ public class NetworkAdapter { String macAddress, Set redirectRules, String staticIp) { this.networkAttachmentType = checkNotNull(networkAttachmentType, - "networkAttachmentType"); + "networkAttachmentType can't be null"); this.macAddress = macAddress; this.redirectRules = ImmutableSet.copyOf(redirectRules); this.staticIp = staticIp; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkInterfaceCard.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkInterfaceCard.java index 816626cf13..36b3195d91 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkInterfaceCard.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkInterfaceCard.java @@ -31,8 +31,8 @@ public class NetworkInterfaceCard { private final boolean enabled; public NetworkInterfaceCard(long slot, NetworkAdapter networkAdapter, String hostInterfaceName, boolean enabled) { - this.slot = checkNotNull(slot, "slot"); - this.networkAdapter = checkNotNull(networkAdapter, "networkAdapter"); + this.slot = checkNotNull(slot, "slot can't be null"); + this.networkAdapter = checkNotNull(networkAdapter, "networkAdapter can't be null"); this.hostInterfaceName = hostInterfaceName; this.enabled = enabled; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkSpec.java index 70ade79c54..7219e1b1f5 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/NetworkSpec.java @@ -34,7 +34,7 @@ public class NetworkSpec { private final List networkInterfaceCards; public NetworkSpec(final List networkInterfaceCards) { - this.networkInterfaceCards = ImmutableList.copyOf(checkNotNull(networkInterfaceCards, "networkInterfaceCards")); + this.networkInterfaceCards = ImmutableList.copyOf(checkNotNull(networkInterfaceCards, "networkInterfaceCards can't be null")); } public static Builder builder() { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/RedirectRule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/RedirectRule.java index 34df5d202b..fcf1d9d1c0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/RedirectRule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/RedirectRule.java @@ -20,7 +20,7 @@ package org.jclouds.virtualbox.domain; import static com.google.common.base.Preconditions.checkNotNull; -import org.virtualbox_4_1.NATProtocol; +import org.virtualbox_4_2.NATProtocol; import com.google.common.base.Objects; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java index f662230b5a..941c3031c9 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/StorageController.java @@ -24,8 +24,8 @@ import static com.google.common.collect.Iterables.filter; import java.util.Set; import org.jclouds.javax.annotation.Nullable; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.Objects; import com.google.common.base.Predicate; @@ -49,14 +49,10 @@ public class StorageController { private Set isoImages; public StorageController(String name, StorageBus bus, Set hardDisks, Set isoImages) { - checkNotNull(name, "name"); - checkNotNull(bus, "bus"); - checkNotNull(hardDisks, "hardDisks"); - checkNotNull(isoImages, "isoImages"); - this.name = name; - this.bus = bus; - this.hardDisks = hardDisks; - this.isoImages = isoImages; + this.name = checkNotNull(name, "storage name can't be null"); + this.bus = checkNotNull(bus, "bus can't be null"); + this.hardDisks = checkNotNull(hardDisks, "hardDisks can't be null"); + this.isoImages = checkNotNull(isoImages, "isoImages can't be null"); } public String getName() { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java index 79deb2df62..e62327cc5d 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java @@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Collections; import java.util.Set; -import org.virtualbox_4_1.CleanupMode; +import org.virtualbox_4_2.CleanupMode; import com.google.common.base.Objects; import com.google.common.collect.Sets; @@ -44,13 +44,13 @@ public class VmSpec { public VmSpec(String vmId, String vmName, String osTypeId, long memory, String guestUser, String guestPassword, boolean forceOverwrite, Set controllers, CleanupMode cleanupMode) { - this.vmId = checkNotNull(vmId, "vmId"); - this.vmName = checkNotNull(vmName, "vmName"); - this.osTypeId = checkNotNull(osTypeId, "osTypeId"); + this.vmId = checkNotNull(vmId, "vmId can't be null"); + this.vmName = checkNotNull(vmName, "vmName can't be null"); + this.osTypeId = checkNotNull(osTypeId, "osTypeId can't be null"); checkArgument(memory > 0, "memory must be > 0"); this.memory = memory; - this.controllers = checkNotNull(controllers, "controllers"); - this.cleanupMode = checkNotNull(cleanupMode, "cleanupMode"); + this.controllers = checkNotNull(controllers, "controllers can't be null"); + this.cleanupMode = checkNotNull(cleanupMode, "cleanupMode can't be null"); this.forceOverwrite = forceOverwrite; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java index 7ed2b799b0..581c41e01c 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java @@ -21,8 +21,8 @@ package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.virtualbox.domain.StorageController; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.VBoxException; import com.google.common.base.Function; @@ -35,7 +35,7 @@ public class AddIDEControllerIfNotExists implements Function { private final StorageController storageController; public AddIDEControllerIfNotExists(StorageController storageController) { - this.storageController = checkNotNull(storageController, "storageController"); + this.storageController = checkNotNull(storageController, "storageController can't be null"); } @Override diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java index 7dba773b2f..1691fbc454 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java @@ -19,7 +19,7 @@ package org.jclouds.virtualbox.functions; -import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_2.IMachine; import com.google.common.base.Function; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachine.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachine.java index aa27c7c405..c15c4c1fa0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachine.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachine.java @@ -18,12 +18,12 @@ */ package org.jclouds.virtualbox.functions; -import static org.virtualbox_4_1.NetworkAdapterType.Am79C973; -import static org.virtualbox_4_1.NetworkAttachmentType.Bridged; +import static org.virtualbox_4_2.NetworkAdapterType.Am79C973; +import static org.virtualbox_4_2.NetworkAttachmentType.Bridged; import org.jclouds.virtualbox.domain.NetworkInterfaceCard; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INetworkAdapter; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INetworkAdapter; import com.google.common.base.Function; @@ -43,7 +43,6 @@ public class AttachBridgedAdapterToMachine implements Function { public Void apply(IMachine machine) { INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot()); iNetworkAdapter.setAttachmentType(Bridged); - iNetworkAdapter.setAdapterType(Am79C973); iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress()); iNetworkAdapter.setBridgedInterface(networkInterfaceCard.getHostInterfaceName()); iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled()); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachHostOnlyAdapter.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachHostOnlyAdapter.java index 9eb16c0ef4..cdf34656d7 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachHostOnlyAdapter.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachHostOnlyAdapter.java @@ -18,12 +18,11 @@ */ package org.jclouds.virtualbox.functions; -import static org.virtualbox_4_1.NetworkAdapterType.Am79C973; -import static org.virtualbox_4_1.NetworkAttachmentType.HostOnly; - import org.jclouds.virtualbox.domain.NetworkInterfaceCard; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INetworkAdapter; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.NetworkAdapterType; +import org.virtualbox_4_2.NetworkAttachmentType; import com.google.common.base.Function; @@ -41,8 +40,7 @@ public class AttachHostOnlyAdapter implements Function { @Override public Void apply(IMachine machine) { INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot()); - iNetworkAdapter.setAttachmentType(HostOnly); - iNetworkAdapter.setAdapterType(Am79C973); + iNetworkAdapter.setAttachmentType(NetworkAttachmentType.HostOnly); iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress()); iNetworkAdapter.setHostOnlyInterface(networkInterfaceCard.getHostInterfaceName()); iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled()); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java index 3a5f3ab776..36baedc02d 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java @@ -20,9 +20,9 @@ package org.jclouds.virtualbox.functions; import org.jclouds.virtualbox.domain.DeviceDetails; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.VBoxException; import com.google.common.base.Function; @@ -54,6 +54,7 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function%s:%s",rule.getProtocol(), rule.getHost(), rule.getHostPort(), rule.getGuest(), rule.getGuestPort()); - iNetworkAdapter.getNatDriver().addRedirect(ruleName, rule.getProtocol(), rule.getHost(), rule.getHostPort(), + iNetworkAdapter.getNATEngine().addRedirect(ruleName, rule.getProtocol(), rule.getHost(), rule.getHostPort(), rule.getGuest(), rule.getGuestPort()); } catch (VBoxException e) { if (!e.getMessage().contains("already exists")) diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachNicToMachine.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachNicToMachine.java index f24f5b06b6..0e2d57e440 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachNicToMachine.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachNicToMachine.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.virtualbox.domain.NetworkInterfaceCard; import org.jclouds.virtualbox.util.MachineUtils; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.NetworkAttachmentType; import com.google.common.base.Function; @@ -35,8 +35,8 @@ public class AttachNicToMachine implements Function private final MachineUtils machineUtils; public AttachNicToMachine(String vmName, MachineUtils machineUtils) { - this.vmName = checkNotNull(vmName, "vmName"); - this.machineUtils = checkNotNull(machineUtils, "machineUtils"); + this.vmName = checkNotNull(vmName, "vmName can't be null"); + this.machineUtils = checkNotNull(machineUtils, "machineUtils can't be null"); } @Override diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/BridgedIfStringToBridgedIf.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/BridgedIfStringToBridgedIf.java index 414a3605e2..55281019f7 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/BridgedIfStringToBridgedIf.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/BridgedIfStringToBridgedIf.java @@ -48,7 +48,7 @@ public class BridgedIfStringToBridgedIf implements Function { @Override public BridgedIf apply(String rawBridgedIf) { - checkNotNull(rawBridgedIf, "rawBridgedIf"); + checkNotNull(rawBridgedIf, "bridged interface can't be null"); String transformedBridgedIf = transformRawBridgedIf(rawBridgedIf); Map bridgedIfMap = Splitter.on("\n") diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java index b6004e4e9f..1f27f97146 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java @@ -35,16 +35,17 @@ import org.jclouds.virtualbox.domain.NetworkInterfaceCard; import org.jclouds.virtualbox.domain.NetworkSpec; import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.util.MachineUtils; -import org.virtualbox_4_1.CloneMode; -import org.virtualbox_4_1.CloneOptions; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISnapshot; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.CloneMode; +import org.virtualbox_4_2.CloneOptions; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISnapshot; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.inject.Inject; @@ -96,13 +97,14 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu NetworkSpec networkSpec = cloneSpec.getNetworkSpec(); boolean isLinkedClone = cloneSpec.isLinked(); IMachine master = cloneSpec.getMaster(); - String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir); + String flags = ""; + List groups = ImmutableList.of(); + String group = ""; + String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), group , flags , workingDir); IMachine clonedMachine = manager .get() .getVBox() - .createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(), - vmSpec.isForceOverwrite()); - + .createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags); List options = Lists.newArrayList(); if (isLinkedClone) options.add(CloneOptions.Link); @@ -112,8 +114,6 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options); progress.waitForCompletion(-1); - logger.debug(String.format("Machine %s is cloned correctly", - clonedMachine.getName())); // memory may not be the same as the master vm clonedMachine.setMemorySize(cloneSpec.getVmSpec().getMemory()); @@ -127,7 +127,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu } // set only once the creds for this machine, same coming from its master - logger.debug(">> storing guest credentials on vm %s as extra data", clonedMachine.getName()); + logger.debug("<< storing guest credentials on vm(%s) as extra data", clonedMachine.getName()); String masterUsername = master.getExtraData(GUEST_OS_USER); String masterPassword = master.getExtraData(GUEST_OS_PASSWORD); clonedMachine.setExtraData(GUEST_OS_USER, masterUsername); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java index 19535d0d6f..c1497fd8c9 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndInstallVm.java @@ -45,17 +45,17 @@ import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.statements.InstallGuestAdditions; import org.jclouds.virtualbox.util.MachineController; import org.jclouds.virtualbox.util.MachineUtils; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMediumAttachment; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMediumAttachment; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Splitter; +import com.google.common.base.Stopwatch; import com.google.common.collect.Iterables; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.Uninterruptibles; import com.google.inject.Inject; @Singleton @@ -87,7 +87,7 @@ public class CreateAndInstallVm implements Function { this.machineUtils = machineUtils; this.imachineToNodeMetadata = imachineToNodeMetadata; this.machineController = machineController; - this.version = Iterables.get(Splitter.on('r').split(version), 0); + this.version = Iterables.get(Splitter.on('-').split(version), 0); this.preconfigurationUrl = preconfigurationUrl; } @@ -103,31 +103,32 @@ public class CreateAndInstallVm implements Function { preconfigurationUrl); configureOsInstallationWithKeyboardSequence(masterName, installationKeySequence); - - // the OS installation is a long process: let's delay the check for ssh of 40 sec - Uninterruptibles.sleepUninterruptibly(40, TimeUnit.SECONDS); masterMachine.setExtraData(GUEST_OS_USER, masterSpec.getLoginCredentials().getUser()); masterMachine.setExtraData(GUEST_OS_PASSWORD, masterSpec.getLoginCredentials().getPassword()); SshClient client = sshClientForIMachine.apply(masterMachine); logger.debug(">> awaiting installation to finish node(%s)", masterName); + Stopwatch stopwatch = new Stopwatch(); + stopwatch.start(); checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", masterName); + stopwatch.stop(); + logger.debug(String.format("Elapsed time for the OS installation: %d minutes", TimeUnit.SECONDS.convert(stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS))); NodeMetadata nodeMetadata = imachineToNodeMetadata.apply(masterMachine); logger.debug(">> awaiting post-installation actions on vm: %s", masterName); ListenableFuture execCleanup = machineUtils.runScriptOnNode(nodeMetadata, call("cleanupUdevIfNeeded"), RunScriptOptions.NONE); ExecResponse cleanupResponse = Futures.getUnchecked(execCleanup); - checkState(cleanupResponse.getExitStatus() == 0); + checkState(cleanupResponse.getExitStatus() == 0, "post-installation actions on vm(%s) failed", masterName); logger.debug(">> awaiting installation of guest additions on vm: %s", masterName); ListenableFuture execInstallGA = machineUtils.runScriptOnNode(nodeMetadata, new InstallGuestAdditions(vmSpec, version), RunScriptOptions.NONE); ExecResponse gaInstallationResponse = Futures.getUnchecked(execInstallGA); - checkState(gaInstallationResponse.getExitStatus() == 0); + checkState(gaInstallationResponse.getExitStatus() == 0, "installation of guest additions on vm(%s) failed", masterName); - machineController.ensureMachineIsShutdown(masterName); + machineController.ensureMachineIsShutdown(masterName); // detach DVD and ISOs, if needed Iterable mediumAttachments = Iterables.filter( @@ -140,9 +141,9 @@ public class CreateAndInstallVm implements Function { } }); for (IMediumAttachment iMediumAttachment : mediumAttachments) { - logger.debug("Detach %s from (%s)", iMediumAttachment.getMedium() + logger.debug("<< iMedium(%s) detached from (%s)", iMediumAttachment.getMedium() .getName(), masterMachine.getName()); - machineUtils.writeLockMachineAndApply( + machineUtils.sharedLockMachineAndApply( masterMachine.getName(), new DetachDistroMediumFromMachine(iMediumAttachment .getController(), iMediumAttachment.getPort(), diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java index bd710c4a82..a8227d5343 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java @@ -23,7 +23,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.virtualbox.util.MachineUtils.machineNotFoundException; import java.io.File; +import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; import javax.annotation.Resource; import javax.inject.Inject; @@ -42,16 +44,18 @@ import org.jclouds.virtualbox.domain.NetworkSpec; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.util.MachineUtils; -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.IVirtualBox; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.AccessMode; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Uninterruptibles; /** * @author Mattias Holmqvist @@ -95,10 +99,12 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi private IMachine createMachine(IVirtualBox vBox, MasterSpec masterSpec) { VmSpec vmSpec = masterSpec.getVmSpec(); - String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir); + String flags = ""; + List groups = Lists.newArrayList(); + String group = ""; + String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), group , flags , workingDir); - IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), - vmSpec.getVmId(), vmSpec.isForceOverwrite()); + IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags); manager.get().getVBox().registerMachine(newMachine); ensureConfiguration(masterSpec); @@ -171,6 +177,6 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) { machineUtils.writeLockMachineAndApply(vmName, - new AddIDEControllerIfNotExists(checkNotNull(storageController, "storageController"))); + new AddIDEControllerIfNotExists(checkNotNull(storageController, "storageController can't be null"))); } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExists.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExists.java index 7aacd94241..7226179250 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExists.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExists.java @@ -27,14 +27,15 @@ import javax.inject.Singleton; import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.util.MachineUtils; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IMediumAttachment; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.AccessMode; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IMediumAttachment; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -65,7 +66,7 @@ public class CreateMediumIfNotAlreadyExists implements Function { public String apply(IMachine machine) { String macAddress = machine.getNetworkAdapter(0l).getMACAddress(); - int offset = 0; - int step = 2; + int offset = 0, step = 2; for (int j = 1; j <= 5; j++) { macAddress = new StringBuilder(macAddress).insert(j * step + offset, ":").toString().toLowerCase(); offset++; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java index f7e8a8a9db..e5166f8da0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java @@ -19,6 +19,9 @@ package org.jclouds.virtualbox.functions; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized; +import static org.jclouds.compute.util.ComputeServiceUtils.parseVersionOrReturnEmptyString; import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_PASSWORD; import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_USER; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_NAME_SEPARATOR; @@ -31,6 +34,8 @@ import javax.annotation.Resource; import javax.inject.Named; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.NodeMetadata.Status; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.reference.ComputeServiceConstants; @@ -40,13 +45,16 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.javax.annotation.Nullable; import org.jclouds.logging.Logger; import org.jclouds.virtualbox.util.NetworkUtils; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.IGuestOSType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Splitter; +import com.google.common.base.Supplier; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.inject.Inject; @@ -59,14 +67,18 @@ public class IMachineToNodeMetadata implements Function @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; + private final Supplier virtualboxManager; private final Map toPortableNodeStatus; private final NetworkUtils networkUtils; + private final Map> osVersionMap; @Inject - public IMachineToNodeMetadata(Map toPortableNodeStatus, - NetworkUtils networkUtils) { - this.toPortableNodeStatus = toPortableNodeStatus; - this.networkUtils = networkUtils; + public IMachineToNodeMetadata(Supplier virtualboxManager, Map toPortableNodeStatus, + NetworkUtils networkUtils, Map> osVersionMap) { + this.virtualboxManager = checkNotNull(virtualboxManager, "virtualboxManager"); + this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus"); + this.networkUtils = checkNotNull(networkUtils, "networkUtils"); + this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap"); } @Override @@ -98,6 +110,13 @@ public class IMachineToNodeMetadata implements Function nodeState = Status.UNRECOGNIZED; nodeMetadataBuilder.status(nodeState); nodeMetadataBuilder = getIpAddresses(vm, nodeMetadataBuilder); + + IGuestOSType guestOSType = virtualboxManager.get().getVBox().getGuestOSType(vm.getOSTypeId()); + OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription()); + String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap); + OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family) + .version(version).is64Bit(guestOSType.getIs64Bit()).build(); + nodeMetadataBuilder.operatingSystem(os); String guestOsUser = vm.getExtraData(GUEST_OS_USER); String guestOsPassword = vm.getExtraData(GUEST_OS_PASSWORD); @@ -114,11 +133,11 @@ public class IMachineToNodeMetadata implements Function INetworkAdapter adapter = vm.getNetworkAdapter(slot); if(adapter != null) { if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) { - String hostIP = adapter.getNatDriver().getHostIP(); + String hostIP = adapter.getNATEngine().getHostIP(); if(!hostIP.isEmpty()) publicIpAddresses.add(hostIP); - for (String nameProtocolnumberAddressInboundportGuestTargetport : adapter.getNatDriver().getRedirects()) { - Iterable stuff = Splitter.on(',').split(nameProtocolnumberAddressInboundportGuestTargetport); + for (String nameProtocolnumberAddressInboudportGuestTargetport : adapter.getNATEngine().getRedirects()) { + Iterable stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); String protocolNumber = Iterables.get(stuff, 1); String hostAddress = Iterables.get(stuff, 2); String inboundPort = Iterables.get(stuff, 3); @@ -130,13 +149,11 @@ public class IMachineToNodeMetadata implements Function } } } else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) { - // TODO quick test first String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot()); privateIpAddresses.add(clientIpAddress); } else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) { - // TODO quick test first - String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot()); + String clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName()); publicIpAddresses.add(clientIpAddress); } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java index 713dff67ca..6ff3437d85 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java @@ -18,7 +18,6 @@ */ package org.jclouds.virtualbox.functions; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_PASSWORD; import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_USER; @@ -31,12 +30,13 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.Logger; import org.jclouds.ssh.SshClient; import org.jclouds.virtualbox.util.NetworkUtils; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.NetworkAttachmentType; import com.google.common.base.Function; import com.google.common.base.Splitter; +import com.google.common.base.Strings; import com.google.common.collect.Iterables; import com.google.common.net.HostAndPort; import com.google.inject.Inject; @@ -44,65 +44,55 @@ import com.google.inject.Inject; @Singleton public class IMachineToSshClient implements Function { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; - private final SshClient.Factory sshClientFactory; - private final NetworkUtils networkUtils; - - @Inject - public IMachineToSshClient(SshClient.Factory sshClientFactory, - NetworkUtils networkUtils) { - this.sshClientFactory = sshClientFactory; - this.networkUtils = networkUtils; - } + private final SshClient.Factory sshClientFactory; + private final NetworkUtils networkUtils; - @Override + @Inject + public IMachineToSshClient(SshClient.Factory sshClientFactory, NetworkUtils networkUtils) { + this.sshClientFactory = sshClientFactory; + this.networkUtils = networkUtils; + } + + @Override public SshClient apply(final IMachine vm) { - INetworkAdapter networkAdapter = vm.getNetworkAdapter(0L); - - SshClient client = null; - checkNotNull(networkAdapter); - - String clientIpAddress = null; String sshPort = "22"; String guestIdentity = vm.getExtraData(GUEST_OS_USER); String guestCredential = vm.getExtraData(GUEST_OS_PASSWORD); - - LoginCredentials loginCredentials = LoginCredentials.builder() - .user(guestIdentity).password(guestCredential) + LoginCredentials loginCredentials = LoginCredentials.builder().user(guestIdentity).password(guestCredential) .authenticateSudo(true).build(); - if (networkAdapter.getAttachmentType() - .equals(NetworkAttachmentType.NAT)) { - for (String nameProtocolnumberAddressInboundPortGuestTargetport : networkAdapter - .getNatDriver().getRedirects()) { - Iterable stuff = Splitter.on(',').split( - nameProtocolnumberAddressInboundPortGuestTargetport); - String protocolNumber = Iterables.get(stuff, 1); - String hostAddress = Iterables.get(stuff, 2); - String inboundPort = Iterables.get(stuff, 3); - String targetPort = Iterables.get(stuff, 5); - if ("1".equals(protocolNumber) && "22".equals(targetPort)) { - clientIpAddress = hostAddress; - sshPort = inboundPort; - } - } - } else if (networkAdapter.getAttachmentType().equals( - NetworkAttachmentType.Bridged)) { - clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot()); - } else if (networkAdapter.getAttachmentType().equals( - NetworkAttachmentType.HostOnly)) { - clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot()); - } - - checkNotNull(clientIpAddress, "clientIpAddress"); - client = sshClientFactory.create( - HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)), - loginCredentials); - checkNotNull(client); - return client; - } + String clientIpAddress = null; -} + long nicSlot = 0; + while (nicSlot < 4 && Strings.isNullOrEmpty(clientIpAddress)) { + INetworkAdapter networkAdapter = vm.getNetworkAdapter(nicSlot); + + if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.NAT)) { + for (String nameProtocolnumberAddressInboudportGuestTargetport : networkAdapter.getNATEngine() + .getRedirects()) { + Iterable stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); + String protocolNumber = Iterables.get(stuff, 1); + String hostAddress = Iterables.get(stuff, 2); + String inboundPort = Iterables.get(stuff, 3); + String targetPort = Iterables.get(stuff, 5); + if ("1".equals(protocolNumber) && "22".equals(targetPort)) { + clientIpAddress = hostAddress; + sshPort = inboundPort; + } + } + } else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.Bridged)) { + clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot()); + } else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.HostOnly)) { + clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName()); + } + nicSlot++; + } + return sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)), + loginCredentials); + } + +} \ No newline at end of file diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToVmSpec.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToVmSpec.java index a3344dc552..c9e97d18b2 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToVmSpec.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToVmSpec.java @@ -30,12 +30,12 @@ import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.StorageController.Builder; import org.jclouds.virtualbox.domain.VmSpec; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IMediumAttachment; -import org.virtualbox_4_1.IStorageController; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IMediumAttachment; +import org.virtualbox_4_2.IStorageController; import com.google.common.base.Function; import com.google.common.collect.Lists; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java index 29974f1f4f..b02707b8a6 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IpAddressesLoadingCache.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import javax.annotation.Resource; import javax.inject.Inject; @@ -33,14 +32,13 @@ import javax.inject.Singleton; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot; -import org.jclouds.virtualbox.util.NetworkUtils; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.cache.AbstractLoadingCache; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Maps; -import com.google.common.util.concurrent.Uninterruptibles; /** * A {@link LoadingCache} for ip addresses. If the requested ip address has been @@ -71,19 +69,12 @@ public class IpAddressesLoadingCache extends return masters.get(machineNameOrIdAndNicPort); } String query = String.format("/VirtualBox/GuestInfo/Net/%s/V4/IP", machineNameOrIdAndNicPort.getSlotText()); - String currentIp = ""; - while (!NetworkUtils.isIpv4(currentIp)) { - currentIp = manager.get().getVBox().findMachine(machineNameOrIdAndNicPort.getMachineNameOrId()) - .getGuestPropertyValue(query); - if(!Strings.nullToEmpty(currentIp).isEmpty()) - logger.debug("Found IP address %s for '%s' at slot %s", currentIp, - machineNameOrIdAndNicPort.getMachineNameOrId(), - machineNameOrIdAndNicPort.getSlotText()); - Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); - } - - masters.put(machineNameOrIdAndNicPort, currentIp); - return currentIp; + String ipAddress = Strings.nullToEmpty(manager.get().getVBox() + .findMachine(machineNameOrIdAndNicPort.getMachineNameOrId()).getGuestPropertyValue(query)); + logger.debug("<< vm(%s) has IP address(%s) at slot(%s)", machineNameOrIdAndNicPort.getMachineNameOrId(), + ipAddress, machineNameOrIdAndNicPort.getSlotText()); + masters.put(machineNameOrIdAndNicPort, ipAddress); + return ipAddress; } @Override diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java index 751afbbf4b..c46a4ed1d0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java @@ -27,12 +27,12 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.virtualbox.domain.ErrorCode; import org.jclouds.virtualbox.domain.ExecutionType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.SessionState; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java index 2e1cfbc352..c6a82173f9 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/MastersLoadingCache.java @@ -69,23 +69,27 @@ import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.YamlImage; import org.jclouds.virtualbox.functions.admin.PreseedCfgServer; import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen; +import org.jclouds.virtualbox.statements.Md5; import org.jclouds.virtualbox.util.NetworkUtils; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.CaseFormat; import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.cache.AbstractLoadingCache; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.net.HostAndPort; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; /** * A {@link LoadingCache} for masters. If the requested master has been @@ -100,218 +104,181 @@ import com.google.common.net.HostAndPort; @Singleton public class MastersLoadingCache extends AbstractLoadingCache { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; - private final Map masters = Maps.newHashMap(); - private final Function masterCreatorAndInstaller; - private final Map imageMapping; - private final String workingDir; - private final String installationKeySequence; - private final String isosDir; - private final Supplier manager; - private final String version; - private final String preconfigurationUrl; + private final Map masters = Maps.newHashMap(); + private final Function masterCreatorAndInstaller; + private final Map imageMapping; + private final String workingDir; + private final String installationKeySequence; + private final String isosDir; + private final Supplier manager; + private final String version; + private final String preconfigurationUrl; - private final Factory runScriptOnNodeFactory; - private final RetryIfSocketNotYetOpen socketTester; - private final Supplier host; - private final Supplier providerSupplier; + private final Factory runScriptOnNodeFactory; + private final RetryIfSocketNotYetOpen socketTester; + private final Supplier host; + private final Supplier providerSupplier; private final HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata; - @Inject - public MastersLoadingCache( - @BuildVersion String version, - @Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence, - @Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl, - @Named(VIRTUALBOX_WORKINGDIR) String workingDir, - Function masterLoader, - Supplier> yamlMapper, - Supplier manager, - Factory runScriptOnNodeFactory, - RetryIfSocketNotYetOpen socketTester, Supplier host, - @Provider Supplier providerSupplier, - HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) { - checkNotNull(version, "version"); - checkNotNull(installationKeySequence, "installationKeySequence"); - checkNotNull(manager, "vboxmanager"); - this.manager = manager; - this.masterCreatorAndInstaller = masterLoader; - this.installationKeySequence = installationKeySequence; - this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR - : workingDir; - this.isosDir = workingDir + File.separator + "isos"; - this.imageMapping = Maps.newLinkedHashMap(); - for (Entry entry : yamlMapper.get().entrySet()) { - this.imageMapping.put(entry.getKey().getId(), entry.getValue()); - } - this.version = Iterables.get(Splitter.on('r').split(version), 0); - this.preconfigurationUrl = preconfigurationUrl; + @Inject + public MastersLoadingCache(@BuildVersion String version, + @Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence, + @Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl, + @Named(VIRTUALBOX_WORKINGDIR) String workingDir, Function masterLoader, + Supplier> yamlMapper, Supplier manager, + Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier host, + @Provider Supplier providerSupplier, HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) { + this.manager = checkNotNull(manager, "vboxmanager can't be null"); + this.masterCreatorAndInstaller = masterLoader; + this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence can't be null"); + this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR : workingDir; + this.isosDir = workingDir + File.separator + "isos"; + this.imageMapping = Maps.newLinkedHashMap(); + for (Entry entry : yamlMapper.get().entrySet()) { + this.imageMapping.put(entry.getKey().getId(), entry.getValue()); + } + this.version = Iterables.get(Splitter.on('r').split(checkNotNull(version, "version")), 0); + this.preconfigurationUrl = preconfigurationUrl; - this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, - "runScriptOnNodeFactory"); - this.socketTester = checkNotNull(socketTester, "socketTester"); - this.socketTester.seconds(3L); - this.host = checkNotNull(host, "host"); - this.providerSupplier = checkNotNull(providerSupplier, - "endpoint to virtualbox websrvd is needed"); - this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata; - } + this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); + this.socketTester = checkNotNull(socketTester, "socketTester"); + this.socketTester.seconds(3L); + this.host = checkNotNull(host, "host"); + this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed"); + this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata; + } - @PostConstruct - public void createCacheDirStructure() { - if (!new File(workingDir).exists()) { - new File(workingDir, "isos").mkdirs(); - } - } + @PostConstruct + public void createCacheDirStructure() { + if (!new File(workingDir).exists()) { + new File(workingDir, "isos").mkdirs(); + } + } - @Override - public synchronized Master get(Image key) throws ExecutionException { - // check if we have loaded this machine before - if (masters.containsKey(key.getId())) { - return masters.get(key.getId()); - } - checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR), - "master image names cannot contain \"" - + VIRTUALBOX_NODE_NAME_SEPARATOR + "\""); - String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId(); - IMachine masterMachine; - Master master; - // ready the preseed file server - PreseedCfgServer server = new PreseedCfgServer(); - try { - // try and find a master machine in vbox - masterMachine = manager.get().getVBox().findMachine(vmName); - master = Master.builder().machine(masterMachine).build(); - } catch (VBoxException e) { - if (machineNotFoundException(e)) { - // machine was not found try to build one from a yaml file - YamlImage currentImage = checkNotNull(imageMapping.get(key.getId()), "currentImage"); - URI preseedServer; + @Override + public synchronized Master get(Image key) throws ExecutionException { + // check if we have loaded this machine before + if (masters.containsKey(key.getId())) { + return masters.get(key.getId()); + } + checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR), "master image names cannot contain \"" + + VIRTUALBOX_NODE_NAME_SEPARATOR + "\""); + String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId(); + IMachine masterMachine; + Master master; + // ready the preseed file server + PreseedCfgServer server = new PreseedCfgServer(); + try { + // try and find a master machine in vbox + masterMachine = manager.get().getVBox().findMachine(vmName); + master = Master.builder().machine(masterMachine).build(); + } catch (VBoxException e) { + if (machineNotFoundException(e)) { + // machine was not found try to build one from a yaml file + YamlImage currentImage = checkNotNull(imageMapping.get(key.getId()), "currentImage"); + URI preseedServer; try { preseedServer = new URI(preconfigurationUrl); - if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(), - preseedServer.getPort()))) { + if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(), preseedServer.getPort()))) { server.start(preconfigurationUrl, currentImage.preseed_cfg); } } catch (URISyntaxException e1) { logger.error("Cannot start the preseed server", e); throw e; } - - MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, - vmName); - masterMachine = masterCreatorAndInstaller.apply(masterSpec); - master = Master.builder().machine(masterMachine) - .spec(masterSpec).build(); - } else { - logger.error("Problem during master creation", e); - throw e; - } - } finally { - server.stop(); - } - masters.put(key.getId(), master); - return master; - } + MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, vmName); + masterMachine = masterCreatorAndInstaller.apply(masterSpec); + master = Master.builder().machine(masterMachine).spec(masterSpec).build(); + } else { + logger.error("Problem during master creation", e); + throw e; + } + } finally { + server.stop(); + } - private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage, - String vmName) throws ExecutionException { - String guestAdditionsFileName = String.format( - "VBoxGuestAdditions_%s.iso", version); - String guestAdditionsIso = String.format("%s/%s", isosDir, - guestAdditionsFileName); - String guestAdditionsUri = "http://download.virtualbox.org/virtualbox/" - + version + "/" + guestAdditionsFileName; - if (!new File(guestAdditionsIso).exists()) { - getFilePathOrDownload(guestAdditionsUri, null); - } - // check if the iso is here, download if not - String localIsoUrl = checkNotNull(getFilePathOrDownload(currentImage.iso, currentImage.iso_md5), "distro iso"); - String adminDisk = workingDir + File.separator + vmName + ".vdi"; - HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk) - .autoDelete(true).controllerPort(0).deviceSlot(1).build(); + masters.put(key.getId(), master); + return master; + } - StorageController ideController = StorageController.builder() - .name("IDE Controller").bus(StorageBus.IDE) - .attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk) - .attachISO(1, 0, guestAdditionsIso).build(); + private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage, String vmName) throws ExecutionException { + String guestAdditionsFileName = String.format("VBoxGuestAdditions_%s.iso", version); + String guestAdditionsIso = String.format("%s/%s", isosDir, guestAdditionsFileName); + String guestAdditionsUri = "http://download.virtualbox.org/virtualbox/" + version + "/" + guestAdditionsFileName; + if (!new File(guestAdditionsIso).exists()) { + getFilePathOrDownload(guestAdditionsUri, null); + } + // check if the iso is here, download if not + String localIsoUrl = checkNotNull(getFilePathOrDownload(currentImage.iso, currentImage.iso_md5), "distro iso"); + String adminDisk = workingDir + File.separator + vmName + ".vdi"; + HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1) + .build(); - VmSpec vmSpecification = VmSpec.builder().id(currentImage.id) - .name(vmName).memoryMB(512).osTypeId(getOsTypeId(currentImage.os_family, currentImage.os_64bit)) - .controller(ideController).forceOverwrite(true) - .guestUser(currentImage.username).guestPassword(currentImage.credential) - .cleanUpMode(CleanupMode.Full).build(); + StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE) + .attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk).build(); - NetworkAdapter networkAdapter = NetworkAdapter - .builder() - .networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule(providerSupplier.get().getHost(), NetworkUtils.MASTER_PORT, - "", 22).build(); + VmSpec vmSpecification = VmSpec.builder().id(currentImage.id).name(vmName).memoryMB(512) + .osTypeId(getOsTypeId(currentImage.os_family, currentImage.os_64bit)).controller(ideController) + .forceOverwrite(true).guestUser(currentImage.username).guestPassword(currentImage.credential) + .cleanUpMode(CleanupMode.Full).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard - .builder().addNetworkAdapter(networkAdapter).slot(0L).build(); + NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) + .tcpRedirectRule(providerSupplier.get().getHost(), NetworkUtils.MASTER_PORT, "", 22).build(); - NetworkSpec networkSpec = NetworkSpec.builder() - .addNIC(networkInterfaceCard).build(); - - return MasterSpec - .builder() - .vm(vmSpecification) - .iso(IsoSpec - .builder() - .sourcePath(localIsoUrl) - .installationScript( - installationKeySequence.replace("HOSTNAME", - vmSpecification.getVmName())).build()) - .network(networkSpec) - .credentials(new LoginCredentials(currentImage.username, currentImage.credential, null, true)) - .build(); - } + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) + .slot(0L).build(); + + NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); + + return MasterSpec + .builder() + .vm(vmSpecification) + .iso(IsoSpec.builder().sourcePath(localIsoUrl) + .installationScript(installationKeySequence.replace("HOSTNAME", vmSpecification.getVmName())).build()) + .network(networkSpec) + .credentials(new LoginCredentials(currentImage.username, currentImage.credential, null, true)).build(); + } @Override - public synchronized Master getIfPresent(Object key) { - checkArgument(key instanceof Image, - "this cache is for entries who's keys are Images"); - Image image = Image.class.cast(key); - if (masters.containsKey(image.getId())) { - return masters.get(image.getId()); - } - return null; - } + public synchronized Master getIfPresent(Object key) { + checkArgument(key instanceof Image, "this cache is for entries who's keys are Images"); + Image image = Image.class.cast(key); + if (masters.containsKey(image.getId())) { + return masters.get(image.getId()); + } + return null; + } - private String getFilePathOrDownload(String httpUrl, String md5) - throws ExecutionException { - String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1, - httpUrl.length()); + private String getFilePathOrDownload(String httpUrl, String expectedMd5) throws ExecutionException { + String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1, httpUrl.length()); URI provider = providerSupplier.get(); - if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), - provider.getPort()))) { + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { throw new RuntimeException("could not connect to virtualbox"); } File file = new File(isosDir, fileName); - List statements = Lists.newArrayList(); - statements.add(Statements.saveHttpResponseTo(URI.create(httpUrl), - isosDir, fileName)); + List statements = new ImmutableList.Builder().add( + Statements.saveHttpResponseTo(URI.create(httpUrl), isosDir, fileName)).build(); StatementList statementList = new StatementList(statements); - NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata - .apply(host.get()); - runScriptOnNodeFactory - .create(hostNodeMetadata, statementList, runAsRoot(false)).init() - .call(); + NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get()); + ListenableFuture future = runScriptOnNodeFactory.submit(hostNodeMetadata, statementList, + runAsRoot(false)); + Futures.getUnchecked(future); - ExecResponse response = runScriptOnNodeFactory - .create( - hostNodeMetadata, - Statements.exec("md5 " + isosDir + File.separator + fileName), - runAsRoot(false)).init().call(); - if (md5 != null) { - if (!Iterables.get( - Splitter.on("=").trimResults().split(response.getOutput()), 1) - .equals(md5)) - return null; + if (expectedMd5 != null) { + String filePath = isosDir + File.separator + fileName; + ListenableFuture md5future = runScriptOnNodeFactory.submit(hostNodeMetadata, new Md5(filePath), + runAsRoot(false)); + + ExecResponse responseMd5 = Futures.getUnchecked(md5future); + assert responseMd5.getExitStatus() == 0 : hostNodeMetadata.getId() + ": " + responseMd5; + checkNotNull(responseMd5.getOutput(), "iso_md5 missing"); + String actualMd5 = responseMd5.getOutput().trim(); + checkState(actualMd5.equals(expectedMd5), "md5 of %s is %s but expected %s", filePath, actualMd5, expectedMd5); } return file.getAbsolutePath(); } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java index 69d0510032..4ce43c55ba 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java @@ -52,13 +52,13 @@ import org.jclouds.virtualbox.statements.DeleteGShadowLock; import org.jclouds.virtualbox.util.MachineController; import org.jclouds.virtualbox.util.MachineUtils; import org.jclouds.virtualbox.util.NetworkUtils; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.LockType; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.LockType; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Optional; @@ -118,7 +118,7 @@ public class NodeCreator implements Function(cloned, @@ -185,8 +185,10 @@ public class NodeCreator implements Function { logger.debug("List of scancodes sent: ", maxOrLess); assert codesSent == maxOrLess.size(); if (any(maxOrLess, in(SPECIAL_KEYBOARD_BUTTON_MAP_LIST.values()))) { - Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS); + // in case of special keystroke we assume more time needed than normal (page refresh) + Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS); } else { - Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); + Uninterruptibles.sleepUninterruptibly(250, TimeUnit.MILLISECONDS); } } return null; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/StringToKeyCode.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/StringToKeyCode.java index 789d06f51a..b684618b66 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/StringToKeyCode.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/StringToKeyCode.java @@ -66,5 +66,4 @@ public class StringToKeyCode implements Function> { private boolean containsSpecialCharacter(String s) { return s.startsWith("<"); } - } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttached.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttached.java index 15480cdfa6..da3e9e1ab9 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttached.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttached.java @@ -22,12 +22,12 @@ package org.jclouds.virtualbox.functions; import java.util.concurrent.TimeUnit; import org.jclouds.logging.Logger; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.ISnapshot; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.ISnapshot; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Supplier; @@ -61,8 +61,6 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function { @@ -69,9 +72,8 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier // the functions and suppliers here are to ensure we don't do heavy i/o in injection @Inject public StartVBoxIfNotAlreadyRunning(Function, VirtualBoxManager> managerForNode, - Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier host, - @Provider Supplier providerSupplier, - HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) { + Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier host, + @Provider Supplier providerSupplier, HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) { this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.socketTester = checkNotNull(socketTester, "socketTester"); this.socketTester.seconds(3L); @@ -82,63 +84,57 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier } @PostConstruct - public synchronized void start() { + public void start() { URI provider = providerSupplier.get(); NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get()); - cleanUpHost(provider, hostNodeMetadata); - - logger.debug("disabling password access"); - runScriptOnNodeFactory - .create( - hostNodeMetadata, - Statements - .exec("VBoxManage setproperty websrvauthlibrary null"), - runAsRoot(false).wrapInInitScript(false)).init().call(); - logger.debug(">> starting vboxwebsrv"); - String vboxwebsrv = "vboxwebsrv -t0 -v -b -H " - + providerSupplier.get().getHost(); - runScriptOnNodeFactory - .create( - hostNodeMetadata, - Statements.exec(vboxwebsrv), - runAsRoot(false).wrapInInitScript(false) - .blockOnComplete(false).nameTask("vboxwebsrv")).init() - .call(); - if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), - provider.getPort()))) { - throw new RuntimeException("could not connect to virtualbox"); + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { + logger.debug("disabling password access"); + runScriptOnNodeFactory + .create(hostNodeMetadata, exec("VBoxManage setproperty websrvauthlibrary null"), + runAsRoot(false).wrapInInitScript(false)).init().call(); + + logger.debug(">> starting vboxwebsrv"); + String vboxwebsrv = "vboxwebsrv -t0 -v -b -H " + providerSupplier.get().getHost(); + runScriptOnNodeFactory + .create(hostNodeMetadata, exec(vboxwebsrv), + runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init() + .call(); + + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { + throw new UncheckedTimeoutException(String.format("could not connect to virtualbox at %s", provider)); + } } manager = managerForNode.apply(host); manager.connect(provider.toASCIIString(), "", ""); if (logger.isDebugEnabled()) if (manager.getSessionObject().getState() != SessionState.Unlocked) - logger.warn("manager is not in unlocked state " - + manager.getSessionObject().getState()); + logger.warn("manager is not in unlocked state " + manager.getSessionObject().getState()); + } - private void cleanUpHost(URI provider, NodeMetadata hostNodeMetadata) { + public void cleanUpHost() { // kill previously started vboxwebsrv (possibly dirty session) - List statements = Lists.newArrayList(); - statements.add(Statements.findPid("vboxwebsrv")); - statements.add(Statements.kill()); + URI provider = providerSupplier.get(); + NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get()); + List statements = new ImmutableList.Builder() + .add(findPid("vboxwebsrv")) + .add(kill()).build(); StatementList statementList = new StatementList(statements); - - if (socketTester.apply(HostAndPort.fromParts(provider.getHost(), - provider.getPort()))) { + + if (socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { logger.debug(String.format("shutting down previously started vboxwewbsrv at %s", provider)); - ExecResponse execResponse = runScriptOnNodeFactory - .create(hostNodeMetadata, statementList, runAsRoot(false)) + ExecResponse execResponse = runScriptOnNodeFactory.create(hostNodeMetadata, statementList, runAsRoot(false)) .init().call(); - if(execResponse.getExitStatus()!=0) - throw new RuntimeException("Cannot execute jclouds"); + if (execResponse.getExitStatus() != 0) + throw new RuntimeException(String.format("Cannot shutdown a running vboxwebsrv at %s. ExecResponse: %s", provider, execResponse)); } } - + @Override public VirtualBoxManager get() { - checkState(manager != null, "start not called"); + checkState(manager != null, "VirtualBoxManager is not initialised"); return manager; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java index d530058a87..701439990b 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMedia.java @@ -52,11 +52,11 @@ import org.jclouds.logging.Logger; import org.jclouds.virtualbox.domain.ErrorCode; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; -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.VBoxException; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.VBoxException; import com.google.common.base.Function; import com.google.common.base.Predicate; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndForceDeleteItsMedia.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndForceDeleteItsMedia.java index c0616ac121..4a97187dd6 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndForceDeleteItsMedia.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndForceDeleteItsMedia.java @@ -49,12 +49,12 @@ import javax.inject.Singleton; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.virtualbox.domain.ErrorCode; -import org.virtualbox_4_1.CleanupMode; -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.VBoxException; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.VBoxException; import com.google.common.base.Function; import com.google.common.base.Throwables; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMachinePredicates.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMachinePredicates.java index 326d0d5074..60499aab7d 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMachinePredicates.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMachinePredicates.java @@ -25,10 +25,10 @@ import static org.jclouds.virtualbox.predicates.IMediumPredicates.deviceTypeEqua import static org.jclouds.virtualbox.predicates.IMediumPredicates.hasParent; import static org.jclouds.virtualbox.predicates.IMediumPredicates.machineIdsContain; import static org.jclouds.virtualbox.util.IMediumAttachments.toMedium; -import static org.virtualbox_4_1.DeviceType.HardDisk; +import static org.virtualbox_4_2.DeviceType.HardDisk; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; import com.google.common.base.Predicate; @@ -58,11 +58,9 @@ public class IMachinePredicates { public String toString() { return "isLinkedClone()"; } - } public static Predicate isLinkedClone() { return IsLinkedClone.INSTANCE; } - } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMediumPredicates.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMediumPredicates.java index 8192ad5e48..85a4fa1bf0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMediumPredicates.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/IMediumPredicates.java @@ -22,8 +22,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.equalTo; import static com.google.common.collect.Iterables.any; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMedium; import com.google.common.base.Predicate; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java index 2df684c394..88ef7186a2 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/EnableNetworkInterface.java @@ -82,5 +82,4 @@ public class EnableNetworkInterface implements Statement { throw new UnsupportedOperationException("windows not yet implemented"); return statements.render(family); } - } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/InstallGuestAdditions.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/InstallGuestAdditions.java index a5cef31aa7..f5758a3f3d 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/InstallGuestAdditions.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/InstallGuestAdditions.java @@ -78,7 +78,7 @@ public class InstallGuestAdditions implements Statement { return false; } }).isPresent()) { - statements.add(exec("mount -t iso9660 /dev/sr1 " + mountPoint)); + statements.add(exec("mount -t iso9660 /dev/cdrom1 " + mountPoint)); } else { String vboxGuestAdditionsIso = "VBoxGuestAdditions_" + vboxVersion + ".iso"; URI download = URI.create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/" @@ -87,7 +87,7 @@ public class InstallGuestAdditions implements Statement { statements.add(saveHttpResponseTo(download, "{tmp}{fs}", vboxGuestAdditionsIso));// statements.add(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint))); } - statements.add(exec(String.format("%s%s", mountPoint, "/VBoxLinuxAdditions.run --nox11"))); // + statements.add(exec(String.format("%s%s", mountPoint, "/VBoxLinuxAdditions.run --nox11"))); return statements; } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/Md5.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/Md5.java new file mode 100644 index 0000000000..e49bb30a30 --- /dev/null +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/Md5.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 + * + * 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.statements; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.scriptbuilder.domain.Statement; + +import com.google.common.collect.ImmutableList; + +public class Md5 implements Statement { + + private final String filePath; + + public Md5(String filePath) { + this.filePath = checkNotNull(filePath, "filePath"); + } + + @Override + public Iterable functionDependencies(OsFamily family) { + return ImmutableList.of(); + } + + @Override + public String render(OsFamily family) { + if (checkNotNull(family, "family") == OsFamily.WINDOWS) + throw new UnsupportedOperationException("windows not yet implemented"); + return String.format("command -v md5sum >/dev/null 2>&1 && md5sum %s | awk '{print $1}' " + + "|| command -v md5 >/dev/null 2>&1 && md5 %s | awk '{ print $4 }'", filePath, filePath); + } + +} diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/SetHostname.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/SetHostname.java new file mode 100644 index 0000000000..13bc863450 --- /dev/null +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/SetHostname.java @@ -0,0 +1,55 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 + * + * 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.statements; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.scriptbuilder.domain.Statement; + +import com.google.common.collect.ImmutableList; + +/** + * Set hostname + * + * @author andrea turli + * + */ +public class SetHostname implements Statement { + + private final String publicIpAddress; + + public SetHostname(String publicIpAddress) { + this.publicIpAddress = checkNotNull(publicIpAddress, "publicIpAddress"); + } + + @Override + public Iterable functionDependencies(OsFamily family) { + return ImmutableList.of(); + } + + @Override + public String render(OsFamily family) { + if (checkNotNull(family, "family") == OsFamily.WINDOWS) + throw new UnsupportedOperationException("windows not yet implemented"); + return String.format("sudo hostname %s", publicIpAddress); + } + +} + diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/IMediumAttachments.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/IMediumAttachments.java index a74bd523b9..15fa1ddf86 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/IMediumAttachments.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/IMediumAttachments.java @@ -18,8 +18,8 @@ */ package org.jclouds.virtualbox.util; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IMediumAttachment; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IMediumAttachment; import com.google.common.base.Function; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineController.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineController.java index 5983a9e0dc..993a3dbb06 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineController.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineController.java @@ -19,6 +19,7 @@ package org.jclouds.virtualbox.util; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; import java.util.List; import java.util.concurrent.TimeUnit; @@ -29,19 +30,20 @@ import javax.inject.Singleton; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; +import org.jclouds.predicates.RetryableNumTimesPredicate; import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning; -import org.virtualbox_4_1.AdditionsFacilityStatus; -import org.virtualbox_4_1.AdditionsFacilityType; -import org.virtualbox_4_1.AdditionsRunLevelType; -import org.virtualbox_4_1.IAdditionsFacility; -import org.virtualbox_4_1.IMachine; -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.SessionState; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.AdditionsFacilityStatus; +import org.virtualbox_4_2.AdditionsFacilityType; +import org.virtualbox_4_2.AdditionsRunLevelType; +import org.virtualbox_4_2.IAdditionsFacility; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.LockType; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Optional; @@ -49,7 +51,6 @@ import com.google.common.base.Predicate; import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; -import com.google.common.util.concurrent.Uninterruptibles; import com.google.inject.Inject; /** @@ -81,66 +82,11 @@ public class MachineController { IMachine machine = manager.get().getVBox().findMachine(vmName); while (!machine.getState().equals(MachineState.Running)) { try { - session = machineUtils.applyForMachine(vmName, - new LaunchMachineIfNotAlreadyRunning(manager.get(), - executionType, "")); + session = machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), + executionType, "")); } catch (RuntimeException e) { - if (e.getMessage() - .contains( - "org.virtualbox_4_1.VBoxException: VirtualBox error: The given session is busy (0x80BB0007)")) { - throw e; - } else if (e.getMessage().contains( - "VirtualBox error: The object is not ready")) { - continue; - } else { - throw e; - } - } - } - // for scancode - Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS); - - String guestAdditionsInstalled = machineUtils.sharedLockMachineAndApplyToSession(vmName, - new Function() { - - @Override - public String apply(ISession session) { - int attempts = 0; - String guestAdditionsInstalled = null; - while (!!session.getConsole().getGuest() - .getAdditionsVersion().isEmpty() && attempts < 3) { - Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS); - guestAdditionsInstalled = session.getConsole().getGuest() - .getAdditionsVersion(); - attempts++; - } - return guestAdditionsInstalled; - } - - }); - if(!Strings.nullToEmpty(guestAdditionsInstalled).isEmpty()) { - waitVBoxServiceIsActive(vmName); - } - - return checkNotNull(session, "session"); - } - - public ISession ensureMachineHasPowerDown(String vmName) { - ISession session = manager.get().getSessionObject(); - IMachine machine = manager.get().getVBox().findMachine(vmName); - while (!machine.getState().equals(MachineState.PoweredOff)) { - try { - session = machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, - new Function() { - @Override - public ISession apply(ISession session) { - IProgress powerDownProgress = session.getConsole().powerDown(); - powerDownProgress.waitForCompletion(-1); - return session; - } - }); - } catch (RuntimeException e) { - if (e.getMessage().contains("Invalid machine state: PoweredOff")) { + if (e.getMessage().contains( + "org.virtualbox_4_2.VBoxException: VirtualBox error: The given session is busy (0x80BB0007)")) { throw e; } else if (e.getMessage().contains("VirtualBox error: The object is not ready")) { continue; @@ -149,30 +95,58 @@ public class MachineController { } } } - safeCheckMachineIsUnlocked(machine); + + String guestAdditionsInstalled = machineUtils.sharedLockMachineAndApplyToSession(vmName, + new Function() { + @Override + public String apply(ISession session) { + new RetryableNumTimesPredicate(new FacilitiesPredicate(session), + 5, 3L, TimeUnit.SECONDS).apply(4); + String guestAdditionsInstalled = session.getConsole().getGuest().getAdditionsVersion(); + return guestAdditionsInstalled; + } + + }); + if (!Strings.nullToEmpty(guestAdditionsInstalled).isEmpty()) { + logger.debug("<< guest additions(%s) installed on vm(%s)", guestAdditionsInstalled, vmName); + waitVBoxServiceIsActive(vmName); + } else { + logger.debug("<< guest additions not available on(%s)", vmName); + } return checkNotNull(session, "session"); } - - /** + + public ISession ensureMachineHasPowerDown(String vmName) { + ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function() { + @Override + public ISession apply(ISession session) { + IProgress powerdownIProgress = session.getConsole().powerDown(); + powerdownIProgress.waitForCompletion(-1); + return session; + } + }); + return checkNotNull(session, "session"); + } + + /** * if machine supports ACPI it can be shutdown gently - not powerdown() * http://askubuntu.com/questions/82015/shutting-down-ubuntu-server-running-in-headless-virtualbox */ public ISession ensureMachineIsShutdown(String vmName) { - IMachine machine = manager.get().getVBox().findMachine(vmName); - ISession session = machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, - new Function() { - @Override - public ISession apply(ISession session) { - session.getConsole().powerButton(); - return session; - } - }); - safeCheckMachineIsUnlocked(machine); + ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function() { + @Override + public ISession apply(ISession session) { + session.getConsole().powerButton(); + return session; + } + }); + checkState(new RetryableNumTimesPredicate( + new MachineStatePredicate(manager.get().getVBox(), vmName), 5, + 3L, TimeUnit.SECONDS).apply(MachineState.PoweredOff), "vm(%s) is not shutdown correctly", vmName); return checkNotNull(session, "session"); } public void ensureMachineIsPaused(String vmName) { - IMachine machine = manager.get().getVBox().findMachine(vmName); while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Paused)) { try { machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function() { @@ -195,11 +169,9 @@ public class MachineController { } } } - safeCheckMachineIsUnlocked(machine); } - + public void ensureMachineIsResumed(String vmName) { - IMachine machine = manager.get().getVBox().findMachine(vmName); while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Running)) { try { machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function() { @@ -211,8 +183,7 @@ public class MachineController { }); } catch (RuntimeException e) { // sometimes the machine might be powered of between the while - // test and the call to - // lockSessionOnMachineAndApply + // test and the call to lockSessionOnMachineAndApply if (e.getMessage().contains("Invalid machine state: Resumed")) { return; } else if (e.getMessage().contains("VirtualBox error: The object is not ready")) { @@ -222,58 +193,74 @@ public class MachineController { } } } - safeCheckMachineIsUnlocked(machine); } - - private void safeCheckMachineIsUnlocked(IMachine machine) { - int guard = 0; - while (!machine.getSessionState().equals(SessionState.Unlocked)) { - if(guard >= 5) { - logger.warn("Machine session (%s) possibly still unlocked!!!", machine.getName()); - break; - } - logger.debug("Machine session (%s) not unlocked - wait ...", machine.getName()); - Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS); - guard++; - } - logger.debug("Machine session (%s) is %s", machine.getName(), machine.getSessionState()); - } - - private void waitVBoxServiceIsActive(String vmName) { + + private void waitVBoxServiceIsActive(final String vmName) { machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function() { @Override public Void apply(ISession session) { - session.getConsole().getGuest().setStatisticsUpdateInterval(1l); - while (!session.getConsole().getGuest().getAdditionsStatus(AdditionsRunLevelType.Userland)) { - Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); - } - - List facilities = session.getConsole().getGuest().getFacilities(); - while (facilities.size() != 4) { - Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); - facilities = session.getConsole().getGuest().getFacilities(); - } - facilities = session.getConsole().getGuest().getFacilities(); - + checkState(new RetryableNumTimesPredicate(new AdditionsStatusPredicate(session), + 5, 2L, TimeUnit.SECONDS).apply(AdditionsRunLevelType.Userland), "timed out waiting for additionsRunLevelType to be %s", AdditionsRunLevelType.Userland); + checkState(new RetryableNumTimesPredicate(new FacilitiesPredicate(session), + 5, 3L, TimeUnit.SECONDS).apply(4), "timed out waiting for 4 running facilities"); Optional vboxServiceFacility = Optional.absent(); while (!vboxServiceFacility.isPresent()) { - vboxServiceFacility = Iterables.tryFind(session.getConsole().getGuest().getFacilities(), - new Predicate() { - @Override - public boolean apply(IAdditionsFacility additionsFacility) { - return additionsFacility.getType().equals(AdditionsFacilityType.VBoxService); - }; - }); + List facilities = session.getConsole().getGuest().getFacilities(); + vboxServiceFacility = Iterables.tryFind(facilities, new Predicate() { + @Override + public boolean apply(IAdditionsFacility additionsFacility) { + return additionsFacility.getType().equals(AdditionsFacilityType.VBoxService) + && additionsFacility.getStatus().equals(AdditionsFacilityStatus.Active); + } + }); } - - while(!vboxServiceFacility.get().getStatus().equals(AdditionsFacilityStatus.Active)) { - Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); - } - Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS); + logger.debug("<< virtualbox service ready on vm(%s)", vmName); return null; } }); } + + private static class AdditionsStatusPredicate implements Predicate { + private final ISession session; + + AdditionsStatusPredicate(ISession session) { + this.session = session; + } + + @Override + public boolean apply(AdditionsRunLevelType input) { + return session.getConsole().getGuest().getAdditionsStatus(input); + } + } + + private static class FacilitiesPredicate implements Predicate { + private final ISession session; + + FacilitiesPredicate(ISession session) { + this.session = session; + } + + @Override + public boolean apply(Integer input) { + return session.getConsole().getGuest().getFacilities().size() == input; + } + } + + private static class MachineStatePredicate implements Predicate { + private final IVirtualBox virtualBox; + private final String vmName; + + MachineStatePredicate(IVirtualBox virtualBox, String vmName) { + this.virtualBox = virtualBox; + this.vmName = vmName; + } + + @Override + public boolean apply(MachineState input) { + MachineState state = virtualBox.findMachine(vmName).getState(); + return state.equals(input); + } + } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineNameOrIdAndNicSlot.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineNameOrIdAndNicSlot.java index 99fd1c5304..1c1017dc5e 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineNameOrIdAndNicSlot.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineNameOrIdAndNicSlot.java @@ -7,6 +7,7 @@ import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Objects; import com.google.common.base.Splitter; +import com.google.common.base.Strings; import com.google.common.collect.Iterables; @@ -61,32 +62,19 @@ public final class MachineNameOrIdAndNicSlot { return new MachineNameOrIdAndNicSlot(checkNotNull(machineNameOrId, "machineNameOrId"), slot); } - public static MachineNameOrIdAndNicSlot fromString( - String machineNameOrIdAndNicSlotString) { - checkNotNull(machineNameOrIdAndNicSlotString); - String machineNameOrId = null; - String nicSlotString = null; - - Iterable splittedString = Splitter.on(SEPARATOR).split( - machineNameOrIdAndNicSlotString); + public static MachineNameOrIdAndNicSlot fromString(String machineNameOrIdAndNicSlotString) { + Iterable splittedString = Splitter.on(SEPARATOR).split(machineNameOrIdAndNicSlotString); checkState(Iterables.size(splittedString) == 2); - machineNameOrId = Iterables.get(splittedString, 0); - nicSlotString = Iterables.get(splittedString, 1); - - long slot = -1; - if (nicSlotString != null) { - checkArgument(!nicSlotString.startsWith("+"), - "Unparseable slot number: %s", nicSlotString); - try { - slot = Long.parseLong(nicSlotString); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Unparseable slot number: " - + nicSlotString); - } - checkArgument(isValidSlot(slot), "Slot number out of range: %s", - nicSlotString); + String machineNameOrId = Strings.nullToEmpty(Iterables.get(splittedString, 0)); + String nicSlotString = Strings.nullToEmpty(Iterables.get(splittedString, 1)); + checkArgument(!nicSlotString.startsWith("+"), "Unparseable slot number: %s", nicSlotString); + try { + long slot = Long.parseLong(nicSlotString); + checkArgument(isValidSlot(slot), "Slot number out of range: %s", nicSlotString); + return new MachineNameOrIdAndNicSlot(machineNameOrId, slot); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Unparseable slot number: " + nicSlotString); } - return new MachineNameOrIdAndNicSlot(machineNameOrId, slot); } public MachineNameOrIdAndNicSlot withDefaultSlot(int defaultSlot) { diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java index 768ff7e501..ac76ec7b44 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/MachineUtils.java @@ -34,17 +34,19 @@ import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; +import org.jclouds.predicates.RetryableNumTimesPredicate; import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.util.Throwables2; import org.jclouds.virtualbox.functions.IpAddressesLoadingCache; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.LockType; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.LockType; +import org.virtualbox_4_2.SessionState; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Uninterruptibles; @@ -202,12 +204,15 @@ public class MachineUtils { throw new RuntimeException(String.format("error applying %s to %s with %s lock: %s", function, machineId, type, e.getMessage()), e); } finally { + // this is a workaround for shared lock type, where session state is not updated immediately + if(type == LockType.Shared) { + Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); + } if (session.getState().equals(SessionState.Locked)) { session.unlockMachine(); - while (!session.getState().equals(SessionState.Unlocked)) { - logger.debug("Session not unlocked - wait ..."); - Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); - } + } + if(!session.getState().equals(SessionState.Unlocked)) { + checkSessionIsUnlocked(session, 5, 3L, TimeUnit.SECONDS); } } } @@ -215,8 +220,7 @@ public class MachineUtils { private ISession lockSession(String machineId, LockType type, int retries) { int count = 0; IMachine immutableMachine = manager.get().getVBox().findMachine(machineId); - ISession session = null; - + ISession session = null; while (true) { try { session = manager.get().getSessionObject(); @@ -239,12 +243,6 @@ public class MachineUtils { checkState(session.getState().equals(SessionState.Locked)); return checkNotNull(session, "session"); } - - void print() { - for (StackTraceElement element : Thread.currentThread().getStackTrace()){ - System.err.println(element.toString()); - } - } /** * @param machineId @@ -270,5 +268,24 @@ public class MachineUtils { return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ") || e.getMessage().contains("Could not find a registered machine with UUID {"); } + + private void checkSessionIsUnlocked(ISession session, int attempts, long period, TimeUnit timeUnit) { + checkState(new RetryableNumTimesPredicate(new SessionStatePredicate(session), + attempts, period, timeUnit).apply(SessionState.Unlocked), + "timed out or number of retries(%s) reached waiting for session to be unlocked", attempts); + } + + private static class SessionStatePredicate implements Predicate { + private final ISession session; + + SessionStatePredicate(ISession session) { + this.session = session; + } + + @Override + public boolean apply(SessionState input) { + return session.getState().equals(input); + } + } } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java index 73ddb4e247..fba6a13f81 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java @@ -25,7 +25,6 @@ import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; import java.net.URI; import java.util.List; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,23 +50,21 @@ import org.jclouds.virtualbox.functions.RetrieveActiveBridgedInterfaces; import org.jclouds.virtualbox.statements.EnableNetworkInterface; import org.jclouds.virtualbox.statements.GetIPAddressFromMAC; import org.jclouds.virtualbox.statements.ScanNetworkWithPing; -import org.virtualbox_4_1.HostNetworkInterfaceType; -import org.virtualbox_4_1.IDHCPServer; -import org.virtualbox_4_1.IHostNetworkInterface; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.LockType; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.HostNetworkInterfaceType; +import org.virtualbox_4_2.IDHCPServer; +import org.virtualbox_4_2.IHostNetworkInterface; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.VirtualBoxManager; -import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.util.concurrent.Uninterruptibles; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; /** @@ -78,11 +75,11 @@ import com.google.inject.Inject; @Singleton public class NetworkUtils { - + // TODO parameterize public static final int MASTER_PORT = 2222; private static final String VIRTUALBOX_HOST_GATEWAY = "10.0.2.15"; - + @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -97,68 +94,59 @@ public class NetworkUtils { @Inject public NetworkUtils(Supplier manager, MachineUtils machineUtils, - MachineController machineController, - Supplier host, - @Provider Supplier providerSupplier, - IpAddressesLoadingCache ipAddressesLoadingCache, - Supplier hostSupplier, + MachineController machineController, Supplier host, @Provider Supplier providerSupplier, + IpAddressesLoadingCache ipAddressesLoadingCache, Supplier hostSupplier, RunScriptOnNode.Factory scriptRunnerFactory) { this.manager = manager; this.machineUtils = machineUtils; - this.host = checkNotNull(host, "host"); - this.providerSupplier = checkNotNull(providerSupplier, - "endpoint to virtualbox websrvd is needed"); + this.host = checkNotNull(host, "host can't be null"); + this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox web server can't be null"); this.ipAddressesLoadingCache = ipAddressesLoadingCache; this.scriptRunnerFactory = scriptRunnerFactory; this.hostSupplier = hostSupplier; } public NetworkSpec createNetworkSpecWhenVboxIsLocalhost() { - NetworkAdapter natAdapter = NetworkAdapter.builder() - .networkAttachmentType(NetworkAttachmentType.NAT) - .build(); + NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT).build(); - NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder() - .addNetworkAdapter(natAdapter) - .slot(1L) + NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(1L).build(); + NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly) .build(); - NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder() - .networkAttachmentType(NetworkAttachmentType.HostOnly) - .build(); - // create new hostOnly interface if needed, otherwise use the one already there with dhcp enabled ... + // create new hostOnly interface if needed, otherwise use the one already + // there with dhcp enabled ... String hostOnlyIfName = getHostOnlyIfOrCreate(); NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter) - .addHostInterfaceName(hostOnlyIfName).slot(0L).build(); + .addHostInterfaceName(hostOnlyIfName).slot(0L).build(); return createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard); } - - public boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) { - ExecResponse execResponse = null; - try { - execResponse = machineUtils.runScriptOnNode(nodeMetadata, - new EnableNetworkInterface(networkInterfaceCard), RunScriptOptions.NONE).get(); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } catch (ExecutionException e) { - logger.error(e.getMessage()); - } - if(execResponse == null) - return false; - return execResponse.getExitStatus() == 0; - } - - private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard, - NetworkInterfaceCard hostOnlyIfaceCard) { - return NetworkSpec.builder() - .addNIC(hostOnlyIfaceCard) - .addNIC(natIfaceCard) + + public NetworkInterfaceCard createHostOnlyNIC(long port) { + NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly) .build(); + // create new hostOnly interface if needed, otherwise use the one already + // there with dhcp enabled ... + String hostOnlyIfName = getHostOnlyIfOrCreate(); + return NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter).addHostInterfaceName(hostOnlyIfName) + .slot(port).build(); } - public String getHostOnlyIfOrCreate() { + public boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) { + ListenableFuture execEnableNetworkInterface = null; + execEnableNetworkInterface = machineUtils.runScriptOnNode(nodeMetadata, new EnableNetworkInterface( + networkInterfaceCard), RunScriptOptions.NONE); + ExecResponse execEnableNetworkInterfaceResponse = Futures.getUnchecked(execEnableNetworkInterface); + return execEnableNetworkInterfaceResponse.getExitStatus() == 0; + } + + private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard, + NetworkInterfaceCard hostOnlyIfaceCard) { + return NetworkSpec.builder().addNIC(hostOnlyIfaceCard).addNIC(natIfaceCard).build(); + } + + public String getHostOnlyIfOrCreate() { IHostNetworkInterface availableHostInterfaceIf = returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(manager - .get().getVBox().getHost().getNetworkInterfaces()); - if (availableHostInterfaceIf==null) { + .get().getVBox().getHost().getNetworkInterfaces()); + if (availableHostInterfaceIf == null) { final String hostOnlyIfName = createHostOnlyIf(); assignDHCPtoHostOnlyInterface(hostOnlyIfName); return hostOnlyIfName; @@ -168,17 +156,17 @@ public class NetworkUtils { } private void assignDHCPtoHostOnlyInterface(final String hostOnlyIfName) { - List availableNetworkInterfaces = manager.get().getVBox().getHost() - .getNetworkInterfaces(); - - IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter(availableNetworkInterfaces, new Predicate() { + List availableNetworkInterfaces = manager.get().getVBox().getHost().getNetworkInterfaces(); + + IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter( + availableNetworkInterfaces, new Predicate() { + + @Override + public boolean apply(IHostNetworkInterface iHostNetworkInterface) { + return iHostNetworkInterface.getName().equals(hostOnlyIfName); + } + })); - @Override - public boolean apply(IHostNetworkInterface iHostNetworkInterface) { - return iHostNetworkInterface.getName().equals(hostOnlyIfName); - } - })); - String hostOnlyIfIpAddress = iHostNetworkInterfaceWithHostOnlyIfName.getIPAddress(); String dhcpIpAddress = hostOnlyIfIpAddress.substring(0, hostOnlyIfIpAddress.lastIndexOf(".")) + ".254"; String dhcpNetmask = "255.255.255.0"; @@ -187,152 +175,135 @@ public class NetworkUtils { NodeMetadata hostNodeMetadata = getHostNodeMetadata(); ExecResponse response = scriptRunnerFactory - .create(hostNodeMetadata, - Statements.exec(String - .format("VBoxManage dhcpserver add --ifname %s --ip %s --netmask %s --lowerip %s --upperip %s --enable", - hostOnlyIfName, dhcpIpAddress, dhcpNetmask, dhcpLowerIp, dhcpUpperIp)), runAsRoot(false).wrapInInitScript(false)).init().call(); - checkState(response.getExitStatus()==0); + .create( + hostNodeMetadata, + Statements.exec(String + .format( + "VBoxManage dhcpserver add --ifname %s --ip %s --netmask %s --lowerip %s --upperip %s --enable", + hostOnlyIfName, dhcpIpAddress, dhcpNetmask, dhcpLowerIp, dhcpUpperIp)), + runAsRoot(false).wrapInInitScript(false)).init().call(); + checkState(response.getExitStatus() == 0); } private String createHostOnlyIf() { - final String hostOnlyIfName; NodeMetadata hostNodeMetadata = getHostNodeMetadata(); ExecResponse createHostOnlyResponse = scriptRunnerFactory - .create(hostNodeMetadata, Statements.exec("VBoxManage hostonlyif create"), - runAsRoot(false).wrapInInitScript(false)).init().call(); + .create(hostNodeMetadata, Statements.exec("VBoxManage hostonlyif create"), + runAsRoot(false).wrapInInitScript(false)).init().call(); String output = createHostOnlyResponse.getOutput(); - checkState(createHostOnlyResponse.getExitStatus()==0); - checkState(output.contains("'"), "cannot create hostonlyif"); - hostOnlyIfName = output.substring(output.indexOf("'") + 1, output.lastIndexOf("'")); - return hostOnlyIfName; + checkState(createHostOnlyResponse.getExitStatus() == 0, "cannot create hostonly interface "); + checkState(output.contains("'"), "cannot create hostonly interface"); + return output.substring(output.indexOf("'") + 1, output.lastIndexOf("'")); } private NodeMetadata getHostNodeMetadata() { - NodeMetadata hostNodeMetadata = NodeMetadataBuilder - .fromNodeMetadata(host.get()) - .publicAddresses( - ImmutableList.of(providerSupplier.get().getHost())) - .build(); - return hostNodeMetadata; + return NodeMetadataBuilder.fromNodeMetadata(host.get()) + .publicAddresses(ImmutableList.of(providerSupplier.get().getHost())).build(); } - private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(Iterable availableNetworkInterfaces) { + private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull( + Iterable availableNetworkInterfaces) { checkNotNull(availableNetworkInterfaces); - return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces), null); + return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces), + null); } /** - * @param availableNetworkInterfaces + * @param availableNetworkInterfaces * @param hostOnlyIfIpAddress * @return */ - private Iterable filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(Iterable availableNetworkInterfaces) { - Iterable filteredNetworkInterfaces = Iterables.filter(availableNetworkInterfaces, new Predicate() { - @Override - public boolean apply(IHostNetworkInterface iHostNetworkInterface) { - // this is an horrible workaround cause iHostNetworkInterface.getDhcpEnabled is working only for windows host - boolean match = false; - List availableDHCPservers = manager.get().getVBox().getDHCPServers(); - for (IDHCPServer idhcpServer : availableDHCPservers) { - if(idhcpServer.getEnabled() && idhcpServer.getNetworkName().equals(iHostNetworkInterface.getNetworkName())) - match = true; - } - return iHostNetworkInterface.getInterfaceType().equals(HostNetworkInterfaceType.HostOnly) && - match; - } - }); + private Iterable filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled( + Iterable availableNetworkInterfaces) { + Iterable filteredNetworkInterfaces = Iterables.filter(availableNetworkInterfaces, + new Predicate() { + @Override + public boolean apply(IHostNetworkInterface iHostNetworkInterface) { + // this is an horrible workaround cause + // iHostNetworkInterface.getDhcpEnabled is working only for + // windows host + boolean match = false; + List availableDHCPservers = manager.get().getVBox().getDHCPServers(); + for (IDHCPServer idhcpServer : availableDHCPservers) { + if (idhcpServer.getEnabled() + && idhcpServer.getNetworkName().equals(iHostNetworkInterface.getNetworkName())) + match = true; + } + return iHostNetworkInterface.getInterfaceType().equals(HostNetworkInterfaceType.HostOnly) && match; + } + }); return filteredNetworkInterfaces; } - - public String getIpAddressFromNicSlot(String machineNameOrId, long nicSlot) { - MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = - MachineNameOrIdAndNicSlot.fromParts(machineNameOrId, nicSlot); - logger.debug("Looking for an available IP address for %s at slot %s ...", - machineNameOrIdAndNicSlot.getMachineNameOrId(), - machineNameOrIdAndNicSlot.getSlotText()); - try { - String ipAddress = ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot); - while(!isValidIpForHostOnly(machineNameOrIdAndNicSlot, ipAddress)) { + public String getValidHostOnlyIpFromVm(String machineNameOrId) { + long nicSlot = 0; + String ipAddress = ""; + while (nicSlot < 4 && ipAddress.isEmpty()) { + MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = MachineNameOrIdAndNicSlot.fromParts(machineNameOrId, + nicSlot); + ipAddress = getIpAddressFromNicSlot(machineNameOrIdAndNicSlot); + if (!isValidIpForHostOnly(machineNameOrIdAndNicSlot, ipAddress)) { ipAddressesLoadingCache.invalidate(machineNameOrIdAndNicSlot); - ipAddress = ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot); + ipAddress = ""; } - logger.debug("Found an available IP address %s for guest: %s at slot: %s", - ipAddress, - machineNameOrIdAndNicSlot.getMachineNameOrId(), - machineNameOrIdAndNicSlot.getSlotText()); - return ipAddress; + nicSlot++; + } + return checkNotNull(Strings.emptyToNull(ipAddress), + String.format("Cannot find a valid IP address for the %s's HostOnly NIC", machineNameOrId)); + } + + public String getIpAddressFromNicSlot(String machineNameOrId, long nicSlot) { + MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = MachineNameOrIdAndNicSlot.fromParts(machineNameOrId, + nicSlot); + return getIpAddressFromNicSlot(machineNameOrIdAndNicSlot); + } + + public String getIpAddressFromNicSlot(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot) { + try { + return ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot); } catch (ExecutionException e) { logger.error("Problem in using the ipAddressCache", e.getCause()); throw Throwables.propagate(e); } } - + + public boolean isValidIpForHostOnly(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot, String ip) { + return !ip.isEmpty() && isIpv4(ip) && !ipBelongsToNatRange(ip) && !ipEqualsToNatGateway(ip); + } + public static boolean isIpv4(String s) { - String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." - + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." - + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; + String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; Pattern pattern = Pattern.compile(IP_V4_ADDRESS_PATTERN); Matcher matcher = pattern.matcher(s); return matcher.matches(); } - - public boolean isValidIpForHostOnly(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot, String ip) { - final String vmNameOrId = machineNameOrIdAndNicSlot.getMachineNameOrId(); - IMachine machine = manager.get().getVBox().findMachine(vmNameOrId); - long slot = machineNameOrIdAndNicSlot.getSlot(); - - if(ip.equals(VIRTUALBOX_HOST_GATEWAY) || !isValidHostOnlyIpAddress(ip, slot, machine)) { - // restart vm - logger.debug("reset node (%s) to refresh guest properties.", vmNameOrId); - machineUtils.lockSessionOnMachineAndApply(vmNameOrId, LockType.Shared, - new Function() { - @Override - public Void apply(ISession session) { - session.getConsole().reset(); - long time = 15; - logger.debug("Waiting %s secs for the reset of (%s) ...", time, vmNameOrId); - Uninterruptibles.sleepUninterruptibly(time, TimeUnit.SECONDS); - return null; - } - }); - return false; - } - return true; - } - public static boolean isValidHostOnlyIpAddress(String ip, long slot, - IMachine machine) { - boolean result = isIpv4(ip) && machine.getNetworkAdapter(slot).getAttachmentType().equals(NetworkAttachmentType.HostOnly) - && !ipBelongsToNatRange(ip); - return result; + private static boolean ipEqualsToNatGateway(String ip) { + return ip.equals(VIRTUALBOX_HOST_GATEWAY); } private static boolean ipBelongsToNatRange(String ip) { return ip.startsWith("10.0.3"); } - - protected String getIpAddressFromBridgedNIC(INetworkAdapter networkAdapter, - String network) { + + protected String getIpAddressFromBridgedNIC(INetworkAdapter networkAdapter, String network) { // RetrieveActiveBridgedInterfaces - List activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(scriptRunnerFactory).apply(hostSupplier.get()); + List activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(scriptRunnerFactory) + .apply(hostSupplier.get()); BridgedIf activeBridgedIf = checkNotNull(Iterables.get(activeBridgedInterfaces, 0), "activeBridgedInterfaces"); network = activeBridgedIf.getIpAddress(); - + // scan ip - RunScriptOnNode ipScanRunScript = scriptRunnerFactory.create( - hostSupplier.get(), new ScanNetworkWithPing(network), - RunScriptOptions.NONE); + RunScriptOnNode ipScanRunScript = scriptRunnerFactory.create(hostSupplier.get(), + new ScanNetworkWithPing(network), RunScriptOptions.NONE); ExecResponse execResponse = ipScanRunScript.init().call(); checkState(execResponse.getExitStatus() == 0); // retrieve ip from mac - RunScriptOnNode getIpFromMACAddressRunScript = scriptRunnerFactory - .create(hostSupplier.get(), new GetIPAddressFromMAC( - networkAdapter.getMACAddress()), - RunScriptOptions.NONE); - ExecResponse ipExecResponse = getIpFromMACAddressRunScript.init() - .call(); + RunScriptOnNode getIpFromMACAddressRunScript = scriptRunnerFactory.create(hostSupplier.get(), + new GetIPAddressFromMAC(networkAdapter.getMACAddress()), RunScriptOptions.NONE); + ExecResponse ipExecResponse = getIpFromMACAddressRunScript.init().call(); checkState(ipExecResponse.getExitStatus() == 0); return checkNotNull(ipExecResponse.getOutput(), "ipAddress"); } diff --git a/labs/virtualbox/src/main/resources/default-images.yaml b/labs/virtualbox/src/main/resources/default-images.yaml index fe4c0c82d3..e6be3668dd 100644 --- a/labs/virtualbox/src/main/resources/default-images.yaml +++ b/labs/virtualbox/src/main/resources/default-images.yaml @@ -229,7 +229,7 @@ images: 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 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 @@ -276,24 +276,20 @@ images: os_description: ubuntu os_version: 12.04.1 os_64bit: true - iso: http://releases.ubuntu.com/12.04/ubuntu-12.04.1-server-amd64.iso + iso: http://releases.ubuntu.com/12.04.1/ubuntu-12.04.1-server-amd64.iso iso_md5: a8c667e871f48f3a662f3fbf1c3ddb17 username: toor credential: password keystroke_sequence: | /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 + console-setup/ask_detect=false keyboard-configuration/layoutcode=us initrd=/install/initrd.gz -- 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 dummy d-i netcfg/get_hostname string unassigned-hostname d-i netcfg/get_domain string unassigned-domain # Continue without a default route @@ -355,4 +351,4 @@ images: #choose-mirror-bin mirror/http/directory string /ubuntu #choose-mirror-bin mirror/suite select maverick #d-i debian-installer/allow_unauthenticated string true - choose-mirror-bin mirror/http/proxy string \ No newline at end of file + choose-mirror-bin mirror/http/proxy string \ No newline at end of file diff --git a/labs/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh b/labs/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh index fcc3618e80..1eb542f1a5 100644 --- a/labs/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh +++ b/labs/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh @@ -2,8 +2,5 @@ function cleanupUdevIfNeeded { if [ -f '/etc/udev/rules.d/70-persistent-net.rules' ] then rm /etc/udev/rules.d/70-persistent-net.rules - mkdir /etc/udev/rules.d/70-persistent-net.rules - rm -rf /dev/.udev/ - rm /lib/udev/rules.d/75-persistent-net-generator.rules fi } \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index c9e9e52d92..369fe15656 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -20,16 +20,23 @@ package org.jclouds.virtualbox; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import static org.jclouds.scriptbuilder.domain.Statements.findPid; +import static org.jclouds.scriptbuilder.domain.Statements.kill; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import java.io.File; +import java.net.URI; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; +import org.jclouds.compute.callables.RunScriptOnNode.Factory; +import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; @@ -39,6 +46,8 @@ import org.jclouds.concurrent.MoreExecutors; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.rest.annotations.BuildVersion; +import org.jclouds.scriptbuilder.domain.Statement; +import org.jclouds.scriptbuilder.domain.StatementList; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.domain.HardDisk; @@ -50,28 +59,32 @@ import org.jclouds.virtualbox.domain.NetworkInterfaceCard; import org.jclouds.virtualbox.domain.NetworkSpec; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; +import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata; import org.jclouds.virtualbox.functions.IMachineToVmSpec; import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia; +import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen; import org.jclouds.virtualbox.util.MachineController; import org.jclouds.virtualbox.util.MachineUtils; import org.jclouds.virtualbox.util.NetworkUtils; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.SessionState; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.common.util.concurrent.Uninterruptibles; import com.google.inject.Injector; import com.google.inject.Key; @@ -116,16 +129,17 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) protected String workingDir; protected String isosDir; - @Inject - protected Supplier host; + @Inject protected Supplier host; + @Inject protected Factory runScriptOnNodeFactory; + @Inject protected RetryIfSocketNotYetOpen socketTester; + @Inject protected HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata; @Inject protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate; @Inject protected LoadingCache mastersCache; private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor(); - private String masterName; - + private String masterName; @Override protected Iterable setupModules() { @@ -147,7 +161,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT masterName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId(); isosDir = workingDir + File.separator + "isos"; - hostVersion = Iterables.get(Splitter.on('r').split(view.utils().injector().getInstance(Key.get(String.class, BuildVersion.class))), 0); + hostVersion = Iterables.get(Splitter.on('-').split(view.utils().injector().getInstance(Key.get(String.class, BuildVersion.class))), 0); operatingSystemIso = String.format("%s/%s.iso", isosDir, template.getImage().getName()); guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion); } @@ -217,5 +231,4 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT undoVm(masterName); } } - } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java index 8f274aaabb..d3e98a3d76 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java @@ -47,6 +47,7 @@ import com.google.common.collect.Iterables; @Test(groups = "live", singleThreaded = true, testName = "PreseedCfgServerTest") public class PreseedCfgServerTest { private static final String lineSeparator = System.getProperty("line.separator"); + @Test public void testJettyServerServesPreseedFile() throws Exception { Properties props = VirtualBoxApiMetadata.defaultProperties(); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java index f27045af9a..fd180604ed 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java @@ -37,7 +37,7 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.functions.IMachineToSshClient; import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_2.IMachine; import com.google.common.collect.Iterables; @@ -61,7 +61,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials())); } - protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { + protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { SshClient ssh = view.utils().injector().getInstance(IMachineToSshClient.class).apply(machine); try { ssh.connect(); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java index 807d31320d..2eca8035e3 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java @@ -24,6 +24,7 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -37,14 +38,14 @@ import org.jclouds.json.config.GsonModule; import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.functions.IMachineToImage; import org.testng.annotations.Test; -import org.virtualbox_4_1.IGuestOSType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IGuestOSType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.VirtualBoxManager; +import com.beust.jcommander.internal.Lists; import com.google.common.base.Function; import com.google.common.base.Suppliers; -import com.google.common.collect.Lists; import com.google.inject.Guice; @Test(groups = "unit") @@ -82,25 +83,6 @@ public class VirtualBoxComputeServiceAdapterTest { Function iMachineToImage = new IMachineToImage( VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap); -// VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), iMachineToImage, new ImageFromYamlString(), new Supplier() { -// -// @Override -// public String get() { -// return "images:\n" + -// " - id: myTestId\n" + -// " name: ubuntu-11.04-server-i386\n" + -// " description: ubuntu 11.04 server (i386)\n" + -// " os_arch: x86\n" + -// " os_family: ubuntu\n" + -// " os_description: ubuntu\n" + -// " os_version: 11.04\n" + -// " iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"; -// } -// }); -// -// Iterator iterator = adapter.listImages().iterator(); -// Image image = Iterators.getOnlyElement(iterator); -// assertEquals(image.getDescription(), "ubuntu 11.04 server (i386)"); } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java index 8fdf558ce8..1b14eca377 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java @@ -72,10 +72,10 @@ public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest { int numNodes = 3; final String clusterName = "test-launch-cluster"; Set nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes, - TemplateOptions.Builder.overrideLoginUser("toor").runScript(AdminAccess.standard())); + TemplateOptions.Builder.overrideLoginUser("toor")); assertEquals(numNodes, nodes.size(), "wrong number of nodes"); for (NodeMetadata node : nodes) { - assertEquals("test-launch-cluster", node.getGroup()); + assertTrue(node.getGroup().equals("test-launch-cluster")); logger.debug("Created Node: %s", node); SshClient client = context.utils().sshForNode().apply(node); client.connect(); @@ -90,4 +90,4 @@ public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest { }); } -} +} \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java index c573080281..ac82bb471b 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java @@ -20,12 +20,11 @@ package org.jclouds.virtualbox.domain; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotEquals; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.StorageBus; public class VmSpecTest { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java index 4f896528d0..463a135dc2 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java @@ -27,10 +27,10 @@ import static org.easymock.EasyMock.verify; import org.jclouds.virtualbox.domain.StorageController; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IStorageController; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IStorageController; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VBoxException; /** * @author Adrian Cole diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java index 290a7f756d..43b446682e 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java @@ -26,8 +26,8 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.VBoxException; /** * @author Mattias Holmqvist diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java index bd4cfa6c91..ec9adf0dfd 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java @@ -22,15 +22,14 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.virtualbox_4_1.NetworkAdapterType.Am79C973; -import static org.virtualbox_4_1.NetworkAttachmentType.Bridged; +import static org.virtualbox_4_2.NetworkAttachmentType.Bridged; import org.jclouds.virtualbox.domain.NetworkAdapter; import org.jclouds.virtualbox.domain.NetworkInterfaceCard; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.NetworkAttachmentType; /** * @author Andrea Turli @@ -49,7 +48,6 @@ public class AttachBridgedAdapterToMachineTest { expect(machine.getNetworkAdapter(adapterId)).andReturn(iNetworkAdapter); iNetworkAdapter.setAttachmentType(Bridged); - iNetworkAdapter.setAdapterType(Am79C973); iNetworkAdapter.setMACAddress(macAddress); iNetworkAdapter.setBridgedInterface(hostInterface); iNetworkAdapter.setEnabled(true); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java index f5c20e8616..928d1ed6d4 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java @@ -32,14 +32,14 @@ import org.jclouds.virtualbox.domain.DeviceDetails; import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.StorageController; import org.testng.annotations.Test; -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.IVirtualBox; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; /** * @author Mattias Holmqvist diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATAdapterToMachineIfNotAlreadyExistsTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATAdapterToMachineIfNotAlreadyExistsTest.java index 916b85107b..5420e0f365 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATAdapterToMachineIfNotAlreadyExistsTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATAdapterToMachineIfNotAlreadyExistsTest.java @@ -25,17 +25,20 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.virtualbox_4_1.NATProtocol.TCP; -import static org.virtualbox_4_1.NetworkAttachmentType.NAT; +import static org.virtualbox_4_2.NATProtocol.TCP; +import static org.virtualbox_4_2.NetworkAttachmentType.NAT; + +import java.util.ArrayList; +import java.util.List; import org.jclouds.virtualbox.domain.NetworkAdapter; import org.jclouds.virtualbox.domain.NetworkInterfaceCard; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INATEngine; -import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INATEngine; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.VBoxException; /** * @author Mattias Holmqvist, Andrea Turli @@ -52,8 +55,10 @@ public class AttachNATAdapterToMachineIfNotAlreadyExistsTest { expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter); iNetworkAdapter.setAttachmentType(NAT); - expect(iNetworkAdapter.getNatDriver()).andReturn(natEngine); + expect(iNetworkAdapter.getNATEngine()).andReturn(natEngine).anyTimes(); + List redirects = new ArrayList(); + expect(natEngine.getRedirects()).andReturn(redirects); natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1", 2222, "", 22); iNetworkAdapter.setEnabled(true); @@ -81,7 +86,10 @@ public class AttachNATAdapterToMachineIfNotAlreadyExistsTest { expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter); iNetworkAdapter.setAttachmentType(NAT); - expect(iNetworkAdapter.getNatDriver()).andReturn(natEngine); + expect(iNetworkAdapter.getNATEngine()).andReturn(natEngine).anyTimes(); + + List redirects = new ArrayList(); + expect(natEngine.getRedirects()).andReturn(redirects); natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1", 2222, "", 22); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java index 4d5034cf42..9543ccc589 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest.java @@ -37,10 +37,10 @@ import org.jclouds.virtualbox.domain.VmSpec; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java index 31b8d0cc88..5d66492a99 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndInstallVmLiveTest.java @@ -22,8 +22,7 @@ package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkState; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Map; @@ -52,10 +51,10 @@ import org.jclouds.virtualbox.predicates.SshResponds; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; @@ -137,8 +136,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest { String version = machine.getGuestPropertyValue("/VirtualBox/GuestAdd/Version"); - assertNotNull(version); - assertFalse(version.isEmpty()); + assertTrue(version != null && !version.isEmpty()); } finally { for (VmSpec spec : ImmutableSet.of(machineSpec.getVmSpec())) { machineController.ensureMachineIsShutdown(spec.getVmName()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java index df9ee62a76..effc685ae1 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java @@ -35,11 +35,11 @@ import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VBoxException; import com.google.inject.Injector; @@ -83,11 +83,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B MasterSpec machineSpec = MasterSpec.builder() .iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(vmSpec) .network(networkSpec).build(); - // undoVm(vmSpec); IMachine debianNode = view.utils().injector() .getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(machineSpec); IMachine machine = manager.get().getVBox().findMachine(vmName); assertEquals(debianNode.getName(), machine.getName()); + undoVm(vmName); } @@ -116,12 +116,12 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B // if osTypeId is not found. assertEquals(errorCode, ErrorCode.VBOX_E_OBJECT_NOT_FOUND); } + undoVm(vmName); } @AfterGroups(groups = "live") @Override protected void tearDownContext() { - undoVm(vmName); super.tearDownContext(); } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java index 0dda9b4995..879acdb43b 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.virtualbox.functions; -import static org.easymock.EasyMock.anyBoolean; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.eq; @@ -27,6 +26,8 @@ import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; +import java.util.List; + import org.easymock.EasyMock; import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.MasterSpec; @@ -35,15 +36,16 @@ import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.util.MachineUtils; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.LockType; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.LockType; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; +import com.beust.jcommander.internal.Lists; import com.google.common.base.Suppliers; /** @@ -52,116 +54,114 @@ import com.google.common.base.Suppliers; @Test(groups = "unit", testName = "CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest") public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest { - @Test(enabled = false) - public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception { + @Test(enabled = false) + public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception { - MachineUtils machineUtils = createMock(MachineUtils.class); - VirtualBoxManager manager = createMock(VirtualBoxManager.class); - IVirtualBox vBox = createMock(IVirtualBox.class); - String vmName = "jclouds-image-my-ubuntu-image"; - StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE).build(); - VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController).cleanUpMode( - CleanupMode.Full).build(); - MasterSpec machineSpec = MasterSpec.builder() - .iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build()) - .vm(vmSpec) - .network(NetworkSpec.builder().build()).build(); - IMachine createdMachine = createMock(IMachine.class); - ISession session = createMock(ISession.class); + MachineUtils machineUtils = createMock(MachineUtils.class); + VirtualBoxManager manager = createMock(VirtualBoxManager.class); + IVirtualBox vBox = createMock(IVirtualBox.class); + String vmName = "jclouds-image-my-ubuntu-image"; + StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE).build(); + VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController) + .cleanUpMode(CleanupMode.Full).build(); + MasterSpec machineSpec = MasterSpec.builder() + .iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build()).vm(vmSpec) + .network(NetworkSpec.builder().build()).build(); + IMachine createdMachine = createMock(IMachine.class); + ISession session = createMock(ISession.class); - expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(vBox.composeMachineFilename(vmName, "/tmp/workingDir")).andReturn("settingsFile"); + expect(manager.getVBox()).andReturn(vBox).anyTimes(); + String flags = ""; + List groups = Lists.newArrayList(); + String group = ""; + expect(vBox.composeMachineFilename(vmName, group, flags, "/tmp/workingDir")).andReturn("settingsFile"); - StringBuilder errorMessageBuilder = new StringBuilder(); - errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {"); - errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)"); - String errorMessage = errorMessageBuilder.toString(); - VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage); + StringBuilder errorMessageBuilder = new StringBuilder(); + errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {"); + errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)"); + String errorMessage = errorMessageBuilder.toString(); + VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage); - expect(vBox.findMachine(vmName)).andThrow(vBoxException); + expect(vBox.findMachine(vmName)).andThrow(vBoxException); - expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn( - createdMachine).anyTimes(); - vBox.registerMachine(createdMachine); + expect(vBox.createMachine(anyString(), eq(vmName), groups, anyString(), anyString())).andReturn(createdMachine) + .anyTimes(); + vBox.registerMachine(createdMachine); - expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes(); - expect(manager.getSessionObject()).andReturn(session); - expect(session.getMachine()).andReturn(createdMachine); - createdMachine.lockMachine(session, LockType.Write); - createdMachine.setMemorySize(1024l); - createdMachine.saveSettings(); - session.unlockMachine(); + expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes(); + expect(manager.getSessionObject()).andReturn(session); + expect(session.getMachine()).andReturn(createdMachine); + createdMachine.lockMachine(session, LockType.Write); + createdMachine.setMemorySize(1024l); + createdMachine.saveSettings(); + session.unlockMachine(); + // TODO: this mock test is not finished. + replay(manager, createdMachine, vBox, session); - //TODO: this mock test is not finished. - replay(manager, createdMachine, vBox, session); + new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, + "/tmp/workingDir").apply(machineSpec); - new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec); + verify(manager, createdMachine, vBox, session); + } - verify(manager, createdMachine, vBox, session); - } + @Test(expectedExceptions = IllegalStateException.class) + public void testFailIfMachineIsAlreadyRegistered() throws Exception { - @Test(expectedExceptions = IllegalStateException.class) - public void testFailIfMachineIsAlreadyRegistered() throws Exception { + MachineUtils machineUtils = createMock(MachineUtils.class); - MachineUtils machineUtils = createMock(MachineUtils.class); + VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class); + IVirtualBox vBox = createNiceMock(IVirtualBox.class); + String vmName = "jclouds-image-my-ubuntu-image"; - VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class); - IVirtualBox vBox = createNiceMock(IVirtualBox.class); - String vmName = "jclouds-image-my-ubuntu-image"; + IMachine registeredMachine = createMock(IMachine.class); - IMachine registeredMachine = createMock(IMachine.class); + expect(manager.getVBox()).andReturn(vBox).anyTimes(); + expect(vBox.findMachine(vmName)).andReturn(registeredMachine).anyTimes(); - expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(vBox.findMachine(vmName)).andReturn(registeredMachine).anyTimes(); + replay(manager, vBox, machineUtils); - replay(manager, vBox, machineUtils); + VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024) + .cleanUpMode(CleanupMode.Full).build(); - VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode( - CleanupMode.Full).build(); + MasterSpec machineSpec = MasterSpec.builder() + .iso(IsoSpec.builder().sourcePath("some.iso").installationScript("dostuff").build()) + .vm(launchSpecification).network(NetworkSpec.builder().build()).build(); + new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, + "/tmp/workingDir").apply(machineSpec); + } - MasterSpec machineSpec = MasterSpec.builder() - .iso(IsoSpec.builder() - .sourcePath("some.iso") - .installationScript("dostuff").build()) - .vm(launchSpecification) - .network(NetworkSpec.builder().build()).build(); - new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec); - } + @Test(expectedExceptions = VBoxException.class) + public void testFailIfOtherVBoxExceptionIsThrown() throws Exception { - @Test(expectedExceptions = VBoxException.class) - public void testFailIfOtherVBoxExceptionIsThrown() throws Exception { + MachineUtils machineUtils = createMock(MachineUtils.class); - MachineUtils machineUtils = createMock(MachineUtils.class); + VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class); + IVirtualBox vBox = createNiceMock(IVirtualBox.class); + String vmName = "jclouds-image-my-ubuntu-image"; - VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class); - IVirtualBox vBox = createNiceMock(IVirtualBox.class); - String vmName = "jclouds-image-my-ubuntu-image"; + String errorMessage = "VirtualBox error: Some other VBox error"; + VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage); - String errorMessage = "VirtualBox error: Some other VBox error"; - VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage); + expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(manager.getVBox()).andReturn(vBox).anyTimes(); + vBox.findMachine(vmName); + expectLastCall().andThrow(vBoxException); - vBox.findMachine(vmName); - expectLastCall().andThrow(vBoxException); + replay(manager, vBox, machineUtils); - replay(manager, vBox, machineUtils); + VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full) + .memoryMB(1024).build(); + MasterSpec machineSpec = MasterSpec.builder() + .iso(IsoSpec.builder().sourcePath("some.iso").installationScript("dostuff").build()) + .vm(launchSpecification).network(NetworkSpec.builder().build()).build(); - VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full) - .memoryMB(1024).build(); - MasterSpec machineSpec = MasterSpec.builder() - .iso(IsoSpec.builder() - .sourcePath("some.iso") - .installationScript("dostuff").build()) - .vm(launchSpecification) - .network(NetworkSpec.builder().build()).build(); + new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, + "/tmp/workingDir").apply(machineSpec); - new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec); + } - } - - private String anyString() { - return EasyMock.anyObject(); - } + private String anyString() { + return EasyMock. anyObject(); + } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java index 3b1f3f8e96..f400ee020c 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsLiveTest.java @@ -28,10 +28,11 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.domain.ErrorCode; import org.jclouds.virtualbox.domain.HardDisk; import org.testng.annotations.Test; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.AccessMode; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.VBoxException; /** * @author Mattias Holmqvist @@ -43,7 +44,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-1.vdi"; HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build(); IMedium iMedium = new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk); - manager.get().getVBox().findMedium(path, DeviceType.HardDisk); + manager.get().getVBox().openMedium(path, DeviceType.HardDisk, AccessMode.ReadWrite, true); try { assertFileCanBeDeleted(path); } finally { @@ -70,7 +71,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build(); new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk); IMedium iMedium = new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk); - manager.get().getVBox().findMedium(path, DeviceType.HardDisk); + manager.get().getVBox().openMedium(path, DeviceType.HardDisk, AccessMode.ReadWrite, true); try { assertFileCanBeDeleted(path); } finally { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java index 755762804d..473872eee2 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java @@ -22,7 +22,6 @@ package org.jclouds.virtualbox.functions; import static org.easymock.EasyMock.anyLong; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; @@ -32,16 +31,17 @@ import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.util.MachineUtils; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IMediumAttachment; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.LockType; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.AccessMode; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IMediumAttachment; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.LockType; +import org.virtualbox_4_2.VBoxException; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; @@ -74,14 +74,14 @@ public class CreateMediumIfNotAlreadyExistsTest { IProgress progress = createNiceMock(IProgress.class); StringBuilder errorBuilder = new StringBuilder(); - errorBuilder.append("org.virtualbox_4_1.VBoxException: VirtualBox error: "); - errorBuilder.append("Could not find an open hard disk with location "); + errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: "); + errorBuilder.append("Could not find file for the medium "); errorBuilder.append("'/Users/johndoe/jclouds-virtualbox-test/testadmin.vdi' (0x80BB0001)"); String errorMessage = errorBuilder.toString(); expect(manager.getVBox()).andReturn(vBox).anyTimes(); VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage); - expect(vBox.findMedium(eq(adminDiskPath), eq(DeviceType.HardDisk))).andThrow(notFoundException); + expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andThrow(notFoundException); expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium); expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress); //expect(machineUtils.writeLockMachineAndApply(anyString(), new DetachDistroMediumFromMachine(anyString(), anyInt() , anyInt()))).andReturn().anyTimes(); @@ -108,7 +108,7 @@ public class CreateMediumIfNotAlreadyExistsTest { IProgress progress = createNiceMock(IProgress.class); expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andReturn(medium); + expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium); expect(medium.deleteStorage()).andReturn(progress); expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(newHardDisk); @@ -140,7 +140,7 @@ public class CreateMediumIfNotAlreadyExistsTest { IProgress progress = createNiceMock(IProgress.class); expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andReturn(medium); + expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium); String oldMachineId = "a1e03931-29f3-4370-ada3-9547b1009212"; String oldMachineName = "oldMachine"; @@ -154,7 +154,7 @@ public class CreateMediumIfNotAlreadyExistsTest { ISession detachSession = createNiceMock(ISession.class); StringBuilder errorBuilder = new StringBuilder(); - errorBuilder.append("org.virtualbox_4_1.VBoxException: VirtualBox error: "); + errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: "); errorBuilder.append("Cannot delete storage: medium '/Users/adriancole/jclouds-virtualbox-test/testadmin.vdi "); errorBuilder.append("is still attached to the following 1 virtual machine(s): "); errorBuilder.append(oldMachineId + " (0x80BB000C)"); @@ -207,7 +207,7 @@ public class CreateMediumIfNotAlreadyExistsTest { IProgress progress = createNiceMock(IProgress.class); expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andReturn(medium); + expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium); replay(manager, machine, vBox, medium, newHardDisk, progress, machineUtils); @@ -232,7 +232,7 @@ public class CreateMediumIfNotAlreadyExistsTest { expect(manager.getVBox()).andReturn(vBox).anyTimes(); VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage); - expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andThrow(notFoundException); + expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andThrow(notFoundException); expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium); expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java index 47342fdf25..33fd5ed355 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java @@ -25,8 +25,8 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.VBoxException; /** * @author Andrea Turli diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java index 436826f927..9427df630a 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToHardwareTest.java @@ -28,10 +28,10 @@ import static org.testng.Assert.assertEquals; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.predicates.ImagePredicates; import org.testng.annotations.Test; -import org.virtualbox_4_1.IGuestOSType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IGuestOSType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Suppliers; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java index 348f800195..a08660cdd8 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToImageTest.java @@ -37,11 +37,11 @@ import org.jclouds.json.config.GsonModule; import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.testng.annotations.Test; -import org.virtualbox_4_1.IGuestOSType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IGuestOSType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Suppliers; import com.google.inject.Guice; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java index 274c28c45c..2960314b4e 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java @@ -28,48 +28,70 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; import static org.testng.Assert.assertEquals; +import java.util.Map; + +import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.json.Json; +import org.jclouds.json.config.GsonModule; import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.util.NetworkUtils; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.INATEngine; -import org.virtualbox_4_1.INetworkAdapter; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.IGuest; +import org.virtualbox_4_2.IGuestOSType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.INATEngine; +import org.virtualbox_4_2.INetworkAdapter; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.VirtualBoxManager; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; +import com.google.inject.Guice; public class IMachineToNodeMetadataTest { private static final String MASTER_NAME = "mock-image-of-a-server"; + Map> map = new BaseComputeServiceContextModule() { + }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) + .getInstance(Json.class)); - @Test + @Test(enabled=false) public void testCreateFromMaster() throws Exception { IMachine vm = createNiceMock(IMachine.class); - - expect(vm.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + MASTER_NAME).anyTimes(); - expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes(); - + VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class); + IVirtualBox vBox = createNiceMock(IVirtualBox.class); + IGuestOSType iGuestOSType = createNiceMock(IGuestOSType.class); INetworkAdapter nat = createNiceMock(INetworkAdapter.class); INATEngine natEng = createNiceMock(INATEngine.class); + expect(vm.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + MASTER_NAME).anyTimes(); + expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes(); expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once(); expect(vm.getNetworkAdapter(eq(1l))).andReturn(null).once(); expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once(); - expect(nat.getNatDriver()).andReturn(natEng).anyTimes(); + expect(nat.getNATEngine()).andReturn(natEng).anyTimes(); expect(natEng.getHostIP()).andReturn("127.0.0.1").once(); expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,2222,,22")); - + + expect(vbm.getVBox()).andReturn(vBox).anyTimes(); + expect(vm.getOSTypeId()).andReturn("RedHat_64").anyTimes(); + expect(vBox.getGuestOSType(vm.getOSTypeId())).andReturn(iGuestOSType); + INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class); NetworkUtils networkUtils = createNiceMock(NetworkUtils.class); - replay(vm, nat, natEng, hostOnly, networkUtils); + replay(vm, vBox, iGuestOSType, nat, natEng, hostOnly, networkUtils); - NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus, - networkUtils).apply(vm); + NodeMetadata node = new IMachineToNodeMetadata(Suppliers + .ofInstance(vbm), VirtualBoxComputeServiceContextModule.toPortableNodeStatus, + networkUtils, map).apply(vm); assertEquals(MASTER_NAME, node.getName()); assertEquals(1, node.getPrivateAddresses().size()); @@ -79,11 +101,13 @@ public class IMachineToNodeMetadataTest { assertEquals("", node.getGroup()); } - @Test + @Test(enabled=false) public void testCreateFromNode() throws Exception { IMachine vm = createNiceMock(IMachine.class); - + VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class); + IVirtualBox vBox = createNiceMock(IVirtualBox.class); + expect(vbm.getVBox()).andReturn(vBox).anyTimes(); String group = "my-cluster-group"; String name = "a-name-with-a-code-338"; @@ -97,18 +121,21 @@ public class IMachineToNodeMetadataTest { INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class); + + expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once(); expect(vm.getNetworkAdapter(eq(1l))).andReturn(hostOnly).once(); expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once(); - expect(nat.getNatDriver()).andReturn(natEng).anyTimes(); + expect(nat.getNATEngine()).andReturn(natEng).anyTimes(); expect(natEng.getHostIP()).andReturn("127.0.0.1").once(); expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,3000,,22")); NetworkUtils networkUtils = createNiceMock(NetworkUtils.class); replay(vm, nat, natEng, hostOnly, networkUtils); - NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus, - networkUtils).apply(vm); + NodeMetadata node = new IMachineToNodeMetadata(Suppliers + .ofInstance(vbm), VirtualBoxComputeServiceContextModule.toPortableNodeStatus, + networkUtils, map).apply(vm); assertEquals(name, node.getName()); assertEquals(group, node.getGroup()); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToVmSpecTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToVmSpecTest.java index d7675df5b8..c2a70d08ca 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToVmSpecTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToVmSpecTest.java @@ -29,13 +29,13 @@ import org.jclouds.virtualbox.domain.IsoImage; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.testng.annotations.Test; -import org.virtualbox_4_1.DeviceType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IMediumAttachment; -import org.virtualbox_4_1.IStorageController; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.DeviceType; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IMediumAttachment; +import org.virtualbox_4_2.IStorageController; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.collect.Lists; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java index 14f761f3ae..412be99755 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java @@ -25,11 +25,11 @@ import static org.easymock.EasyMock.verify; import org.jclouds.virtualbox.domain.ExecutionType; import org.testng.annotations.Test; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.SessionState; +import org.virtualbox_4_2.VirtualBoxManager; @Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest") public class LaunchMachineIfNotAlreadyRunningTest { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttachedTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttachedTest.java index 3e3bb58643..f1e8ab957a 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttachedTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/TakeSnapshotIfNotAlreadyAttachedTest.java @@ -26,14 +26,14 @@ import static org.easymock.EasyMock.verify; import org.jclouds.logging.Logger; import org.testng.annotations.Test; -import org.virtualbox_4_1.IConsole; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.ISnapshot; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.MachineState; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.IConsole; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.ISnapshot; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.MachineState; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Suppliers; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java index 5d06e46191..0e4b3ef2f8 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStringTest.java @@ -60,4 +60,4 @@ public class ImageFromYamlStringTest { public void testNodesParse() { assertEquals(Iterables.getFirst(images.keySet(), null), TEST1); } -} +} \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java index 1d1fb07374..2bfc3e2fc2 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java @@ -24,21 +24,18 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; import java.net.URI; import org.jclouds.compute.callables.RunScriptOnNode; import org.jclouds.compute.callables.RunScriptOnNode.Factory; -import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata.Status; import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.scriptbuilder.domain.Statements; +import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata; import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen; import org.testng.annotations.Test; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Functions; @@ -53,57 +50,18 @@ public class StartVBoxIfNotAlreadyRunningLiveTest { public void testStartVboxConnectsToManagerWhenPortAlreadyListening() throws Exception { VirtualBoxManager manager = createMock(VirtualBoxManager.class); Factory runScriptOnNodeFactory = createMock(Factory.class); + RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class); RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class); + HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata = createMock(HardcodedHostToHostNodeMetadata.class); NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).build(); URI provider = URI.create("http://localhost:18083/"); expect(client.seconds(3)).andReturn(client); expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes(); manager.connect(provider.toASCIIString(), "", ""); expectLastCall().anyTimes(); - - replay(manager, runScriptOnNodeFactory, client); - - new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client, - Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null).start(); - - verify(manager, runScriptOnNodeFactory, client); - - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test - public void testStartVboxDisablesPasswordAccessOnWebsrvauthlibraryStartsVboxwebsrvInBackgroundAndConnectsManagerWhenPortIsNotListening() - throws Exception { - VirtualBoxManager manager = createMock(VirtualBoxManager.class); - Factory runScriptOnNodeFactory = createMock(Factory.class); - RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class); - RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class); - NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).operatingSystem( - OperatingSystem.builder().description("unix").build()).build(); - URI provider = URI.create("http://localhost:18083/"); - - expect(client.seconds(3)).andReturn(client); - expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(false).once().andReturn(true).once(); - expect(runScriptOnNodeFactory.create(host, - Statements.exec("VBoxManage setproperty websrvauthlibrary null"), - runAsRoot(false).wrapInInitScript(false))).andReturn(runScriptOnNode); - expect(runScriptOnNode.init()).andReturn(runScriptOnNode); - expect(runScriptOnNode.call()).andReturn(new ExecResponse("", "", 0)); - - expect(runScriptOnNodeFactory.create(host, - Statements.exec("vboxwebsrv -t 10000 -v -b -H localhost"), runAsRoot(false) - .wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv"))) - .andReturn(runScriptOnNode); - - expect(runScriptOnNode.init()).andReturn(runScriptOnNode); - expect(runScriptOnNode.call()).andReturn(new ExecResponse("", "", 0)); - manager.connect(provider.toASCIIString(), "", ""); - expectLastCall().anyTimes(); - replay(manager, runScriptOnNodeFactory, runScriptOnNode, client); new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client, - Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null); - - verify(manager, runScriptOnNodeFactory, runScriptOnNode, client); + Suppliers.ofInstance(host), Suppliers.ofInstance(provider), hardcodedHostToHostNodeMetadata).start(); + verify(manager, runScriptOnNodeFactory, client); } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java index fdfbd709e6..3297eb2103 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsAndDeleteItsMediaTest.java @@ -27,19 +27,19 @@ import static org.easymock.EasyMock.replay; import java.util.Collections; import java.util.List; -import com.google.common.collect.Lists; - import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IMedium; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.IVirtualBox; -import org.virtualbox_4_1.StorageBus; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.IMedium; +import org.virtualbox_4_2.IProgress; +import org.virtualbox_4_2.IVirtualBox; +import org.virtualbox_4_2.StorageBus; +import org.virtualbox_4_2.VirtualBoxManager; + +import com.google.common.collect.Lists; @Test(groups = "unit", testName = "UnregisterMachineIfExistsTest") public class UnregisterMachineIfExistsAndDeleteItsMediaTest { @@ -58,22 +58,20 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest { IProgress progress = createNiceMock(IProgress.class); List media = Lists.newArrayList(); List mediums = Collections.unmodifiableList(media); - + StorageController ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE) - .attachISO(0, 0, "/tmp/ubuntu-11.04-server-i386.iso") - .attachHardDisk(HardDisk.builder().diskpath("/tmp/testadmin.vdi").controllerPort(0).deviceSlot(1).build()) - .attachISO(1, 1, "/tmp/VBoxGuestAdditions_4.1.2.iso").build(); + .attachISO(0, 0, "/tmp/ubuntu-11.04-server-i386.iso") + .attachHardDisk(HardDisk.builder().diskpath("/tmp/testadmin.vdi").controllerPort(0).deviceSlot(1).build()) + .attachISO(1, 1, "/tmp/VBoxGuestAdditions_4.1.2.iso").build(); VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId) - .controller(ideController) - .forceOverwrite(true) - .cleanUpMode(CleanupMode.Full).build(); + .controller(ideController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); expect(manager.getVBox()).andReturn(vBox).anyTimes(); expect(vBox.findMachine(vmName)).andReturn(registeredMachine); expect(registeredMachine.unregister(mode)).andReturn(mediums); expectLastCall().anyTimes(); - + expect(registeredMachine.delete(mediums)).andReturn(progress); expectLastCall().anyTimes(); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java index 471ae9480f..1123aa4307 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstallerLiveTest.java @@ -42,10 +42,10 @@ import org.jclouds.virtualbox.functions.IMachineToSshClient; import org.jclouds.virtualbox.util.NetworkUtils; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; @@ -56,15 +56,15 @@ import com.google.inject.Injector; /** * @author Andrea Turli */ -@Test(groups = "live", singleThreaded = true, testName = "GuestAdditionsInstallerLiveTest", enabled=false) +@Test(groups = "live", singleThreaded = true, testName = "GuestAdditionsInstallerLiveTest") public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTest { private Injector injector; private Function sshClientForIMachine; private Predicate sshResponds; - - private MasterSpec machineSpec; - + private VmSpec instanceVmSpec; + private NetworkSpec instanceNetworkSpec; + @Override @BeforeClass(groups = "live") public void setupContext() { @@ -83,7 +83,7 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1) .autoDelete(true).build()).attachISO(1, 1, guestAdditionsIso).build(); - VmSpec instanceVmSpec = VmSpec.builder().id(instanceName).name(instanceName).osTypeId("").memoryMB(512) + instanceVmSpec = VmSpec.builder().id(instanceName).name(instanceName).osTypeId("").memoryMB(512) .cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build(); Function configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class); @@ -94,13 +94,14 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", instanceVmSpec.getVmName())).build(); - NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule("127.0.0.1", 2222, "", 22).build(); + NetworkAdapter networkAdapter = NetworkAdapter.builder() + .networkAttachmentType(NetworkAttachmentType.HostOnly) + .build(); NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) - .build(); + .addHostInterfaceName("vboxnet0").slot(0L).build(); - NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); - machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build(); + instanceNetworkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); + //cloneSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build(); } @Test @@ -119,23 +120,29 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes assertTrue(NetworkUtils.isIpv4(networkUtils.getIpAddressFromNicSlot(machine.getName(), 0l))); } finally { - for (String vmNameOrId : ImmutableSet.of(machine.getName())) { - machineController.ensureMachineHasPowerDown(vmNameOrId); - undoVm(vmNameOrId); + if(machine!=null) { + for (String vmNameOrId : ImmutableSet.of(machine.getName())) { + machineController.ensureMachineHasPowerDown(vmNameOrId); + undoVm(vmNameOrId); + } } } } - private IMachine cloneFromMaster() { + protected IMachine cloneFromMaster() { IMachine source = getVmWithGuestAdditionsInstalled(); - CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec()) - .master(source).linked(true).build(); + CloneSpec cloneSpec = CloneSpec.builder() + .vm(instanceVmSpec) + .network(instanceNetworkSpec) + .master(source) + .linked(true) + .build(); return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils) .apply(cloneSpec); } private IMachine getVmWithGuestAdditionsInstalled() { - MasterSpec masterSpecForTest = super.getMasterSpecForTest(); + MasterSpec masterSpecForTest = getMasterSpecForTest(); try { Injector injector = view.utils().injector(); return injector.getInstance(CreateAndInstallVm.class).apply(masterSpecForTest); @@ -144,5 +151,4 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes return manager.get().getVBox().findMachine(masterSpecForTest.getVmSpec().getVmId()); } } - } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java index 6c7c557778..8d34246ce2 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/IMachinePredicatesLiveTest.java @@ -40,10 +40,10 @@ import org.jclouds.virtualbox.functions.CreateAndInstallVm; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsLiveTest.java index 69e1ce36e4..6e9ca0032d 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsLiveTest.java @@ -26,8 +26,8 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.VmSpec; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.StorageBus; /** * @author Andrea Turli, David Alves @@ -44,8 +44,8 @@ public class InstallGuestAdditionsLiveTest extends BaseVirtualBoxClientLiveTest InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8"); String scripts = installer.render(OsFamily.UNIX); - assertEquals("installModuleAssistantIfNeeded || return 1\n" + "mount -t iso9660 /dev/sr1 /mnt\n" - + "/mnt/VBoxLinuxAdditions.run --nox11\n", scripts); + assertEquals(scripts, "installModuleAssistantIfNeeded || return 1\n" + "mount -t iso9660 /dev/cdrom1 /mnt\n" + + "/mnt/VBoxLinuxAdditions.run --nox11\n"); } public void testIsoNotPresent() { @@ -56,12 +56,11 @@ public class InstallGuestAdditionsLiveTest extends BaseVirtualBoxClientLiveTest InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8"); String scripts = installer.render(OsFamily.UNIX); - assertEquals( + assertEquals(scripts, "installModuleAssistantIfNeeded || return 1\n" + "setupPublicCurl || return 1\n" + "(mkdir -p /tmp/ && cd /tmp/ && [ ! -f VBoxGuestAdditions_4.1.8.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.1.8/VBoxGuestAdditions_4.1.8.iso >VBoxGuestAdditions_4.1.8.iso)\n" + "mount -o loop /tmp/VBoxGuestAdditions_4.1.8.iso /mnt\n" - + "/mnt/VBoxLinuxAdditions.run --nox11\n", scripts); + + "/mnt/VBoxLinuxAdditions.run --nox11\n"); } - } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsTest.java new file mode 100644 index 0000000000..09f84531c1 --- /dev/null +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/InstallGuestAdditionsTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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 + * + * 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.statements; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.virtualbox.domain.StorageController; +import org.jclouds.virtualbox.domain.VmSpec; +import org.testng.annotations.Test; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.StorageBus; + +public class InstallGuestAdditionsTest { + + private final static String VBOX_VERISION = "4.2.0"; + + @Test + public void testInstallGAWhenIsoIsPresent() { + StorageController ideController = StorageController.builder() + .name("IDE Controller") + .bus(StorageBus.IDE) + .attachISO(1, 0, "VBoxGuestAdditions_") + .build(); + VmSpec vmSpec = VmSpec.builder() + .id("").name("") + .memoryMB(512) + .osTypeId("") + .controller(ideController) + .forceOverwrite(true) + .cleanUpMode(CleanupMode.Full) + .build(); + InstallGuestAdditions installGuestAdditions = new InstallGuestAdditions(vmSpec , VBOX_VERISION); + assertEquals(installGuestAdditions.render(OsFamily.UNIX), + "installModuleAssistantIfNeeded || return 1\n" + + "mount -t iso9660 /dev/cdrom1 /mnt\n" + + "/mnt/VBoxLinuxAdditions.run --nox11\n"); + } + + @Test + public void testInstallGAWhenIsoIsNotPresent() { + StorageController ideController = StorageController.builder() + .name("IDE Controller") + .bus(StorageBus.IDE) + .build(); + VmSpec vmSpec = VmSpec.builder() + .id("").name("") + .memoryMB(512) + .osTypeId("") + .controller(ideController) + .forceOverwrite(true) + .cleanUpMode(CleanupMode.Full) + .build(); + InstallGuestAdditions installGuestAdditions = new InstallGuestAdditions(vmSpec , VBOX_VERISION); + assertEquals(installGuestAdditions.render(OsFamily.UNIX), + "installModuleAssistantIfNeeded || return 1\n" + + "setupPublicCurl || return 1\n" + + "(mkdir -p /tmp/ && cd /tmp/ && [ ! -f VBoxGuestAdditions_4.2.0.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.2.0/VBoxGuestAdditions_4.2.0.iso >VBoxGuestAdditions_4.2.0.iso)\n" + + "mount -o loop /tmp/VBoxGuestAdditions_4.2.0.iso /mnt\n" + + "/mnt/VBoxLinuxAdditions.run --nox11\n"); + } +} diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java index 8023fd1c77..2fb2ba0686 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java @@ -25,7 +25,7 @@ import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.virtualbox.domain.NetworkAdapter; import org.jclouds.virtualbox.domain.NetworkInterfaceCard; import org.testng.annotations.Test; -import org.virtualbox_4_1.NetworkAttachmentType; +import org.virtualbox_4_2.NetworkAttachmentType; public class SetIpAddressTest { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java index 31460523dd..10e6dde81b 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineControllerLiveTest.java @@ -21,8 +21,8 @@ package org.jclouds.virtualbox.util; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; +import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertSame; import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; @@ -40,12 +40,12 @@ import org.jclouds.virtualbox.functions.CreateAndInstallVm; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.SessionState; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; @@ -55,72 +55,62 @@ import com.google.inject.Injector; @Test(groups = "live", testName = "MachineControllerLiveTest") public class MachineControllerLiveTest extends BaseVirtualBoxClientLiveTest { - private MasterSpec machineSpec; + private MasterSpec masterSpec; private String instanceName; + private IMachine clonedMachine; @Override @BeforeClass(groups = "live") public void setupContext() { super.setupContext(); instanceName = VIRTUALBOX_IMAGE_PREFIX - + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); + + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()); StorageController ideController = StorageController - .builder() - .name("IDE Controller") - .bus(StorageBus.IDE) - .attachISO(0, 0, operatingSystemIso) - .attachHardDisk( - HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1) - .autoDelete(true).build()).attachISO(1, 1, guestAdditionsIso).build(); + .builder() + .name("IDE Controller") + .bus(StorageBus.IDE) + .attachISO(0, 0, operatingSystemIso) + .attachHardDisk( + HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1).autoDelete(true) + .build()).attachISO(1, 1, guestAdditionsIso).build(); VmSpec instanceVmSpec = VmSpec.builder().id(instanceName).name(instanceName).osTypeId("").memoryMB(512) - .cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build(); + .cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build(); Injector injector = view.utils().injector(); - Function configProperties = injector - .getInstance(ValueOfConfigurationKeyOrNull.class); + Function configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class); IsoSpec isoSpec = IsoSpec .builder() .sourcePath(operatingSystemIso) .installationScript( - configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) - .replace("HOSTNAME", instanceVmSpec.getVmName())) - .build(); + configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", + instanceVmSpec.getVmName())).build(); - NetworkAdapter networkAdapter = NetworkAdapter.builder() - .networkAttachmentType(NetworkAttachmentType.HostOnly).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard - .builder().addNetworkAdapter(networkAdapter) + NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly) + .build(); + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) .addHostInterfaceName("vboxnet0").slot(0L).build(); - NetworkSpec networkSpec = NetworkSpec.builder() - .addNIC(networkInterfaceCard).build(); - machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec) - .network(networkSpec).build(); + NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); + masterSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build(); + clonedMachine = cloneFromMaster(); } @Test public void testEnsureMachineisLaunchedAndSessionIsUnlocked() { - cloneFromMaster(); - ISession cloneMachineSession = machineController.ensureMachineIsLaunched(instanceName); - assertSame(cloneMachineSession.getState(), SessionState.Unlocked); - cloneMachineSession = machineController.ensureMachineHasPowerDown(instanceName); - assertSame(cloneMachineSession.getState(), SessionState.Unlocked); - } - - @Test(dependsOnMethods="testEnsureMachineisLaunchedAndSessionIsUnlocked") - public void testEnsureMachineCanBePoweredOffMoreThanOneTimeAndSessionIsUnlocked() { - ISession cloneMachineSession = machineController.ensureMachineHasPowerDown(instanceName); + ISession cloneMachineSession = machineController.ensureMachineIsLaunched(clonedMachine.getName()); + assertTrue(cloneMachineSession.getState() == SessionState.Unlocked); + cloneMachineSession = machineController.ensureMachineHasPowerDown(clonedMachine.getName()); SessionState state = cloneMachineSession.getState(); assertEquals(SessionState.Unlocked, state); } private IMachine cloneFromMaster() { IMachine source = getVmWithGuestAdditionsInstalled(); - CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec()) - .master(source).linked(true).build(); + CloneSpec cloneSpec = CloneSpec.builder().vm(masterSpec.getVmSpec()).network(masterSpec.getNetworkSpec()) + .master(source).linked(true).build(); return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils) - .apply(cloneSpec); + .apply(cloneSpec); } private IMachine getVmWithGuestAdditionsInstalled() { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java index 1ae91601fc..a946de4df2 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/util/MachineUtilsLiveTest.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkState; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; @@ -40,12 +39,12 @@ import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNot import org.jclouds.virtualbox.functions.CreateAndInstallVm; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.virtualbox_4_1.CleanupMode; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.ISession; -import org.virtualbox_4_1.NetworkAttachmentType; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.StorageBus; +import org.virtualbox_4_2.CleanupMode; +import org.virtualbox_4_2.IMachine; +import org.virtualbox_4_2.ISession; +import org.virtualbox_4_2.NetworkAttachmentType; +import org.virtualbox_4_2.SessionState; +import org.virtualbox_4_2.StorageBus; import com.google.common.base.CaseFormat; import com.google.common.base.Function; @@ -109,7 +108,7 @@ public class MachineUtilsLiveTest extends BaseVirtualBoxClientLiveTest { undoVm(clone.getName()); } - @Test(dependsOnMethods="writeLockSessionOnMachine", description = "shared lock is acquired and released correctly") + @Test(dependsOnMethods = "writeLockSessionOnMachine", description = "shared lock is acquired and released correctly") public void sharedLockSessionOnMachine() { final IMachine clone = cloneFromMaster(); ISession session = machineUtils.sharedLockMachineAndApplyToSession(clone.getName(), @@ -124,7 +123,7 @@ public class MachineUtilsLiveTest extends BaseVirtualBoxClientLiveTest { undoVm(clone.getName()); } - @Test(dependsOnMethods="sharedLockSessionOnMachine", description = "shared lock can be acquired after a write lock") + @Test(dependsOnMethods = "sharedLockSessionOnMachine", description = "shared lock can be acquired after a write lock") public void sharedLockCanBeAcquiredAfterWriteLockSessionOnMachine() { final IMachine clone = cloneFromMaster(); try { @@ -133,7 +132,6 @@ public class MachineUtilsLiveTest extends BaseVirtualBoxClientLiveTest { @Override public ISession apply(ISession writeSession) { checkState(writeSession.getState().equals(SessionState.Locked)); - //ISession sharedSession = sharedSession(clone); return writeSession; } }); @@ -143,20 +141,7 @@ public class MachineUtilsLiveTest extends BaseVirtualBoxClientLiveTest { } } - private ISession sharedSession(final IMachine clone) { - ISession sharedSession = machineUtils.sharedLockMachineAndApplyToSession(clone.getName(), - new Function() { - @Override - public ISession apply(ISession sharedSession) { - checkState(sharedSession.getState().equals(SessionState.Locked)); - assertEquals(sharedSession.getMachine().getName(), clone.getName()); - return sharedSession; - } - }); - return sharedSession; - } - - @Test(dependsOnMethods="sharedLockCanBeAcquiredAfterWriteLockSessionOnMachine", description = "write lock cannot be acquired after a shared lock") + @Test(dependsOnMethods = "sharedLockCanBeAcquiredAfterWriteLockSessionOnMachine", description = "write lock cannot be acquired after a shared lock") public void writeLockCannotBeAcquiredAfterSharedLockSessionOnMachine() { final IMachine clone = cloneFromMaster(); try { diff --git a/labs/virtualbox/src/test/resources/default-images.yaml b/labs/virtualbox/src/test/resources/default-images.yaml index fe4c0c82d3..1b0b2482c4 100644 --- a/labs/virtualbox/src/test/resources/default-images.yaml +++ b/labs/virtualbox/src/test/resources/default-images.yaml @@ -229,7 +229,7 @@ images: 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 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 @@ -276,24 +276,20 @@ images: os_description: ubuntu os_version: 12.04.1 os_64bit: true - iso: http://releases.ubuntu.com/12.04/ubuntu-12.04.1-server-amd64.iso + iso: http://releases.ubuntu.com/12.04.1/ubuntu-12.04.1-server-amd64.iso iso_md5: a8c667e871f48f3a662f3fbf1c3ddb17 username: toor credential: password keystroke_sequence: | /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 + console-setup/ask_detect=false keyboard-configuration/layoutcode=us initrd=/install/initrd.gz -- 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 dummy d-i netcfg/get_hostname string unassigned-hostname d-i netcfg/get_domain string unassigned-domain # Continue without a default route @@ -355,4 +351,58 @@ images: #choose-mirror-bin mirror/http/directory string /ubuntu #choose-mirror-bin mirror/suite select maverick #d-i debian-installer/allow_unauthenticated string true - choose-mirror-bin mirror/http/proxy string \ No newline at end of file + choose-mirror-bin mirror/http/proxy string + - id: centos-6.3-amd64 + name: centos-6.3-amd64 + description: centos-6.3 (amd64) + os_arch: amd64 + os_family: centos + os_description: centos + os_version: 6.3 + os_64bit: true + iso: http://www.mirrorservice.org/sites/mirror.centos.org/6.3/isos/i386/CentOS-6.3-x86_64-LiveCD.iso + iso_md5: 9953ff1cc2ef31da89a0e1f993ee6335 + username: root + credential: password + keystroke_sequence: | + + /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg + console-setup/ask_detect=false keyboard-configuration/layoutcode=us + initrd=/install/initrd.gz -- + preseed_cfg: | + ## Options to set on the command line + install + cdrom + lang en_US.UTF-8 + keyboard us + network --bootproto=dhcp + rootpw --iscrypted $1$damlkd,f$UC/u5pUts5QiU3ow.CSso/ + firewall --enabled --service=ssh + authconfig --enableshadow --passalgo=sha512 + selinux --disabled + timezone UTC + bootloader --location=mbr + text + skipx + zerombr + clearpart --all --initlabel + autopart + auth --useshadow --enablemd5 + firstboot --disabled + reboot%packages --ignoremissing + @core + bzip2 + kernel-devel + kernel-headers + -ipw2100-firmware + -ipw2200-firmware + -ivtv-firmware + %end + %post + /usr/bin/yum -y install sudo + /usr/sbin/groupadd veewee + /usr/sbin/useradd veewee -g veewee -G wheel + echo "veewee"|passwd --stdin veewee + echo "veewee ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/veewee + chmod 0440 /etc/sudoers.d/veewee + %end diff --git a/labs/virtualbox/src/test/resources/logback.xml b/labs/virtualbox/src/test/resources/logback.xml index 26f517de96..bce8c261fe 100644 --- a/labs/virtualbox/src/test/resources/logback.xml +++ b/labs/virtualbox/src/test/resources/logback.xml @@ -39,12 +39,12 @@ - + - +