From 69d493b44706a324e96ecdffeacb8f8c61a17f1e Mon Sep 17 00:00:00 2001 From: Illia Date: Mon, 15 Feb 2021 23:19:41 +0200 Subject: [PATCH] Update testtool arguments 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 --- .../netconf/test/tool/Execution.java | 17 ++- .../opendaylight/netconf/test/tool/Main.java | 3 +- .../netconf/test/tool/TesttoolParameters.java | 103 ++++++++++-------- 3 files changed, 66 insertions(+), 57 deletions(-) diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java index 8a0595fde6..4b1470a497 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java @@ -73,15 +73,14 @@ public class Execution implements Callable { .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()); } } diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java index 7c0744bbb4..e2d5a41bec 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java @@ -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> allThreadsPayloads = params .getThreadsPayloads(openDevices); final ArrayList executions = new ArrayList<>(); diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java index 22aa014bb2..f7eaa7e4d7 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java @@ -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("(?.*)@(?\\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 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 : " - + "if available it will be used for spawning netconf connectors via topology configuration as " - + "a part of URI. Example (http:///restconf/config/network-topology:network-topology/topology/topology-netconf/node/)" + .help("Ip of controller if available it will be used for spawning netconf connectors via topology" + + " configuration as a part of" + + " URI(http://:/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://:/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 :"); - 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> getThreadsPayloads(final List 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 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 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; } -- 2.36.6