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 {
public JsonNode flowTest(Optional<JsonNode> params) {
int flowsPerDevice = 1000;
int neighbours = 0;
boolean remove = true;
if (params.isPresent()) {
flowsPerDevice = params.get().get("flowsPerDevice").asInt();
neighbours = params.get().get("neighbours").asInt();
remove = params.get().get("remove").asBoolean();
}
Future<JsonNode> future = worker.submit(new FlowTest(flowsPerDevice, neighbours));
Future<JsonNode> future = worker.submit(new FlowTest(flowsPerDevice, neighbours, remove));
try {
return future.get(10, TimeUnit.SECONDS);
......@@ -496,12 +498,14 @@ public class DemoInstaller implements DemoAPI {
private class FlowTest implements Callable<JsonNode> {
private final int flowPerDevice;
private final int neighbours;
private final boolean remove;
private FlowRuleOperations.Builder adds;
private FlowRuleOperations.Builder removes;
public FlowTest(int flowsPerDevice, int neighbours) {
public FlowTest(int flowsPerDevice, int neighbours, boolean remove) {
this.flowPerDevice = flowsPerDevice;
this.neighbours = neighbours;
this.remove = remove;
prepareInstallation();
}
......@@ -574,7 +578,9 @@ public class DemoInstaller implements DemoAPI {
}));
latch.await(10, TimeUnit.SECONDS);
if (this.remove) {
flowService.apply(removes.build());
}
return node;
}
}
......
......@@ -7,11 +7,11 @@ def run(url, request):
r = requests.post(url, data)
return r
def runTasks(flowPerDevice, neighbours, url, servers, doJson):
def runTasks(flowPerDevice, neighbours, url, servers, doJson, remove):
# We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
# Start the load operations and mark each future with its URL
request = { "flowsPerDevice" : flowPerDevice, "neighbours" : neighbours }
request = { "flowsPerDevice" : flowPerDevice, "neighbours" : neighbours, "remove" : remove }
future_to_url = {executor.submit(run, url % (server), request) for server in servers}
for f in concurrent.futures.as_completed(future_to_url):
try:
......@@ -34,10 +34,12 @@ if __name__ == "__main__":
default=0, type="int")
parser.add_option("-s", "--servers", dest="servers", help="List of servers to hit",
default=[], action="append")
parser.add_option("-r", "--remove", dest="remove", help="Do not remove flows after installation",
default=True, action="store_false")
parser.add_option("-j", "--json", dest="doJson", help="Print results in json",
default=False, action="store_true")
(options, args) = parser.parse_args()
if (len(options.servers) == 0):
options.servers.append("localhost")
runTasks(options.flows, options.neighs, options.url, options.servers, options.doJson)
runTasks(options.flows, options.neighs, options.url, options.servers, options.doJson, options.remove)
......