mirror of https://github.com/apache/jclouds.git
issue 384: GuestAdditionsInstaller - fix future
This commit is contained in:
parent
623f3c6daa
commit
af553b6294
|
@ -65,8 +65,8 @@ public class InstallGuestAdditions implements Statement {
|
||||||
.create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/"
|
.create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/"
|
||||||
+ vboxGuestAdditionsIso), ImmutableMultimap.<String, String> of()))
|
+ vboxGuestAdditionsIso), ImmutableMultimap.<String, String> of()))
|
||||||
.addStatement(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint)))
|
.addStatement(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint)))
|
||||||
.addStatement(call("installGuestAdditions"))
|
.addStatement(call("installModuleAssistantIfNeeded"))
|
||||||
.addStatement(exec(String.format("sh %s%s", mountPoint, "/VBoxLinuxAdditions.run")))
|
.addStatement(exec(String.format("%s%s", mountPoint, "/VBoxLinuxAdditions.run")))
|
||||||
.addStatement(exec(String.format("umount %s", mountPoint)));
|
.addStatement(exec(String.format("umount %s", mountPoint)));
|
||||||
|
|
||||||
return scriptBuilder.render(family);
|
return scriptBuilder.render(family);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function installGuestAdditions {
|
function installModuleAssistantIfNeeded {
|
||||||
unset OSNAME;
|
unset OSNAME;
|
||||||
local OSNAME=`lsb_release -d -s | cut -d ' ' -f 1`; shift
|
local OSNAME=`lsb_release -d -s | cut -d ' ' -f 1`; shift
|
||||||
if [ $OSNAME = 'Ubuntu' ]
|
if [ $OSNAME = 'Ubuntu' ]
|
|
@ -32,11 +32,11 @@ import com.google.common.io.CharStreams;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class InstallGuestAdditionsTest {
|
public class GuestAdditionsInstallationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnix() throws IOException {
|
public void testUnix() throws IOException {
|
||||||
InstallGuestAdditions statement = new InstallGuestAdditions("4.1.6");
|
InstallGuestAdditions statement = new InstallGuestAdditions("4.1.6");
|
||||||
assertEquals(statement.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,8 @@ package org.jclouds.virtualbox.statements;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -70,14 +72,20 @@ public class GuestAdditionsInstaller implements Function<String, IMachine> {
|
||||||
|
|
||||||
NodeMetadata vmMetadata = new IMachineToNodeMetadata().apply(vm);
|
NodeMetadata vmMetadata = new IMachineToNodeMetadata().apply(vm);
|
||||||
|
|
||||||
context.getComputeService().submitScriptOnNode(vmMetadata.getId(), statementList,
|
ListenableFuture<ExecResponse> execFuture = context.getComputeService().submitScriptOnNode(vmMetadata.getId(), statementList,
|
||||||
runAsRoot(true).wrapInInitScript(false));
|
runAsRoot(true).wrapInInitScript(false));
|
||||||
|
try {
|
||||||
|
execFuture.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMachineIsLaunched(String vmName) {
|
private void ensureMachineIsLaunched(String vmName) {
|
||||||
machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, ""));
|
machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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
|
|
@ -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
|
|
Loading…
Reference in New Issue