Update testtool arguments 82/95182/13
authorIllia <illia.ihushev@pantheon.tech>
Mon, 15 Feb 2021 21:19:41 +0000 (23:19 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 11 May 2021 18:27:20 +0000 (18:27 +0000)
1. Remove edit-content argument. Instead of using node config template
in form of file node config will be created, modified by corresponding
Java models and than converted to request body string with GSON.
2. Split auth argument to controller-auth-username,
controller-auth-password. Add default value(admin) for them.
3. Split controller-destination argument to controller-ip,
controller-port.

JIRA: NETCONF-758
Change-Id: Iccf19c9482727b88d3f21a85008d13f554a8da08
Signed-off-by: Illia <illia.ihushev@pantheon.tech>
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java

index 8a0595fde6038f4828ddb313ed6570b5f2c9f3be..4b1470a497697e54335e67326a8c2a2ea5fc09b1 100644 (file)
@@ -73,15 +73,14 @@ public class Execution implements Callable<Void> {
                     .setBody(payload.getPayload())
                     .setRequestTimeout(Integer.MAX_VALUE);
 
-            if (params.auth != null) {
-                requestBuilder.setRealm(new Realm.RealmBuilder()
-                        .setScheme(Realm.AuthScheme.BASIC)
-                        .setPrincipal(params.auth.get(0))
-                        .setPassword(params.auth.get(1))
-                        .setMethodName("POST")
-                        .setUsePreemptiveAuth(true)
-                        .build());
-            }
+            requestBuilder.setRealm(new Realm.RealmBuilder()
+                    .setScheme(Realm.AuthScheme.BASIC)
+                    .setPrincipal(params.controllerAuthUsername)
+                    .setPassword(params.controllerAuthPassword)
+                    .setMethodName("POST")
+                    .setUsePreemptiveAuth(true)
+                    .build());
+
             this.payloads.add(requestBuilder.build());
         }
     }
index 7c0744bbb441cb6ca343fa94c969f60149a6fbc8..e2d5a41bec040bfaa5f511abf9b44432b6d95c5e 100644 (file)
@@ -49,7 +49,8 @@ public final class Main {
                 LOG.error("Failed to start any simulated devices, exiting...");
                 System.exit(1);
             }
