alshabib
Committed by Gerrit Code Review

option to not remove flows in flow-tester.py

Change-Id: I6d0be801b628cd6cf3678d5c846fb99cabf41ca3
...@@ -148,12 +148,14 @@ public class DemoInstaller implements DemoAPI { ...@@ -148,12 +148,14 @@ public class DemoInstaller implements DemoAPI {
148 public JsonNode flowTest(Optional<JsonNode> params) { 148 public JsonNode flowTest(Optional<JsonNode> params) {
149 int flowsPerDevice = 1000; 149 int flowsPerDevice = 1000;
150 int neighbours = 0; 150 int neighbours = 0;
151 + boolean remove = true;
151 if (params.isPresent()) { 152 if (params.isPresent()) {
152 flowsPerDevice = params.get().get("flowsPerDevice").asInt(); 153 flowsPerDevice = params.get().get("flowsPerDevice").asInt();
153 neighbours = params.get().get("neighbours").asInt(); 154 neighbours = params.get().get("neighbours").asInt();
155 + remove = params.get().get("remove").asBoolean();
154 } 156 }
155 157
156 - Future<JsonNode> future = worker.submit(new FlowTest(flowsPerDevice, neighbours)); 158 + Future<JsonNode> future = worker.submit(new FlowTest(flowsPerDevice, neighbours, remove));
157 159
158 try { 160 try {
159 return future.get(10, TimeUnit.SECONDS); 161 return future.get(10, TimeUnit.SECONDS);
...@@ -496,12 +498,14 @@ public class DemoInstaller implements DemoAPI { ...@@ -496,12 +498,14 @@ public class DemoInstaller implements DemoAPI {
496 private class FlowTest implements Callable<JsonNode> { 498 private class FlowTest implements Callable<JsonNode> {
497 private final int flowPerDevice; 499 private final int flowPerDevice;
498 private final int neighbours; 500 private final int neighbours;
501 + private final boolean remove;
499 private FlowRuleOperations.Builder adds; 502 private FlowRuleOperations.Builder adds;
500 private FlowRuleOperations.Builder removes; 503 private FlowRuleOperations.Builder removes;
501 504
502 - public FlowTest(int flowsPerDevice, int neighbours) { 505 + public FlowTest(int flowsPerDevice, int neighbours, boolean remove) {
503 this.flowPerDevice = flowsPerDevice; 506 this.flowPerDevice = flowsPerDevice;
504 this.neighbours = neighbours; 507 this.neighbours = neighbours;
508 + this.remove = remove;
505 prepareInstallation(); 509 prepareInstallation();
506 } 510 }
507 511
...@@ -574,7 +578,9 @@ public class DemoInstaller implements DemoAPI { ...@@ -574,7 +578,9 @@ public class DemoInstaller implements DemoAPI {
574 })); 578 }));
575 579
576 latch.await(10, TimeUnit.SECONDS); 580 latch.await(10, TimeUnit.SECONDS);
581 + if (this.remove) {
577 flowService.apply(removes.build()); 582 flowService.apply(removes.build());
583 + }
578 return node; 584 return node;
579 } 585 }
580 } 586 }
......
...@@ -7,11 +7,11 @@ def run(url, request): ...@@ -7,11 +7,11 @@ def run(url, request):
7 r = requests.post(url, data) 7 r = requests.post(url, data)
8 return r 8 return r
9 9
10 -def runTasks(flowPerDevice, neighbours, url, servers, doJson): 10 +def runTasks(flowPerDevice, neighbours, url, servers, doJson, remove):
11 # We can use a with statement to ensure threads are cleaned up promptly 11 # We can use a with statement to ensure threads are cleaned up promptly
12 with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: 12 with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
13 # Start the load operations and mark each future with its URL 13 # Start the load operations and mark each future with its URL
14 - request = { "flowsPerDevice" : flowPerDevice, "neighbours" : neighbours } 14 + request = { "flowsPerDevice" : flowPerDevice, "neighbours" : neighbours, "remove" : remove }
15 future_to_url = {executor.submit(run, url % (server), request) for server in servers} 15 future_to_url = {executor.submit(run, url % (server), request) for server in servers}
16 for f in concurrent.futures.as_completed(future_to_url): 16 for f in concurrent.futures.as_completed(future_to_url):
17 try: 17 try:
...@@ -34,10 +34,12 @@ if __name__ == "__main__": ...@@ -34,10 +34,12 @@ if __name__ == "__main__":
34 default=0, type="int") 34 default=0, type="int")
35 parser.add_option("-s", "--servers", dest="servers", help="List of servers to hit", 35 parser.add_option("-s", "--servers", dest="servers", help="List of servers to hit",
36 default=[], action="append") 36 default=[], action="append")
37 + parser.add_option("-r", "--remove", dest="remove", help="Do not remove flows after installation",
38 + default=True, action="store_false")
37 parser.add_option("-j", "--json", dest="doJson", help="Print results in json", 39 parser.add_option("-j", "--json", dest="doJson", help="Print results in json",
38 default=False, action="store_true") 40 default=False, action="store_true")
39 41
40 (options, args) = parser.parse_args() 42 (options, args) = parser.parse_args()
41 if (len(options.servers) == 0): 43 if (len(options.servers) == 0):
42 options.servers.append("localhost") 44 options.servers.append("localhost")
43 - runTasks(options.flows, options.neighs, options.url, options.servers, options.doJson) 45 + runTasks(options.flows, options.neighs, options.url, options.servers, options.doJson, options.remove)
......