diff --git a/drivers/sshj/pom.xml b/drivers/sshj/pom.xml index 8e1e3bce50..9bed134854 100644 --- a/drivers/sshj/pom.xml +++ b/drivers/sshj/pom.xml @@ -44,6 +44,14 @@ + + localhost + 22 + + + + + org.jclouds @@ -60,6 +68,12 @@ jclouds-slf4j ${project.version} + + ch.qos.logback + logback-classic + 0.9.30 + test + org.jclouds.driver jclouds-bouncycastle @@ -99,4 +113,65 @@ + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + none + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + file.encoding + UTF-8 + + + test.ssh.host + ${test.ssh.host} + + + test.ssh.port + ${test.ssh.port} + + + test.ssh.username + ${test.ssh.username} + + + test.ssh.keyfile + ${test.ssh.keyfile} + + + test.ssh.password + ${test.ssh.password} + + + + + + + + + + diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java index e8b3a1cebc..6e6aff1275 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java @@ -24,11 +24,13 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.InetAddress; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.domain.Credentials; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; @@ -44,7 +46,7 @@ import com.google.inject.Injector; * * @author Adrian Cole */ -@Test(groups = "live") +@Test(groups = "live", testName = "SshjSshClientLiveTest") public class SshjSshClientLiveTest { protected static final String sshHost = System.getProperty("test.ssh.host", "localhost"); protected static final String sshPort = System.getProperty("test.ssh.port", "22"); @@ -57,8 +59,8 @@ public class SshjSshClientLiveTest { public SshClient setupClient() throws NumberFormatException, FileNotFoundException, IOException { int port = Integer.parseInt(sshPort); if (sshUser == null - || ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile.trim().equals(""))) - || sshUser.trim().equals("")) { + || ((sshPass == null || sshPass.trim().equals("")) && (sshKeyFile == null || sshKeyFile.trim() + .equals(""))) || sshUser.trim().equals("")) { System.err.println("ssh credentials not present. Tests will be lame"); return new SshClient() { @@ -106,12 +108,12 @@ public class SshjSshClientLiveTest { }; } else { - Injector i = Guice.createInjector(new SshjSshClientModule()); + Injector i = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection; if (sshKeyFile != null && !sshKeyFile.trim().equals("")) { - connection = factory.create(new IPSocket(sshHost, port), - new Credentials(sshUser, Strings2.toStringAndClose(new FileInputStream(sshKeyFile)))); + connection = factory.create(new IPSocket(sshHost, port), new Credentials(sshUser, Strings2 + .toStringAndClose(new FileInputStream(sshKeyFile)))); } else { connection = factory.create(new IPSocket(sshHost, port), new Credentials(sshUser, sshPass)); } @@ -139,7 +141,8 @@ public class SshjSshClientLiveTest { public void testExecHostname() throws IOException { ExecResponse response = setupClient().exec("hostname"); assertEquals(response.getError(), ""); - assertEquals(response.getOutput().trim(), sshHost); + assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName() + : sshHost); } } diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java index 648a0ad601..836d3c6d80 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java @@ -18,8 +18,10 @@ */ package org.jclouds.sshj; +import static com.google.inject.name.Names.bindProperties; + import java.io.IOException; -import java.net.UnknownHostException; +import java.util.Properties; import net.schmizz.sshj.common.SSHException; import net.schmizz.sshj.connection.ConnectionException; @@ -27,6 +29,7 @@ import net.schmizz.sshj.transport.TransportException; import net.schmizz.sshj.userauth.UserAuthException; import org.jclouds.domain.Credentials; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.rest.AuthorizationException; import org.jclouds.ssh.SshClient; @@ -34,6 +37,7 @@ import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; @@ -48,15 +52,26 @@ public class SshjSshClientTest { protected SshjSshClient ssh; @BeforeTest - public void setupSsh() throws UnknownHostException { + public void setupSsh() { ssh = createClient(); } - protected SshjSshClient createClient() throws UnknownHostException { - Injector i = Guice.createInjector(module()); + protected SshjSshClient createClient() { + return createClient(new Properties()); + } + + protected SshjSshClient createClient(final Properties props) { + Injector i = Guice.createInjector(module(), new AbstractModule() { + + @Override + protected void configure() { + bindProperties(binder(), props); + } + + }, new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshjSshClient ssh = SshjSshClient.class.cast(factory.create(new IPSocket("localhost", 22), new Credentials( - "username", "password"))); + "username", "password"))); return ssh; } @@ -75,13 +90,20 @@ public class SshjSshClientTest { assert !ssh.shouldRetry(new IOException("channel %s is not open", new NullPointerException())); } - public void testOnlyRetryAuthWhenSet() throws UnknownHostException { + public void testOnlyRetryAuthWhenSet() { SshjSshClient ssh1 = createClient(); assert !ssh1.shouldRetry(new AuthorizationException("problem", null)); ssh1.retryAuth = true; assert ssh1.shouldRetry(new AuthorizationException("problem", null)); } + public void testOnlyRetryAuthWhenSetViaProperties() { + Properties props = new Properties(); + props.setProperty("jclouds.ssh.retry-auth", "true"); + SshjSshClient ssh1 = createClient(props); + assert ssh1.shouldRetry(new AuthorizationException("problem", null)); + } + public void testExceptionMessagesRetry() { assert !ssh.shouldRetry(new SSHException("")); assert !ssh.shouldRetry(new NullPointerException((String) null)); @@ -89,10 +111,11 @@ public class SshjSshClientTest { public void testCausalChainHasMessageContaining() { assert ssh.causalChainHasMessageContaining( - new SSHException("Session.connect: java.io.IOException: End of IO Stream Read")).apply( - " End of IO Stream Read"); + new SSHException("Session.connect: java.io.IOException: End of IO Stream Read")).apply( + " End of IO Stream Read"); assert ssh.causalChainHasMessageContaining( - new SSHException("Session.connect: java.net.SocketException: Connection reset")).apply("java.net.Socket"); + new SSHException("Session.connect: java.net.SocketException: Connection reset")) + .apply("java.net.Socket"); assert !ssh.causalChainHasMessageContaining(new NullPointerException()).apply(" End of IO Stream Read"); } } diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java index 3e073eee63..754b524f55 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java @@ -18,9 +18,8 @@ */ package org.jclouds.sshj.config; -import java.net.UnknownHostException; - import org.jclouds.domain.Credentials; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.SshjSshClient; @@ -37,9 +36,9 @@ import com.google.inject.Injector; @Test public class SshjSshClientModuleTest { - public void testConfigureBindsClient() throws UnknownHostException { + public void testConfigureBindsClient() { - Injector i = Guice.createInjector(new SshjSshClientModule()); + Injector i = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection = factory.create(new IPSocket("localhost", 22), new Credentials("username", "password")); assert connection instanceof SshjSshClient; diff --git a/drivers/sshj/src/test/resources/logback.xml b/drivers/sshj/src/test/resources/logback.xml new file mode 100644 index 0000000000..d7a1f1accc --- /dev/null +++ b/drivers/sshj/src/test/resources/logback.xml @@ -0,0 +1,15 @@ + + + + target/test-data/jclouds-ssh.log + true + + %-4relative [%thread] %-5level %logger{35} - %msg%n + + + + + + + +