From af553b6294f485736c686ba9cd9f9ed32df10a86 Mon Sep 17 00:00:00 2001 From: andreaturli Date: Mon, 6 Feb 2012 22:53:09 +0000 Subject: [PATCH] issue 384: GuestAdditionsInstaller - fix future --- .../statements/InstallGuestAdditions.java | 4 +-- ...s.sh => installModuleAssistantIfNeeded.sh} | 2 +- ...va => GuestAdditionsInstallationTest.java} | 4 +-- .../statements/GuestAdditionsInstaller.java | 16 +++++++--- .../test_guest_additions_installer.sh | 26 ++++++++++++++++ .../resources/test_install_guest_additions.sh | 30 ------------------- 6 files changed, 43 insertions(+), 39 deletions(-) rename labs/virtualbox/src/main/resources/functions/{installGuestAdditions.sh => installModuleAssistantIfNeeded.sh} (85%) rename labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/{InstallGuestAdditionsTest.java => GuestAdditionsInstallationTest.java} (90%) create mode 100644 labs/virtualbox/src/test/resources/test_guest_additions_installer.sh delete mode 100644 labs/virtualbox/src/test/resources/test_install_guest_additions.sh 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 cfcf5f7c5b..8ba07609ea 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 @@ -65,8 +65,8 @@ public class InstallGuestAdditions implements Statement { .create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/" + vboxGuestAdditionsIso), ImmutableMultimap. of())) .addStatement(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint))) - .addStatement(call("installGuestAdditions")) - .addStatement(exec(String.format("sh %s%s", mountPoint, "/VBoxLinuxAdditions.run"))) + .addStatement(call("installModuleAssistantIfNeeded")) + .addStatement(exec(String.format("%s%s", mountPoint, "/VBoxLinuxAdditions.run"))) .addStatement(exec(String.format("umount %s", mountPoint))); return scriptBuilder.render(family); diff --git a/labs/virtualbox/src/main/resources/functions/installGuestAdditions.sh b/labs/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh similarity index 85% rename from labs/virtualbox/src/main/resources/functions/installGuestAdditions.sh rename to labs/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh index 205aa45d92..93e741f357 100644 --- a/labs/virtualbox/src/main/resources/functions/installGuestAdditions.sh +++ b/labs/virtualbox/src/main/resources/functions/installModuleAssistantIfNeeded.sh @@ -1,4 +1,4 @@ -function installGuestAdditions { +function installModuleAssistantIfNeeded { unset OSNAME; local OSNAME=`lsb_release -d -s | cut -d ' ' -f 1`; shift if [ $OSNAME = 'Ubuntu' ] diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/InstallGuestAdditionsTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GuestAdditionsInstallationTest.java similarity index 90% rename from labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/InstallGuestAdditionsTest.java rename to labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GuestAdditionsInstallationTest.java index 8aace24860..3f854e50b2 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/InstallGuestAdditionsTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/domain/GuestAdditionsInstallationTest.java @@ -32,11 +32,11 @@ import com.google.common.io.CharStreams; import com.google.common.io.Resources; @Test(groups = "unit") -public class InstallGuestAdditionsTest { +public class GuestAdditionsInstallationTest { @Test public void testUnix() throws IOException { InstallGuestAdditions statement = new InstallGuestAdditions("4.1.6"); assertEquals(statement.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources - .getResource("test_install_guest_additions." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8))); + .getResource("test_guest_additions_installer." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8))); } } \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java index 62ba744ea3..36fbba812a 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java @@ -3,6 +3,8 @@ package org.jclouds.virtualbox.statements; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import java.util.concurrent.ExecutionException; + import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Singleton; @@ -70,14 +72,20 @@ public class GuestAdditionsInstaller implements Function { NodeMetadata vmMetadata = new IMachineToNodeMetadata().apply(vm); - context.getComputeService().submitScriptOnNode(vmMetadata.getId(), statementList, + ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmMetadata.getId(), statementList, runAsRoot(true).wrapInInitScript(false)); - + try { + execFuture.get(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } return vm; } private void ensureMachineIsLaunched(String vmName) { machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, "")); } - -} + +} \ No newline at end of file diff --git a/labs/virtualbox/src/test/resources/test_guest_additions_installer.sh b/labs/virtualbox/src/test/resources/test_guest_additions_installer.sh new file mode 100644 index 0000000000..8af63cbff9 --- /dev/null +++ b/labs/virtualbox/src/test/resources/test_guest_additions_installer.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set +u +shopt -s xpg_echo +shopt -s expand_aliases +unset PATH JAVA_HOME LD_LIBRARY_PATH +function abort { + echo "aborting: $@" 1>&2 + exit 1 +} +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 build-essential module-assistant && m-a prepare -i + fi + return 0 +} +export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin +(mkdir -p /tmp/ && cd /tmp/ && [ ! -f VBoxGuestAdditions_4.1.6.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.1.6/VBoxGuestAdditions_4.1.6.iso >VBoxGuestAdditions_4.1.6.iso) +mount -o loop /tmp/VBoxGuestAdditions_4.1.6.iso /mnt +installModuleAssistantIfNeeded || exit 1 +/mnt/VBoxLinuxAdditions.run +umount /mnt +exit 0 diff --git a/labs/virtualbox/src/test/resources/test_install_guest_additions.sh b/labs/virtualbox/src/test/resources/test_install_guest_additions.sh deleted file mode 100644 index fe2736bff5..0000000000 --- a/labs/virtualbox/src/test/resources/test_install_guest_additions.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -set +u -shopt -s xpg_echo -shopt -s expand_aliases -unset PATH JAVA_HOME LD_LIBRARY_PATH -function abort { - echo "aborting: $@" 1>&2 - exit 1 -} -function installGuestAdditions { - unset OSNAME; - [ $# -eq 1 ] || { - abort "installGuestAdditions requires virtual machine name parameter" - return 1 - } - local OSNAME=`lsb_release -d -s | cut -d ' ' -f 1`; shift - if [ $OSNAME = 'Ubuntu' ] - then - echo "OS Name is Ubuntu" - `apt-get install build-essential module-assistant && m-a prepare -i` - fi - return 0 -} -export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin -(mkdir -p /tmp && cd /tmp && [ ! -f VBoxGuestAdditions_4.1.6.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.1.6/VBoxGuestAdditions_4.1.6.iso >VBoxGuestAdditions_4.1.6.iso) -mount -o loop /tmp/VBoxGuestAdditions_4.1.6.iso /mnt -installGuestAdditions || exit 1 -sh /mnt/VBoxLinuxAdditions.run -umount /mnt -exit 0