Add AuthHandler to stresstool 87/19687/7
authorTomas Cere <tcere@cisco.com>
Tue, 5 May 2015 09:21:18 +0000 (11:21 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 15 May 2015 08:17:10 +0000 (08:17 +0000)
Stop bundling BouncyCastle into strestool uber-jar,
JCE certificate gets wiped this way and Oracle JDK refuses to use it.
Instead export them into target/lib dir and setup stresstool jar classpath to point to this directory.

Change-Id: I3c7ab9ea0f5faba2f02f4e0cfa21adda6bce2e4e
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/netconf-testtool/pom.xml
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/stress/Parameters.java
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/stress/StressClient.java
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/client/stress/StressClientCallable.java

index 0d98fca..30b1cbf 100644 (file)
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>stress-client dependency copy</id>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.bouncycastle</groupId>
+                                    <artifactId>bcpkix-jdk15on</artifactId>
+                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                                    <overWrite>true</overWrite>
+                                    <destFileName>bcpkix-jdk15on.jar</destFileName>
+                                </artifactItem>
+                                <artifactItem>
+                                    <groupId>org.bouncycastle</groupId>
+                                    <artifactId>bcprov-jdk15on</artifactId>
+                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                                    <overWrite>true</overWrite>
+                                    <destFileName>bcprov-jdk15on.jar</destFileName>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
                                     </excludes>
                                 </filter>
                             </filters>
+                            <artifactSet>
+                                <excludes>
+                                    <exclude>org.bouncycastle:*</exclude>
+                                </excludes>
+                            </artifactSet>
                             <transformers>
                                 <transformer
                                         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-                                    <mainClass>org.opendaylight.controller.netconf.test.tool.client.stress.StressClient</mainClass>
+                                    <manifestEntries>
+                                        <Main-Class>org.opendaylight.controller.netconf.test.tool.client.stress.StressClient</Main-Class>
+                                        <Class-Path>. lib lib/bcprov-jdk15on.jar lib/bcpkix-jdk15on.jar</Class-Path>
+                                    </manifestEntries>
                                 </transformer>
                             </transformers>
                             <shadedArtifactAttached>true</shadedArtifactAttached>
index 8a9a915..84766ad 100644 (file)
@@ -49,6 +49,12 @@ public class Parameters {
     @Arg(dest = "ssh")
     public boolean ssh;
 
+    @Arg(dest = "username")
+    public String username;
+
+    @Arg(dest = "password")
+    public String password;
+
     @Arg(dest = "msg-timeout")
     public long msgTimeout;
 
@@ -128,6 +134,16 @@ public class Parameters {
                 .setDefault(false)
                 .dest("ssh");
 
+        parser.addArgument("--username")
+                .type(String.class)
+                .setDefault("admin")
+                .dest("username");
+
+        parser.addArgument("--password")
+                .type(String.class)
+                .setDefault("admin")
+                .dest("password");
+
         parser.addArgument("--tcp-header")
                 .type(String.class)
                 .required(false)
index 2916ec5..e03de59 100644 (file)
@@ -16,6 +16,8 @@ import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timer;
 import java.io.IOException;
+import java.security.Provider;
+import java.security.Security;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -26,8 +28,10 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import net.sourceforge.argparse4j.inf.ArgumentParser;
 import net.sourceforge.argparse4j.inf.ArgumentParserException;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl;
+import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.controller.sal.connect.api.RemoteDevice;
 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator;
@@ -85,6 +89,7 @@ public final class StressClient {
     private static long macStart = 0xAABBCCDD0000L;
 
     public static void main(final String[] args) {
+
         final Parameters params = parseArgs(args, Parameters.getParser());
         params.validate();
 
@@ -169,6 +174,10 @@ public final class StressClient {
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.warn("Unable to close executor properly", e);
         }
+        //stop the underlying ssh thread that gets spawned if we use ssh
+        if (params.ssh) {
+            AsyncSshHandler.DEFAULT_CLIENT.stop();
+        }
     }
 
     static NetconfMessage prepareMessage(final int id, final String editContentString) {
index a4c5c57..a37fcd7 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl;
 import org.opendaylight.controller.netconf.client.NetconfClientSession;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder;
+import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.controller.sal.connect.api.RemoteDevice;
 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator;
@@ -92,6 +93,7 @@ public class StressClientCallable implements Callable<Boolean>{
             });
         }
         netconfClientConfigurationBuilder.withProtocol(params.ssh ? NetconfClientConfiguration.NetconfClientProtocol.SSH : NetconfClientConfiguration.NetconfClientProtocol.TCP);
+        netconfClientConfigurationBuilder.withAuthHandler(new LoginPassword(params.username, params.password));
         netconfClientConfigurationBuilder.withConnectionTimeoutMillis(20000L);
         netconfClientConfigurationBuilder.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
         return netconfClientConfigurationBuilder.build();

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.