http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java b/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java deleted file mode 100644 index 70e46db..0000000 --- a/virtualbox/src/main/java/org/jclouds/virtualbox/util/NetworkUtils.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -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; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import com.google.common.util.concurrent.Uninterruptibles; -import org.jclouds.compute.callables.RunScriptOnNode; -import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.options.RunScriptOptions; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.location.Provider; -import org.jclouds.logging.Logger; -import org.jclouds.scriptbuilder.domain.Statements; -import org.jclouds.virtualbox.domain.BridgedIf; -import org.jclouds.virtualbox.domain.NetworkAdapter; -import org.jclouds.virtualbox.domain.NetworkInterfaceCard; -import org.jclouds.virtualbox.domain.NetworkSpec; -import org.jclouds.virtualbox.functions.IpAddressesLoadingCache; -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_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.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.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.inject.Inject; - -/** - * Utilities to manage VirtualBox networks on guests - */ - -@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; - - private final Supplier<VirtualBoxManager> manager; - private final MachineUtils machineUtils; - private final Supplier<NodeMetadata> host; - private final Supplier<URI> providerSupplier; - private final IpAddressesLoadingCache ipAddressesLoadingCache; - private final RunScriptOnNode.Factory scriptRunnerFactory; - private final Supplier<NodeMetadata> hostSupplier; - - @Inject - public NetworkUtils(Supplier<VirtualBoxManager> manager, MachineUtils machineUtils, Supplier<NodeMetadata> host, - @Provider Supplier<URI> providerSupplier, IpAddressesLoadingCache ipAddressesLoadingCache, - Supplier<NodeMetadata> hostSupplier, RunScriptOnNode.Factory scriptRunnerFactory) { - this.manager = manager; - this.machineUtils = machineUtils; - 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(); - - NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(1L).build(); - 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(); - NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter) - .addHostInterfaceName(hostOnlyIfName).slot(0L).build(); - return createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard); - } - - 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 boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) { - ListenableFuture<ExecResponse> 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) { - final String hostOnlyIfName = createHostOnlyIf(); - assignDHCPtoHostOnlyInterface(hostOnlyIfName); - return hostOnlyIfName; - } else { - return availableHostInterfaceIf.getName(); - } - } - - private void assignDHCPtoHostOnlyInterface(final String hostOnlyIfName) { - List<IHostNetworkInterface> availableNetworkInterfaces = manager.get().getVBox().getHost().getNetworkInterfaces(); - - IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter( - availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() { - - @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"; - String dhcpLowerIp = hostOnlyIfIpAddress.substring(0, hostOnlyIfIpAddress.lastIndexOf(".")) + ".2"; - String dhcpUpperIp = hostOnlyIfIpAddress.substring(0, hostOnlyIfIpAddress.lastIndexOf(".")) + ".253"; - 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); - } - - private String createHostOnlyIf() { - NodeMetadata hostNodeMetadata = getHostNodeMetadata(); - ExecResponse createHostOnlyResponse = scriptRunnerFactory - .create(hostNodeMetadata, Statements.exec("VBoxManage hostonlyif create"), - runAsRoot(false).wrapInInitScript(false)).init().call(); - String output = createHostOnlyResponse.getOutput(); - 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() { - return NodeMetadataBuilder.fromNodeMetadata(host.get()) - .publicAddresses(ImmutableList.of(providerSupplier.get().getHost())).build(); - } - - private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull( - Iterable<IHostNetworkInterface> availableNetworkInterfaces) { - checkNotNull(availableNetworkInterfaces); - return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces), - null); - } - - private Iterable<IHostNetworkInterface> filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled( - Iterable<IHostNetworkInterface> availableNetworkInterfaces) { - return Iterables.filter(availableNetworkInterfaces, - new Predicate<IHostNetworkInterface>() { - @Override - public boolean apply(IHostNetworkInterface iHostNetworkInterface) { - // this is an horrible workaround cause - // iHostNetworkInterface.getDhcpEnabled is working only for - // windows host - boolean match = false; - List<IDHCPServer> 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; - } - }); - } - - public String getValidHostOnlyIpFromVm(String machineNameOrId) { - long nicSlot = 0; - int count = 0; - String ipAddress = ""; - while (nicSlot < 4 && ipAddress.isEmpty()) { - MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = - MachineNameOrIdAndNicSlot.fromParts(machineNameOrId, nicSlot); - while (count < 10 && ipAddress.isEmpty()) { - Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS); - ipAddress = getIpAddressFromNicSlot(machineNameOrIdAndNicSlot); - if (!isValidIpForHostOnly(ipAddress)) { - ipAddressesLoadingCache.invalidate(machineNameOrIdAndNicSlot); - ipAddress = ""; - } - count++; - } - 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(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])$"; - Pattern pattern = Pattern.compile(IP_V4_ADDRESS_PATTERN); - Matcher matcher = pattern.matcher(s); - return matcher.matches(); - } - - 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) { - // RetrieveActiveBridgedInterfaces - List<BridgedIf> activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(scriptRunnerFactory) - .apply(hostSupplier.get()); - BridgedIf activeBridgedIf = checkNotNull(Iterables.get(activeBridgedInterfaces, 0), "activeBridgedInterfaces"); - String network = activeBridgedIf.getIpAddress(); - - // scan ip - 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(); - checkState(ipExecResponse.getExitStatus() == 0); - return checkNotNull(ipExecResponse.getOutput(), "ipAddress"); - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/virtualbox/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata deleted file mode 100644 index 6eeabb6..0000000 --- a/virtualbox/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata +++ /dev/null @@ -1 +0,0 @@ -org.jclouds.virtualbox.VirtualBoxApiMetadata \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/default-images.yaml ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/default-images.yaml b/virtualbox/src/main/resources/default-images.yaml deleted file mode 100644 index ff50c2b..0000000 --- a/virtualbox/src/main/resources/default-images.yaml +++ /dev/null @@ -1,149 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -images: - - id: ubuntu-12.04.1-amd64 - name: ubuntu-12.04.1-server-amd64 - description: ubuntu 12.04.1 server (amd64) - os_arch: amd64 - os_family: ubuntu - os_description: ubuntu - os_version: 12.04.1 - os_64bit: true - iso: http://releases.ubuntu.com/12.04.1/ubuntu-12.04.1-server-amd64.iso - iso_md5: a8c667e871f48f3a662f3fbf1c3ddb17 - username: toor - credential: password - keystroke_sequence: <Esc><Esc><Enter> /install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL debian-installer=en_US auto locale=en_US kbd-chooser/method=us hostname=HOSTNAME fb=false debconf/frontend=noninteractive console-setup/ask_detect=false keyboard-configuration/layoutcode=us initrd=/install/initrd.gz -- <Enter> - preseed_cfg: | - ## Options to set on the command line - d-i debian-installer/locale string en_US.utf8 - d-i console-setup/ask_detect boolean false - d-i console-setup/layout string USA - d-i netcfg/get_hostname string unassigned-hostname - d-i netcfg/get_domain string unassigned-domain - # Continue without a default route - # Not working , specify a dummy in the DHCP - #d-i netcfg/no_default_route boolean - d-i time/zone string UTC - d-i clock-setup/utc-auto boolean true - d-i clock-setup/utc boolean true - d-i kbd-chooser/method select American English - d-i netcfg/wireless_wep string - d-i base-installer/kernel/override-image string linux-server - #d-i base-installer/kernel/override-image string linux-image-2.6.32-21-generic - # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive - d-i debconf debconf/frontend select Noninteractive - d-i pkgsel/install-language-support boolean false - tasksel tasksel/first multiselect standard, ubuntu-server - #d-i partman-auto/method string regular - d-i partman-auto/method string lvm - #d-i partman-auto/purge_lvm_from_device boolean true - d-i partman-lvm/confirm boolean true - d-i partman-lvm/device_remove_lvm boolean true - d-i partman-auto/choose_recipe select atomic - d-i partman/confirm_write_new_label boolean true - d-i partman/confirm_nooverwrite boolean true - d-i partman/choose_partition select finish - d-i partman/confirm boolean true - #http://ubuntu-virginia.ubuntuforums.org/showthread.php?p=9626883 - #Message: "write the changes to disk and configure lvm preseed" - #http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input - #preseed partman-lvm/confirm_nooverwrite boolean true - # Write the changes to disks and configure LVM? - d-i partman-lvm/confirm boolean true - d-i partman-lvm/confirm_nooverwrite boolean true - d-i partman-auto-lvm/guided_size string max - ## Default user, we can get away with a recipe to change this - d-i passwd/user-fullname string toor - d-i passwd/username string toor - d-i passwd/user-password password password - d-i passwd/user-password-again password password - d-i user-setup/encrypt-home boolean false - d-i user-setup/allow-password-weak boolean true - ## minimum is ssh and ntp - # Individual additional packages to install - d-i pkgsel/include string openssh-server ntp - # Whether to upgrade packages after debootstrap. - # Allowed values: none, safe-upgrade, full-upgrade - d-i pkgsel/upgrade select full-upgrade - d-i grub-installer/only_debian boolean true - d-i grub-installer/with_other_os boolean true - d-i finish-install/reboot_in_progress note - #For the update - d-i pkgsel/update-policy select none - # debconf-get-selections --install - #Use mirror - #d-i apt-setup/use_mirror boolean true - #d-i mirror/country string manual - #choose-mirror-bin mirror/protocol string http - #choose-mirror-bin mirror/http/hostname string 192.168.4.150 - #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 - - id: centos-6.3-amd64 - name: centos-6.3-amd64 - description: centos-6.3 (amd64) - os_arch: amd64 - os_family: RedHat - os_description: RedHat - os_version: 6.3 - os_64bit: true - iso: http://www.mirrorservice.org/sites/mirror.centos.org/6.3/isos/x86_64/CentOS-6.3-x86_64-minimal.iso - iso_md5: 087713752fa88c03a5e8471c661ad1a2 - username: toor - credential: password - keystroke_sequence: <Tab> <Spacebar> text ks=PRECONFIGURATION_URL <Enter> - 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 --driveorder=sda --append="crashkernel=auto rhgb quiet" - zerombr yes - - clearpart --all --drives=sda --initlabel - autopart - auth --useshadow --enablemd5 - #skip answers to the First Boot process - firstboot --disable - #reboot machine - reboot - - %packages --ignoremissing - @core - %end - - %post - /usr/bin/yum -y install sudo gcc make kernel kernel-devel openssl-devel perl wget dkms acpid - /etc/init.d/haldaemon stop - /etc/init.d/acpid start - /etc/init.d/haldaemon start - /usr/sbin/groupadd toor - /usr/sbin/useradd toor -g toor -G wheel - echo "password"|passwd --stdin toor - echo "toor ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/toor - chmod 0440 /etc/sudoers.d/toor - sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers - %end \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/functions/checkVBoxService.sh ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/functions/checkVBoxService.sh b/virtualbox/src/main/resources/functions/checkVBoxService.sh deleted file mode 100644 index 85ab94b..0000000 --- a/virtualbox/src/main/resources/functions/checkVBoxService.sh +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -function checkVBoxService { - local _FOUND=`ps aux | grep '[V]BoxService'` - [ -n "$_FOUND" ] && { - return 0 - } || { - return 1 - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh b/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh deleted file mode 100644 index 921cb48..0000000 --- a/virtualbox/src/main/resources/functions/cleanupUdevIfNeeded.sh +++ /dev/null @@ -1,23 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -function cleanupUdevIfNeeded { - if [ -f '/etc/udev/rules.d/70-persistent-net.rules' ] - then - rm /etc/udev/rules.d/70-persistent-net.rules - fi - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/functions/exportIpAddressFromVmNamed.sh ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/functions/exportIpAddressFromVmNamed.sh b/virtualbox/src/main/resources/functions/exportIpAddressFromVmNamed.sh deleted file mode 100644 index aeb941b..0000000 --- a/virtualbox/src/main/resources/functions/exportIpAddressFromVmNamed.sh +++ /dev/null @@ -1,32 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -function exportIpAddressFromVmNamed { - unset FOUND_IP_ADDRESS; - [ $# -eq 1 ] || { - abort "exportIpAddressFromVmNamed requires virtual machine name parameter" - return 1 - } - local VMNAME="$0"; shift - local _FOUND=`VBoxManage guestproperty enumerate "$VMNAME" --patterns "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $4 }' | cut -c 1-14` - [ -n "$_FOUND" ] && { - export FOUND_IP_ADDRESS=$_FOUND - echo [$FOUND_IP_ADDRESS] - return 0 - } || { - return 1 - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/functions/getIpAddress.cmd ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/functions/getIpAddress.cmd b/virtualbox/src/main/resources/functions/getIpAddress.cmd deleted file mode 100644 index 460afbf..0000000 --- a/virtualbox/src/main/resources/functions/getIpAddress.cmd +++ /dev/null @@ -1,16 +0,0 @@ -REM -REM Licensed to the Apache Software Foundation (ASF) under one or more -REM contributor license agreements. See the NOTICE file distributed with -REM this work for additional information regarding copyright ownership. -REM The ASF licenses this file to You under the Apache License, Version 2.0 -REM (the "License"); you may not use this file except in compliance with -REM the License. You may obtain a copy of the License at -REM -REM http://www.apache.org/licenses/LICENSE-2.0 -REM -REM Unless required by applicable law or agreed to in writing, software -REM distributed under the License is distributed on an "AS IS" BASIS, -REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -REM See the License for the specific language governing permissions and -REM limitations under the License. -REM http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/functions/getIpAddress.sh ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/functions/getIpAddress.sh b/virtualbox/src/main/resources/functions/getIpAddress.sh deleted file mode 100644 index f4e28ad..0000000 --- a/virtualbox/src/main/resources/functions/getIpAddress.sh +++ /dev/null @@ -1,32 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -function getIpAddress { - unset FOUND_IP_ADDRESS; - [ $# -eq 1 ] || { - abort "installGuestAdditions requires virtual machine name parameter" - return 1 - } - local VMNAME="$0"; shift - local _FOUND=`VBoxManage guestproperty enumerate "$VMNAME" --patterns "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $4 }' | cut -c 1-14` - [ -n "$_FOUND" ] && { - export FOUND_IP_ADDRESS=$_FOUND - echo [$FOUND_IP_ADDRESS] - return 0 - } || { - return 1 - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh ---------------------------------------------------------------------- diff --git a/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh b/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh deleted file mode 100644 index 5a392e1..0000000 --- a/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh +++ /dev/null @@ -1,27 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. -# -function installModuleAssistantIfNeeded { - unset OSNAME; - local OSNAME=`lsb_release -d -s | cut -d ' ' -f 1`; shift - if [ $OSNAME = 'Ubuntu' ] - then - echo "OS is Ubuntu" - apt-get -f -y -qq --force-yes install dkms build-essential linux-headers-`uname -r` module-assistant acpid; - m-a prepare -i - return 0 - fi -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java deleted file mode 100644 index 362b985..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; - -import java.io.File; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.rest.annotations.BuildVersion; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.util.Strings2; -import org.jclouds.virtualbox.config.VirtualBoxConstants; -import org.jclouds.virtualbox.domain.HardDisk; -import org.jclouds.virtualbox.domain.IsoSpec; -import org.jclouds.virtualbox.domain.Master; -import org.jclouds.virtualbox.domain.MasterSpec; -import org.jclouds.virtualbox.domain.NetworkAdapter; -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.IMachineToVmSpec; -import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia; -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_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.Splitter; -import com.google.common.base.Supplier; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.util.concurrent.Uninterruptibles; -import com.google.inject.Key; -import com.google.inject.Module; - -/** - * Tests behavior of {@code VirtualBoxClient} - */ -@Test(groups = "live", singleThreaded = true, testName = "BaseVirtualBoxClientLiveTest") -public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveTest { - - public static final String DESTROY_MASTER = "jclouds.virtualbox.destroy-test-master"; - - public BaseVirtualBoxClientLiveTest() { - provider = "virtualbox"; - } - - @Inject - protected MachineController machineController; - - @Inject - protected Supplier<VirtualBoxManager> manager; - - @Inject - void eagerlyStartManager(Supplier<VirtualBoxManager> manager) { - this.manager = manager; - manager.get(); - } - - @Inject - protected MachineUtils machineUtils; - - @Inject - protected NetworkUtils networkUtils; - - protected String hostVersion; - protected String operatingSystemIso; - protected String guestAdditionsIso; - @Inject - @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) - protected String workingDir; - protected String isosDir; - protected String keystrokeSequence; - @Inject protected Supplier<NodeMetadata> host; - @Inject - protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate; - @Inject - protected LoadingCache<Image, Master> mastersCache; - private String masterName; - - @Override - protected Iterable<Module> setupModules() { - return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule(), new ExecutorServiceModule( - sameThreadExecutor(), sameThreadExecutor())); - } - - @Override - @BeforeClass(groups = { "integration", "live" }) - public void setupContext() { - super.setupContext(); - view.utils().injector().injectMembers(this); - - // try and get a master from the cache, this will initialize the config/download isos and - // prepare everything IF a master is not available, subsequent calls should be pretty fast - Template template = view.getComputeService().templateBuilder().build(); - checkNotNull(mastersCache.getUnchecked(template.getImage())); - - masterName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId(); - isosDir = workingDir + File.separator + "isos"; - - 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); - keystrokeSequence = ""; - try { - keystrokeSequence = Strings2.toStringAndClose(getClass().getResourceAsStream("/default-keystroke-sequence")); - } catch (IOException e) { - throw new RuntimeException("error reading default-keystroke-sequence file"); - } - } - - protected void undoVm(String vmNameOrId) { - IMachine vm = null; - try { - vm = manager.get().getVBox().findMachine(vmNameOrId); - VmSpec vmSpec = new IMachineToVmSpec().apply(vm); - int attempts = 0; - while (attempts < 10 && !vm.getSessionState().equals(SessionState.Unlocked)) { - attempts++; - Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); - } - machineUtils.applyForMachine(vmNameOrId, new UnregisterMachineIfExistsAndDeleteItsMedia(vmSpec)); - - } catch (VBoxException e) { - if (e.getMessage().contains("Could not find a registered machine named")) - return; - } - } - - public String adminDisk(String vmName) { - return workingDir + File.separator + vmName + ".vdi"; - } - - public MasterSpec getMasterSpecForTest() { - StorageController ideController = StorageController - .builder() - .name("IDE Controller") - .bus(StorageBus.IDE) - .attachISO(0, 0, operatingSystemIso) - .attachHardDisk( - HardDisk.builder().diskpath(adminDisk(masterName)).controllerPort(0).deviceSlot(1) - .autoDelete(true).build()).attachISO(1, 0, guestAdditionsIso).build(); - - VmSpec sourceVmSpec = VmSpec.builder().id(masterName).name(masterName).osTypeId("").memoryMB(512) - .cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build(); - - IsoSpec isoSpec = IsoSpec - .builder() - .sourcePath(operatingSystemIso) - .installationScript(keystrokeSequence).build(); - - NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) - .tcpRedirectRule("127.0.0.1", 2222, "", 22).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter) - .build(); - - NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build(); - return MasterSpec.builder().iso(isoSpec).vm(sourceVmSpec).network(networkSpec).build(); - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - @AfterSuite - protected void destroyMaster() { - if (System.getProperty(DESTROY_MASTER) != null - || Boolean.parseBoolean(System.getProperty(DESTROY_MASTER))) { - undoVm(masterName); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java deleted file mode 100644 index 249d6de..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/PreseedCfgServerTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; -import java.net.URL; -import java.util.Map; -import java.util.Properties; - -import org.jclouds.compute.domain.Image; -import org.jclouds.util.Strings2; -import org.jclouds.virtualbox.config.VirtualBoxConstants; -import org.jclouds.virtualbox.domain.YamlImage; -import org.jclouds.virtualbox.functions.YamlImagesFromFileConfig; -import org.jclouds.virtualbox.functions.admin.ImagesToYamlImagesFromYamlDescriptor; -import org.jclouds.virtualbox.functions.admin.PreseedCfgServer; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -/** - * Tests that jetty is able to serve the preseed.cfg from the provided yaml - * image. This test is here to have access to the defaultProperties() method in - * {@link VirtualBoxPropertiesBuilder}. - */ -@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(); - - String preconfigurationUrl = props.getProperty(VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL); - - int port = URI.create(preconfigurationUrl).getPort(); - - PreseedCfgServer starter = new PreseedCfgServer(); - - starter.start(preconfigurationUrl, getDefaultImage().preseed_cfg); - - String preseedFileFromJetty = Strings2.toStringAndClose(new URL("http://127.0.0.1:" + port + "/preseed.cfg").openStream()); - String preseedFileFromFile = getDefaultImage().preseed_cfg + lineSeparator; - assertEquals(preseedFileFromFile, preseedFileFromJetty); - - starter.stop(); - } - - public static YamlImage getDefaultImage() { - Map<Image, YamlImage> images = new ImagesToYamlImagesFromYamlDescriptor(new YamlImagesFromFileConfig( - "/default-images.yaml")).get(); - return Iterables.get(images.values(), 0); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java deleted file mode 100644 index 45b73e1..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/VirtualBoxApiMetadataTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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; - -import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "VirtualBoxApiMetadataTest") -public class VirtualBoxApiMetadataTest extends BaseComputeServiceApiMetadataTest { - - public VirtualBoxApiMetadataTest() { - super(new VirtualBoxApiMetadata()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java deleted file mode 100644 index cac53b9..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.compute; - -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; - -import java.util.Random; - -import javax.inject.Inject; - -import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; -import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Template; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.ssh.SshClient; -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_2.IMachine; - -import com.google.common.collect.Iterables; - -@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") -public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { - - private NodeAndInitialCredentials<IMachine> ubuntu; - private NodeAndInitialCredentials<IMachine> centos; - - @Inject - protected VirtualBoxComputeServiceAdapter adapter; - - - @Test - public void testCreatedNodeHasExpectedNameAndWeCanConnectViaSsh() { - String group = "foo"; - String name = "foo-ef9"; - Template template = view.getComputeService().templateBuilder().build(); - ubuntu = adapter.createNodeWithGroupEncodedIntoName(group, name, template); - assertTrue(ubuntu.getNode().getName().contains(group)); - assertTrue(ubuntu.getNode().getName().contains(name)); - assertTrue(ubuntu.getNode().getName().startsWith(VIRTUALBOX_NODE_PREFIX)); - doConnectViaSsh(ubuntu.getNode(), prioritizeCredentialsFromTemplate.apply(template, ubuntu.getCredentials())); - } - - @Test - public void testCreatedCentosNodeHasExpectedNameAndWeCanConnectViaSsh() { - String group = "foo"; - String name = "centos6-" + new Random(100).nextInt(); - Template template = view.getComputeService().templateBuilder() - .imageId("centos-6.3-amd64") - .build(); - centos = adapter.createNodeWithGroupEncodedIntoName(group, name, template); - assertTrue(centos.getNode().getName().contains(group)); - assertTrue(centos.getNode().getName().contains(name)); - assertTrue(centos.getNode().getName().startsWith(VIRTUALBOX_NODE_PREFIX)); - doConnectViaSsh(centos.getNode(), prioritizeCredentialsFromTemplate.apply(template, centos.getCredentials())); - } - - protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) { - SshClient ssh = view.utils().injector().getInstance(IMachineToSshClient.class).apply(machine); - try { - ssh.connect(); - ExecResponse hello = ssh.exec("echo hello"); - assertEquals(hello.getOutput().trim(), "hello"); - System.err.println(ssh.exec("df -k").getOutput()); - System.err.println(ssh.exec("mount").getOutput()); - System.err.println(ssh.exec("uname -a").getOutput()); - } finally { - if (ssh != null) - ssh.disconnect(); - } - } - - @Test - public void testListHardwareProfiles() { - Iterable<Hardware> profiles = adapter.listHardwareProfiles(); - assertFalse(Iterables.isEmpty(profiles)); - } - - @Test - public void testListImages() { - Iterable<Image> iMageIterable = adapter.listImages(); - assertFalse(Iterables.isEmpty(iMageIterable)); - } - - @AfterGroups(groups = "live") - @Override - protected void tearDownContext() { - if (ubuntu != null) - adapter.destroyNode(ubuntu.getNodeId() + ""); - if (centos != null) - adapter.destroyNode(centos.getNodeId() + ""); - super.tearDownContext(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java deleted file mode 100644 index afa8c83..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.compute; - -import static org.easymock.EasyMock.createNiceMock; -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.List; -import java.util.Map; - -import org.easymock.EasyMock; -import org.jclouds.compute.config.BaseComputeServiceContextModule; -import org.jclouds.compute.domain.Image; -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.functions.IMachineToImage; -import org.testng.annotations.Test; -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.inject.Guice; - -@Test(groups = "unit") -public class VirtualBoxComputeServiceAdapterTest { - - Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() { - }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) - .getInstance(Json.class)); - - @Test - public void testListImages() throws Exception { - - VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class); - IVirtualBox vBox = createNiceMock(IVirtualBox.class); - IGuestOSType osType = createNiceMock(IGuestOSType.class); - - List<IMachine> machines = Lists.newArrayList(); - IMachine imageMachine = createNiceMock(IMachine.class); - IMachine clonedMachine = createNiceMock(IMachine.class); - machines.add(imageMachine); - machines.add(clonedMachine); - - expect(clonedMachine.getName()).andReturn("My Linux Node"); - expect(clonedMachine.getDescription()).andReturn("My Linux Node"); - expect(imageMachine.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + "ubuntu-10.04"); - expect(imageMachine.getDescription()).andReturn(VIRTUALBOX_IMAGE_PREFIX + "ubuntu-10.04"); - - expect(manager.getVBox()).andReturn(vBox).anyTimes(); - expect(vBox.getMachines()).andReturn(machines).anyTimes(); - expect(vBox.getGuestOSType(EasyMock.<String> anyObject())).andReturn(osType).anyTimes(); - expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes(); - expect(osType.getIs64Bit()).andReturn(true).anyTimes(); - - replay(manager, vBox, clonedMachine, imageMachine, osType); - - Function<IMachine, Image> iMachineToImage = new IMachineToImage( - VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java deleted file mode 100644 index 389f439..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.compute; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.ContextBuilder; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.RunNodesException; -import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; -import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.ssh.SshClient; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest") -public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - ComputeServiceContext context; - - @BeforeClass - public void setUp() { - context = ContextBuilder.newBuilder("virtualbox").modules( - ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule())).build( - ComputeServiceContext.class); - } - - @Test - public void testLaunchCluster() throws RunNodesException { - int numNodes = 3; - final String clusterName = "test-launch-cluster"; - Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes, - TemplateOptions.Builder.overrideLoginUser("toor")); - assertEquals(numNodes, nodes.size(), "wrong number of nodes"); - for (NodeMetadata node : nodes) { - assertTrue(node.getGroup().equals("test-launch-cluster")); - logger.debug("Created Node: %s", node); - SshClient client = context.utils().sshForNode().apply(node); - client.connect(); - ExecResponse hello = client.exec("echo hello"); - assertEquals(hello.getOutput().trim(), "hello"); - } - context.getComputeService().destroyNodesMatching(new Predicate<NodeMetadata>() { - @Override - public boolean apply(NodeMetadata input) { - return input.getId().contains(clusterName); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java deleted file mode 100644 index 3318d4a..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/compute/extensions/VirtualBoxImageExtensionLiveTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.compute.extensions; - -import java.util.concurrent.ExecutionException; - -import org.jclouds.compute.RunNodesException; -import org.jclouds.compute.extensions.internal.BaseImageExtensionLiveTest; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.Test; - -import com.google.inject.Module; - -@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxImageExtensionLiveTest") -public class VirtualBoxImageExtensionLiveTest extends BaseImageExtensionLiveTest { - - @Override - public void testDeleteImage() { - // TODO - } - - @Override - public void testCreateImage() throws RunNodesException, - InterruptedException, ExecutionException { - // TODO - } - - @Override - public void testSpawnNodeFromImage() throws RunNodesException { - // TODO - } - - public VirtualBoxImageExtensionLiveTest() { - provider = "virtualbox"; - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ExportIpAddressForVMNamedTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ExportIpAddressForVMNamedTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ExportIpAddressForVMNamedTest.java deleted file mode 100644 index 1ea1af4..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ExportIpAddressForVMNamedTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.domain; - -import static org.jclouds.scriptbuilder.domain.Statements.interpret; -import static org.jclouds.virtualbox.statements.Statements.exportIpAddressFromVmNamed; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.scriptbuilder.ScriptBuilder; -import org.jclouds.scriptbuilder.domain.OsFamily; -import org.jclouds.scriptbuilder.domain.ShellToken; -import org.testng.annotations.Test; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; - -@Test(groups = "unit") -public class ExportIpAddressForVMNamedTest { - - ScriptBuilder exportIpAddressForVMNamedBuilder = new ScriptBuilder() - .addStatement(exportIpAddressFromVmNamed("{args}")) - .addStatement(interpret("echo {varl}FOUND_IP_ADDRESS{varr}{lf}")); - - public void testUNIX() throws IOException { - assertEquals(exportIpAddressForVMNamedBuilder.render(OsFamily.UNIX), Resources.toString(Resources.getResource( - "test_export_ip_address_from_vm_named." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ScanNetworkWithPingTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ScanNetworkWithPingTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ScanNetworkWithPingTest.java deleted file mode 100644 index 08552fd..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/domain/ScanNetworkWithPingTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.domain; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.scriptbuilder.domain.OsFamily; -import org.jclouds.virtualbox.statements.ScanNetworkWithPing; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class ScanNetworkWithPingTest { - - private static final String network = "192.168.1.1"; - private static final String networkWithoutLastNumber = "192.168.1"; - - public void testGetIPAdressFromMacAddressUnix() { - ScanNetworkWithPing statement = new ScanNetworkWithPing(network); - assertEquals(statement.render(OsFamily.UNIX), "for i in {1..254} ; do ping -c 1 -t 1 " + networkWithoutLastNumber + ".$i & done"); - - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java deleted file mode 100644 index a32a6f4..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.domain; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; - -import org.testng.annotations.Test; -import org.virtualbox_4_2.CleanupMode; -import org.virtualbox_4_2.StorageBus; - -public class VmSpecTest { - - @Test - public void testEqualsSuccessful() throws Exception { - VmSpec vmSpec = defaultVm().build(); - VmSpec sameVmSpec = defaultVm().build(); - assertEquals(vmSpec, sameVmSpec); - } - - @Test - public void testEqualsWrongId() throws Exception { - VmSpec vmSpec = defaultVm().build(); - VmSpec other = defaultVm().id("OtherVMId").build(); - assertNotEquals(vmSpec, other); - } - - @Test - public void testEqualsWrongName() throws Exception { - VmSpec vmSpec = defaultVm().build(); - VmSpec other = defaultVm().name("OtherName").build(); - assertNotEquals(vmSpec, other); - } - - @Test - public void testEqualsWrongOsType() throws Exception { - VmSpec vmSpec = defaultVm().build(); - VmSpec other = defaultVm().osTypeId("OtherOS").build(); - assertNotEquals(vmSpec, other); - } - - @Test - public void testEqualsWrongForceOverwriteRule() throws Exception { - VmSpec vmSpec = defaultVm().build(); - VmSpec other = defaultVm().forceOverwrite(false).build(); - assertNotEquals(vmSpec, other); - } - - private VmSpec.Builder defaultVm() { - return VmSpec.builder() - .id("MyVmId") - .name("My VM") - .osTypeId("Ubuntu") - .memoryMB(1024) - .cleanUpMode(CleanupMode.Full) - .forceOverwrite(true) - .controller( - StorageController.builder().name("Controller") - .bus(StorageBus.IDE) - .attachHardDisk(HardDisk.builder().diskpath("/tmp/tempdisk.vdi") - .controllerPort(0).deviceSlot(0).build()) - .build()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestConfiguration.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestConfiguration.java b/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestConfiguration.java deleted file mode 100644 index e778f5e..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestConfiguration.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.virtualbox.experiment; - -import java.util.Map; - -import org.jclouds.scriptbuilder.statements.login.AdminAccess.Configuration; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; - -public enum TestConfiguration implements Configuration { - INSTANCE; - int pwCount = 0; - - public TestConfiguration reset() { - pwCount = 0; - return this; - } - - private final Supplier<String> defaultAdminUsername = Suppliers.ofInstance("defaultAdminUsername"); - private final Supplier<Map<String, String>> defaultAdminSshKeys = Suppliers - .<Map<String, String>> ofInstance(ImmutableMap.of("public", "publicKey", "private", "privateKey")); - private final Supplier<String> passwordGenerator = new Supplier<String>() { - - @Override - public String get() { - return pwCount++ + ""; - } - - }; - - private final Function<String, String> cryptFunction = new Function<String, String>() { - - @Override - public String apply(String input) { - return String.format("crypt(%s)", input); - } - - }; - - @Override - public Supplier<String> defaultAdminUsername() { - return defaultAdminUsername; - } - - @Override - public Supplier<Map<String, String>> defaultAdminSshKeys() { - return defaultAdminSshKeys; - } - - @Override - public Supplier<String> passwordGenerator() { - return passwordGenerator; - } - - @Override - public Function<String, String> cryptFunction() { - return cryptFunction; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java deleted file mode 100644 index 63fc292..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExistsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.functions; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import org.jclouds.virtualbox.domain.StorageController; -import org.testng.annotations.Test; -import org.virtualbox_4_2.IMachine; -import org.virtualbox_4_2.IStorageController; -import org.virtualbox_4_2.StorageBus; -import org.virtualbox_4_2.VBoxException; - -@Test(groups = "unit", testName = "AddIDEControllerIfNotExistsTest") -public class AddIDEControllerIfNotExistsTest { - - @Test - public void testFine() throws Exception { - IMachine vm = createMock(IMachine.class); - - String controllerName = "IDE Controller"; - StorageController storageController = StorageController.builder().bus(StorageBus.IDE).name(controllerName).build(); - - expect(vm.addStorageController(controllerName, StorageBus.IDE)).andReturn( - createNiceMock(IStorageController.class)); - vm.saveSettings(); - - replay(vm); - - new AddIDEControllerIfNotExists(storageController).apply(vm); - - verify(vm); - } - - @Test - public void testAcceptableException() throws Exception { - IMachine vm = createMock(IMachine.class); - - String controllerName = "IDE Controller"; - StorageController storageController = StorageController.builder().bus(StorageBus.IDE).name(controllerName).build(); - - expect(vm.addStorageController(controllerName, StorageBus.IDE)).andThrow( - new VBoxException(createNiceMock(Throwable.class), - "VirtualBox error: Storage controller named 'IDE Controller' already exists (0x80BB000C)")); - - replay(vm); - - new AddIDEControllerIfNotExists(storageController).apply(vm); - - verify(vm); - } - - @Test(expectedExceptions = VBoxException.class) - public void testUnacceptableException() throws Exception { - IMachine vm = createMock(IMachine.class); - - String controllerName = "IDE Controller"; - StorageController storageController = StorageController.builder().bus(StorageBus.IDE).name(controllerName).build(); - - expect(vm.addStorageController(controllerName, StorageBus.IDE)).andThrow( - new VBoxException(createNiceMock(Throwable.class), "VirtualBox error: General Error")); - - replay(vm); - - new AddIDEControllerIfNotExists(storageController).apply(vm); - - verify(vm); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyBootOrderToMachineTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyBootOrderToMachineTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyBootOrderToMachineTest.java deleted file mode 100644 index 922ece6..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyBootOrderToMachineTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.functions; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import com.google.common.collect.ImmutableMap; -import org.testng.annotations.Test; -import org.virtualbox_4_2.DeviceType; -import org.virtualbox_4_2.IMachine; - -import java.util.Map; - -@Test(groups = "unit", testName = "ApplyBootOrderToMachineTest") -public class ApplyBootOrderToMachineTest { - - @Test - public void testSetBootOrderSuccessful() throws Exception { - Map<Long, DeviceType> positionAndDeviceType = ImmutableMap.of(1l, DeviceType.HardDisk); - IMachine machine = createMock(IMachine.class); - for (long position : positionAndDeviceType.keySet()) { - machine.setBootOrder(position, positionAndDeviceType.get(position)); - } - machine.saveSettings(); - replay(machine); - new ApplyBootOrderToMachine(positionAndDeviceType).apply(machine); - verify(machine); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java deleted file mode 100644 index 6efe32b..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.functions; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import org.testng.annotations.Test; -import org.virtualbox_4_2.IMachine; -import org.virtualbox_4_2.VBoxException; - -@Test(groups = "unit", testName = "ApplyMemoryToMachineTest") -public class ApplyMemoryToMachineTest { - - @Test - public void testSetRAMSizeSuccessful() throws Exception { - long memorySize = 1024l; - IMachine machine = createMock(IMachine.class); - - machine.setMemorySize(memorySize); - machine.saveSettings(); - - replay(machine); - - new ApplyMemoryToMachine(memorySize).apply(machine); - - verify(machine); - } - - @Test(expectedExceptions = VBoxException.class) - public void testRethrowInvalidRamSizeError() throws Exception { - // Mainly here for documentation purposes - final String error = "VirtualBox error: Invalid RAM size: " - + "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)"; - - long memorySize = 1024l; - IMachine machine = createMock(IMachine.class); - - VBoxException invalidRamSizeException = new VBoxException(createNiceMock(Throwable.class), error); - machine.setMemorySize(memorySize); - expectLastCall().andThrow(invalidRamSizeException); - machine.saveSettings(); - - replay(machine); - - new ApplyMemoryToMachine(memorySize).apply(machine); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/75178c77/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java ---------------------------------------------------------------------- diff --git a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java b/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java deleted file mode 100644 index d97774c..0000000 --- a/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachBridgedAdapterToMachineTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.functions; - -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_2.NetworkAttachmentType.Bridged; - -import org.jclouds.virtualbox.domain.NetworkAdapter; -import org.jclouds.virtualbox.domain.NetworkInterfaceCard; -import org.testng.annotations.Test; -import org.virtualbox_4_2.IMachine; -import org.virtualbox_4_2.INetworkAdapter; -import org.virtualbox_4_2.NetworkAttachmentType; - -@Test(groups = "unit", testName = "AttachBridgedAdapterToMachineTest") -public class AttachBridgedAdapterToMachineTest { - - private String macAddress; - private String hostInterface; - - @Test - public void testApplyNetworkingToNonExistingAdapter() throws Exception { - Long adapterId = 0l; - IMachine machine = createMock(IMachine.class); - INetworkAdapter iNetworkAdapter = createMock(INetworkAdapter.class); - - expect(machine.getNetworkAdapter(adapterId)).andReturn(iNetworkAdapter); - iNetworkAdapter.setAttachmentType(Bridged); - iNetworkAdapter.setMACAddress(macAddress); - iNetworkAdapter.setBridgedInterface(hostInterface); - iNetworkAdapter.setEnabled(true); - machine.saveSettings(); - - replay(machine, iNetworkAdapter); - NetworkAdapter networkAdapter = NetworkAdapter.builder() - .networkAttachmentType(NetworkAttachmentType.Bridged).build(); - NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard - .builder().addNetworkAdapter(networkAdapter).build(); - - new AttachBridgedAdapterToMachine(networkInterfaceCard).apply(machine); - - verify(machine, iNetworkAdapter); - } - -}
