test cleanup

This commit is contained in:
Adrian Cole 2011-12-21 23:29:45 -08:00
parent cc147a6ec6
commit 70269a0091
1 changed files with 6 additions and 37 deletions

View File

@ -50,18 +50,14 @@ import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.compute.ComputeTestUtils; import org.jclouds.compute.ComputeTestUtils;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.annotations.Identity;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -146,8 +142,8 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
@Test @Test
public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException { public void testCreateNodeWithGroupEncodedIntoName() throws InterruptedException {
String group = prefix + "#foo"; String group = prefix + "-foo";
String name = group + "#node#" + new Random().nextInt(); String name = group + "-node-" + new Random().nextInt();
Template template = computeContext.getComputeService().templateBuilder().build(); Template template = computeContext.getComputeService().templateBuilder().build();
if (!client if (!client
@ -168,38 +164,11 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
String address = rule != null ? rule.getIPAddress() : vm.getNode().getIPAddress(); String address = rule != null ? rule.getIPAddress() : vm.getNode().getIPAddress();
loginCredentials = prioritizeCredentialsFromTemplate.apply(template, vm.getCredentials());
assert InetAddresses.isInetAddress(address) : vm; assert InetAddresses.isInetAddress(address) : vm;
IPSocket socket = new IPSocket(address, 22); IPSocket socket = new IPSocket(address, 22);
doConnectViaSsh(socket, prioritizeCredentialsFromTemplate.apply(template, vm.getCredentials())); checkSSH(socket);
}
protected void doConnectViaSsh(IPSocket socket, LoginCredentials creds) {
SshClient ssh = computeContext.utils().sshFactory().create(socket, creds);
try {
connectWithRetry(ssh, 5, 2000);
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();
}
}
private void connectWithRetry(SshClient ssh, int times, int delayInMilli) {
for (int i = 0; i < times; i++) {
try {
ssh.connect();
break;
} catch (SshException e) {
try {
Thread.sleep(delayInMilli);
} catch (InterruptedException e1) {
}
}
}
} }
@Test @Test