mirror of https://github.com/apache/jclouds.git
issue 384: modify SshDaemonIsRunning<IMachine> in SshAvailable<String> to address jclouds's comment
This commit is contained in:
parent
c86e771a9c
commit
c263c7b126
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.jclouds.virtualbox.predicates;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -30,7 +29,6 @@ import org.jclouds.compute.ComputeServiceContext;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.ssh.SshException;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
|
@ -38,35 +36,38 @@ import com.google.common.base.Predicate;
|
|||
*
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
public class SshDaemonIsRunning implements Predicate<IMachine> {
|
||||
public class SshAvailable implements Predicate<String> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final ComputeServiceContext context;
|
||||
private final String nodeId;
|
||||
|
||||
public SshDaemonIsRunning(ComputeServiceContext context, String nodeId) {
|
||||
public SshAvailable(ComputeServiceContext context) {
|
||||
this.context = context;
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(@Nullable IMachine machine) {
|
||||
boolean sshDeamonIsRunning = false;
|
||||
public boolean apply(@Nullable String nodeId) {
|
||||
boolean sshDaemonIsRunning = false;
|
||||
try {
|
||||
if (context.getComputeService()
|
||||
.runScriptOnNode(nodeId, "id", wrapInInitScript(false))
|
||||
.runScriptOnNode(nodeId, "id", wrapInInitScript(false).runAsRoot(false))
|
||||
.getExitCode() == 0) {
|
||||
logger.debug("Got response from ssh daemon.");
|
||||
sshDeamonIsRunning = true;
|
||||
logger.debug("Got response from ssh daemon running on %s", nodeId);
|
||||
sshDaemonIsRunning = true;
|
||||
}
|
||||
} catch (SshException e) {
|
||||
logger.debug("No response from ssh daemon...");
|
||||
propagate(e);
|
||||
logger.debug("No response from ssh daemon running on %s", nodeId);
|
||||
return sshDaemonIsRunning;
|
||||
}
|
||||
return sshDeamonIsRunning;
|
||||
return sshDaemonIsRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SSH Daemon is available";
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,9 @@ package org.jclouds.virtualbox.predicates;
|
|||
|
||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||
import static org.jclouds.virtualbox.util.MachineUtils.applyForMachine;
|
||||
import static org.jclouds.virtualbox.util.MachineUtils.lockSessionOnMachineAndApply;
|
||||
import static org.virtualbox_4_1.LockType.Shared;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -16,12 +19,15 @@ import org.jclouds.virtualbox.functions.IsoToIMachine;
|
|||
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
|
||||
public class SshDaemonIsRunningLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
||||
private boolean forceOverwrite = true;
|
||||
private String vmId = "jclouds-image-iso-1";
|
||||
|
@ -43,13 +49,23 @@ public class SshDaemonIsRunningLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
hostId, "localhost", guestId, "localhost", new Credentials("toor",
|
||||
"password"));
|
||||
|
||||
IMachine nodeWithSshDaemonRunning = getNodeWithSshDaemonRunning(manager,
|
||||
localHostContext);
|
||||
getNodeWithSshDaemonRunning(manager, localHostContext);
|
||||
ensureMachineIsLaunched(vmName);
|
||||
RetryablePredicate<IMachine> predicate = new RetryablePredicate<IMachine>(
|
||||
new SshDaemonIsRunning(localHostContext, guestId), 5, 1,
|
||||
RetryablePredicate<String> predicate = new RetryablePredicate<String>(
|
||||
new SshAvailable(localHostContext), 5, 1,
|
||||
TimeUnit.SECONDS);
|
||||
predicate.apply(nodeWithSshDaemonRunning);
|
||||
assertTrue(predicate.apply(guestId));
|
||||
|
||||
lockSessionOnMachineAndApply(manager, Shared, vmName, new Function<ISession, Void>() {
|
||||
|
||||
@Override
|
||||
public Void apply(ISession session) {
|
||||
IProgress powerDownProgress = session.getConsole().powerDown();
|
||||
powerDownProgress.waitForCompletion(-1);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private IMachine getNodeWithSshDaemonRunning(VirtualBoxManager manager,
|
Loading…
Reference in New Issue