-            if (params.controllerDestination != null) {
+            //if ODL controller ip is not set NETCONF devices will be started, but not registered at the controller
+            if (params.controllerIp != null) {
                 final ArrayList<ArrayList<Execution.DestToPayload>> allThreadsPayloads = params
                     .getThreadsPayloads(openDevices);
                 final ArrayList<Execution> executions = new ArrayList<>();
index 22aa014bb2d426b4d9e853007695bdf7a6e863aa..f7eaa7e4d77a698ecaec7bd9f7044342cb391d06 100644 (file)
@@ -44,26 +44,27 @@ public class TesttoolParameters {
     private static final String HOST_KEY = "{HOST}";
     private static final String PORT_KEY = "{PORT}";
     private static final String TCP_ONLY = "{TCP_ONLY}";
-    private static final String ADDRESS_PORT = "{ADDRESS:PORT}";
-    private static final String DEST =
-        "http://{ADDRESS:PORT}/restconf/config/network-topology:network-topology/topology/topology-netconf/";
+    private static final String RESTCONF_NETCONF_TOPOLOGY_PATH_TEMPLATE =
+        "http://%s:%s/restconf/config/network-topology:network-topology/topology/topology-netconf/";
     private static final Pattern YANG_FILENAME_PATTERN = Pattern
         .compile("(?<name>.*)@(?<revision>\\d{4}-\\d{2}-\\d{2})\\.yang");
     private static final Pattern REVISION_DATE_PATTERN = Pattern.compile("revision\\s+\"?(\\d{4}-\\d{2}-\\d{2})\"?");
 
     private static final String RESOURCE = "/config-template.json";
-    @Arg(dest = "edit-content")
-    public File editContent;
     @Arg(dest = "async")
     public boolean async;
     @Arg(dest = "thread-amount")
     public int threadAmount;
     @Arg(dest = "throttle")
     public int throttle;
-    @Arg(dest = "auth")
-    public ArrayList<String> auth;
-    @Arg(dest = "controller-destination")
-    public String controllerDestination;
+    @Arg(dest = "controller-auth-username")
+    public String controllerAuthUsername;
+    @Arg(dest = "controller-auth-password")
+    public String controllerAuthPassword;
+    @Arg(dest = "controller-ip")
+    public String controllerIp;
+    @Arg(dest = "controller-port")
+    public Integer controllerPort;
     @Arg(dest = "schemas-dir")
     public File schemasDir;
     @Arg(dest = "devices-count")
@@ -94,7 +95,6 @@ public class TesttoolParameters {
     public File initialConfigXMLFile;
     @Arg(dest = "time-out")
     public long timeOut;
-    private InputStream stream;
     @Arg(dest = "ip")
     public String ip;
     @Arg(dest = "thread-pool-size")
@@ -130,18 +130,33 @@ public class TesttoolParameters {
                         + "with mutltiple threads this gets divided among all threads")
                 .dest("throttle");
 
-        parser.addArgument("--auth")
-                .nargs(2)
-                .help("Username and password for HTTP basic authentication in order username password.")
-                .dest("auth");
+        parser.addArgument("--controller-auth-username")
+                .type(String.class)
+                .setDefault("admin")
+                .help("Username for HTTP basic authentication to destination controller.")
+                .dest("controller-auth-username");
+
+        parser.addArgument("--controller-auth-password")
+                .type(String.class)
+                .setDefault("admin")
+                .help("Password for HTTP basic authentication to destination controller.")
+                .dest("controller-auth-password");
 
-        parser.addArgument("--controller-destination")
+        parser.addArgument("--controller-ip")
                 .type(String.class)
-                .help("Ip address and port of controller. Must be in following format <ip>:<port> "
-                        + "if available it will be used for spawning netconf connectors via topology configuration as "
-                        + "a part of URI. Example (http://<controller destination>/restconf/config/network-topology:network-topology/topology/topology-netconf/node/<node-id>)"
+                .help("Ip of controller if available it will be used for spawning netconf connectors via topology"
+                        + " configuration as a part of"
+                        + " URI(http://<controller-ip>:<controller-port>/restconf/config/...)"
+                        + " otherwise it will just start simulated devices and skip the execution of PUT requests")
+                .dest("controller-ip");
+
+        parser.addArgument("--controller-port")
+                .type(Integer.class)
+                .help("Port of controller if available it will be used for spawning netconf connectors via topology "
+                        + "configuration as a part of"
+                        + " URI(http://<controller-ip>:<controller-port>/restconf/config/...) "
                         + "otherwise it will just start simulated devices and skip the execution of PUT requests")
-                .dest("controller-destination");
+                .dest("controller-port");
 
         parser.addArgument("--device-count")
                 .type(Integer.class)
@@ -285,18 +300,14 @@ public class TesttoolParameters {
 
     @SuppressWarnings("checkstyle:regexpSinglelineJava")
     void validate() {
-        if (editContent == null) {
-            stream = TesttoolParameters.class.getResourceAsStream(RESOURCE);
+        if (controllerIp != null) {
+            //FIXME Ip validation
+            checkArgument(controllerPort != null, "Controller port is missing");
+            //FIXME Is there specific bound
+            checkArgument(controllerPort >= 0, "Controller port should be non-negative integer");
+            checkArgument(controllerPort < 65354, "Controller port should be less than 65354");
         } else {
-            checkArgument(!editContent.isDirectory(), "Edit content file is a dir");
-            checkArgument(editContent.canRead(), "Edit content file is unreadable");
-        }
-
-        if (controllerDestination != null) {
-            checkArgument(controllerDestination.contains(":"),
-                "Controller Destination needs to be in a following format <ip>:<port>");
-            final String[] parts = controllerDestination.split(Pattern.quote(":"));
-            checkArgument(Integer.parseInt(parts[1]) > 0, "Port =< 0");
+            checkArgument(controllerPort == null, "Controller ip is missing");
         }
 
         checkArgument(deviceCount > 0, "Device count has to be > 0");
@@ -356,13 +367,10 @@ public class TesttoolParameters {
     public ArrayList<ArrayList<Execution.DestToPayload>> getThreadsPayloads(final List<Integer> openDevices) {
         final String editContentString;
         try {
-            if (stream == null) {
-                editContentString = Files.readString(editContent.toPath());
-            } else {
-                editContentString = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
-            }
+            final InputStream stream = TesttoolParameters.class.getResourceAsStream(RESOURCE);
+            editContentString = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
         } catch (final IOException e) {
-            throw new IllegalArgumentException("Cannot read content of " + editContent, e);
+            throw new IllegalArgumentException("Cannot read content of " + RESOURCE, e);
         }
 
         int from;
@@ -377,17 +385,17 @@ public class TesttoolParameters {
             final int leftoverBatchedRequests = batchedRequests % threadAmount;
             final int leftoverRequests = openDevices.size() - batchedRequests * generateConfigBatchSize;
 
-            final StringBuilder destBuilder = new StringBuilder(DEST);
-            destBuilder.replace(destBuilder.indexOf(ADDRESS_PORT),
-                destBuilder.indexOf(ADDRESS_PORT) + ADDRESS_PORT.length(),
-                controllerDestination);
+            //FIXME Move this to validate() and rename it to init() or create init() and move there.
+            //FIXME Make it field.
+            final String restconfNetconfTopologyPath = String.format(RESTCONF_NETCONF_TOPOLOGY_PATH_TEMPLATE,
+                    controllerIp, controllerPort);
 
             for (int l = 0; l < threadAmount; l++) {
                 from = l * batchedRequests * batchedRequestsPerThread;
                 to = from + batchedRequests * batchedRequestsPerThread;
                 iterator = openDevices.subList(from, to).iterator();
                 allThreadsPayloads.add(createBatchedPayloads(batchedRequestsPerThread, iterator, editContentString,
-                    destBuilder.toString()));
+                        restconfNetconfTopologyPath));
             }
             ArrayList<Execution.DestToPayload> payloads = null;
             if (leftoverBatchedRequests > 0) {
@@ -395,7 +403,7 @@ public class TesttoolParameters {
                 to = from + batchedRequests * batchedRequestsPerThread;
                 iterator = openDevices.subList(from, to).iterator();
                 payloads = createBatchedPayloads(leftoverBatchedRequests, iterator, editContentString,
-                    destBuilder.toString());
+                        restconfNetconfTopologyPath);
             }
             String payload = "";
 
@@ -410,7 +418,7 @@ public class TesttoolParameters {
             if (leftoverRequests > 0 || leftoverBatchedRequests > 0) {
 
                 if (payloads != null) {
-                    payloads.add(new Execution.DestToPayload(destBuilder.toString(), payload));
+                    payloads.add(new Execution.DestToPayload(restconfNetconfTopologyPath, payload));
                 }
                 allThreadsPayloads.add(payloads);
             }
@@ -463,11 +471,12 @@ public class TesttoolParameters {
         final ArrayList<Execution.DestToPayload> payloads = new ArrayList<>();
 
         while (openDevices.hasNext()) {
-            final StringBuilder destBuilder = new StringBuilder(DEST);
-            destBuilder.replace(destBuilder.indexOf(ADDRESS_PORT),
-                destBuilder.indexOf(ADDRESS_PORT) + ADDRESS_PORT.length(), controllerDestination);
+            //FIXME Move this to validate() and rename it to init() or create init() and move there.
+            //FIXME Make it field.
+            final String restconfNetconfTopologyPath = String.format(RESTCONF_NETCONF_TOPOLOGY_PATH_TEMPLATE,
+                    controllerIp, controllerPort);
             payloads.add(new Execution.DestToPayload(
-                destBuilder.toString(), prepareMessage(openDevices.next(), editContentString)));
+                    restconfNetconfTopologyPath, prepareMessage(openDevices.next(), editContentString)));
         }
         return payloads;
     }