Add the ability to edit running in stress-client 65/25565/6
authorTomas Cere <tcere@cisco.com>
Fri, 21 Aug 2015 10:47:41 +0000 (12:47 +0200)
committerTomas Cere <tcere@cisco.com>
Wed, 16 Sep 2015 07:37:45 +0000 (07:37 +0000)
Change-Id: I1aa1c3bbcae86af328ffc85815ceb48748ab9201
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/AsyncExecutionStrategy.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/Parameters.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClient.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/SyncExecutionStrategy.java

index f1718228fdf28d346c6d7ae4a525e2a24bae8496..c39fd46e5d9544cafd1308451b73b17415137f0f 100644 (file)
@@ -77,7 +77,9 @@ class AsyncExecutionStrategy implements ExecutionStrategy {
             }
             batchI++;
             LOG.info("Batch {} with size {} sent. Committing", batchI, editBatch);
-            futures.add(sessionListener.sendRequest(StressClient.COMMIT_MSG, StressClient.COMMIT_QNAME));
+            if (params.candidateDatastore) {
+                futures.add(sessionListener.sendRequest(StressClient.COMMIT_MSG, StressClient.COMMIT_QNAME));
+            }
         }
 
         LOG.info("All batches sent. Waiting for responses");
@@ -98,6 +100,7 @@ class AsyncExecutionStrategy implements ExecutionStrategy {
             }
         }
 
-        Preconditions.checkState(responseCounter.get() == editAmount + editBatches.size(), "Not all responses were received, only %s from %s", responseCounter.get(), params.editCount + editBatches.size());
+        Preconditions.checkState(responseCounter.get() == editAmount + (params.candidateDatastore ? editBatches.size() : 0),
+                "Not all responses were received, only %s from %s", responseCounter.get(), params.editCount + editBatches.size());
     }
 }
index b524a8c48cfff2d11fd499ea40d2fdc72df4021e..c7e3dbfdab5c362d3920c8130ca861fd69d0e0f2 100644 (file)
@@ -34,6 +34,9 @@ public class Parameters {
     @Arg(dest = "edit-batch-size")
     public int editBatchSize;
 
+    @Arg(dest = "candidate-datastore")
+    public boolean candidateDatastore;
+
     @Arg(dest = "debug")
     public boolean debug;
 
@@ -100,9 +103,15 @@ public class Parameters {
                 .type(Integer.class)
                 .required(false)
                 .setDefault(-1)
-                .type(Integer.class)
                 .dest("edit-batch-size");
 
+        parser.addArgument("--candidate-datastore")
+                .type(Boolean.class)
+                .required(false)
+                .setDefault(true)
+                .help("Edit candidate or running datastore. Defaults to candidate.")
+                .dest("candidate-datastore");
+
         parser.addArgument("--debug")
                 .type(Boolean.class)
                 .setDefault(false)
index e6aed331e94e9bee9bed9cd9e487419fb7dcd555..11e8641fd9ae5531644a4aae238c0a61794507dd 100644 (file)
@@ -62,11 +62,12 @@ public final class StressClient {
     }
 
     static final QName EDIT_QNAME = QName.create(EditConfigInput.QNAME, "edit-config");
-    static final org.w3c.dom.Document editBlueprint;
+    static final org.w3c.dom.Document editCandidateBlueprint;
+    static final org.w3c.dom.Document editRunningBlueprint;
 
     static {
         try {
-            editBlueprint = XmlUtil.readXmlToDocument(
+            editCandidateBlueprint = XmlUtil.readXmlToDocument(
                     "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
                             "    <edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
                             "        <target>\n" +
@@ -76,6 +77,17 @@ public final class StressClient {
                             "        <config/>\n" +
                             "    </edit-config>\n" +
                             "</rpc>");
+
+            editRunningBlueprint = XmlUtil.readXmlToDocument(
+                    "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+                            "    <edit-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+                            "        <target>\n" +
+                            "            <running/>\n" +
+                            "        </target>\n" +
+                            "        <default-operation>none</default-operation>" +
+                            "        <config/>\n" +
+                            "    </edit-config>\n" +
+                            "</rpc>");
         } catch (SAXException | IOException e) {
             throw new ExceptionInInitializerError(e);
         }
@@ -86,9 +98,11 @@ public final class StressClient {
 
     private static long macStart = 0xAABBCCDD0000L;
 
+    private static Parameters params;
+
     public static void main(final String[] args) {
 
-        final Parameters params = parseArgs(args, Parameters.getParser());
+        params = parseArgs(args, Parameters.getParser());
         params.validate();
 
         final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
@@ -179,7 +193,7 @@ public final class StressClient {
     }
 
     static NetconfMessage prepareMessage(final int id, final String editContentString) {
-        final Document msg = XmlUtil.createDocumentCopy(editBlueprint);
+        final Document msg = XmlUtil.createDocumentCopy(params.candidateDatastore ? editCandidateBlueprint : editRunningBlueprint);
         msg.getDocumentElement().setAttribute("message-id", Integer.toString(id));
         final NetconfMessage netconfMessage = new NetconfMessage(msg);
 
index 6f559db83fb34a750b794199a69ef4bcec44339f..6830464db3b81ddb725aa4b89fef466d6bd80593 100644 (file)
@@ -80,11 +80,14 @@ class SyncExecutionStrategy implements ExecutionStrategy {
             LOG.info("Batch {} with size {} sent. Committing", batchI, editBatch);
 
             // Commit batch sync
-            waitForResponse(responseCounter,
-                    sessionListener.sendRequest(StressClient.COMMIT_MSG, StressClient.COMMIT_QNAME));
+            if (params.candidateDatastore) {
+                waitForResponse(responseCounter,
+                        sessionListener.sendRequest(StressClient.COMMIT_MSG, StressClient.COMMIT_QNAME));
+            }
         }
 
-        Preconditions.checkState(responseCounter.get() == editAmount + editBatches.size(), "Not all responses were received, only %s from %s", responseCounter.get(), params.editCount + editBatches.size());
+        Preconditions.checkState(responseCounter.get() == editAmount + (params.candidateDatastore ? editBatches.size() : 0),
+                "Not all responses were received, only %s from %s", responseCounter.get(), params.editCount + editBatches.size());
     }
 
     private void waitForResponse(AtomicInteger responseCounter, final ListenableFuture<RpcResult<NetconfMessage>> netconfMessageFuture) {