Thomas Vachuska

Improved STC to show commands being executed.

Enhanced the net-smoke test scenario.

Change-Id: Idc828a6a4f18a02db1723a58a6020c4f07b8f3f1
......@@ -17,6 +17,7 @@
<!-- TODO: parametrize this via recipes -->
<group name="Net-Setup">
<step name="Push-Topos" exec="onos-push-topos ${OCN}"/>
<step name="Stop-Mininet-If-Needed" env="~" exec="onos-mininet stop"/>
<step name="Install-Apps"
exec="onos ${OC1} app activate org.onosproject.openflow org.onosproject.proxyarp org.onosproject.fwd"/>
......@@ -30,11 +31,11 @@
exec="onos-check-summary ${OC1} [0-9]* 0 0 0"/>
<step name="Start-Mininet"
requires="Install-Apps,Initial-Summary-Check,Push-Topos"
requires="Install-Apps,Initial-Summary-Check,Push-Topos,Stop-Mininet-If-Needed"
exec="onos-mininet start topos/topo att-onos.py ${ONOS_INSTANCES}"/>
<step name="Wait-For-Mininet" requires="Start-Mininet"
exec="onos-mininet wait 15"/>
exec="onos-mininet wait 20"/>
<step name="Check-Summary" requires="Wait-For-Mininet"
exec="onos-check-summary ${OC1} [0-9]* 25 140 0"/>
......
......@@ -21,10 +21,10 @@
<dependency name="Reactive-Forwarding.Net-Pingall" requires="Net-Setup"/>
<import file="${ONOS_SCENARIOS}/net-link-down-up.xml" namespace="Reactive-Forwarding"/>
<dependency name="Reactive-Forwarding.Net-Link-Down-Up" requires="~Reactive-Forwarding.Net-Pingall"/>
<dependency name="Reactive-Forwarding.Net-Link-Down-Up" requires="Net-Setup,~Reactive-Forwarding.Net-Pingall"/>
<import file="${ONOS_SCENARIOS}/net-host-intent.xml"/>
<dependency name="Host-Intent-Connectivity" requires="~Reactive-Forwarding.Net-Link-Down-Up"/>
<dependency name="Host-Intent-Connectivity" requires="Net-Setup,~Reactive-Forwarding.Net-Link-Down-Up"/>
<import file="${ONOS_SCENARIOS}/net-teardown.xml"/>
<dependency name="Net-Teardown" requires="~Host-Intent-Connectivity"/>
......
......@@ -425,7 +425,7 @@ public class Compiler {
last = end + 1;
}
sb.append(pString.substring(last));
return sb.toString();
return sb.toString().replace('\n', ' ').replace('\r', ' ');
}
/**
......
......@@ -166,7 +166,7 @@ public final class Main {
// Processes the scenario 'list' command.
private void processList() {
coordinator.getRecords()
.forEach(event -> logStatus(event.time(), event.name(), event.status()));
.forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command()));
}
// Processes the scenario 'run' command for range of steps.
......@@ -188,12 +188,12 @@ public final class Main {
private static class Listener implements StepProcessListener {
@Override
public void onStart(Step step) {
logStatus(currentTimeMillis(), step.name(), IN_PROGRESS);
logStatus(currentTimeMillis(), step.name(), IN_PROGRESS, step.command());
}
@Override
public void onCompletion(Step step, Status status) {
logStatus(currentTimeMillis(), step.name(), status);
logStatus(currentTimeMillis(), step.name(), status, null);
}
@Override
......@@ -202,9 +202,13 @@ public final class Main {
}
// Logs the step status.
private static void logStatus(long time, String name, Status status) {
private static void logStatus(long time, String name, Status status, String cmd) {
if (cmd != null) {
print("%s %s%s %s%s -- %s", time(time), color(status), name, action(status), color(null), cmd);
} else {
print("%s %s%s %s%s", time(time), color(status), name, action(status), color(null));
}
}
// Produces a description of event using the specified step status.
private static String action(Status status) {
......
......@@ -109,7 +109,7 @@ class ScenarioStore {
* @param step test step or group
*/
synchronized void markStarted(Step step) {
add(new StepEvent(step.name(), IN_PROGRESS));
add(new StepEvent(step.name(), IN_PROGRESS, step.command()));
save();
}
......@@ -120,7 +120,7 @@ class ScenarioStore {
* @param status new step status
*/
synchronized void markComplete(Step step, Status status) {
add(new StepEvent(step.name(), status));
add(new StepEvent(step.name(), status, null));
save();
}
......
......@@ -18,15 +18,19 @@ package org.onlab.stc;
import org.onlab.stc.Coordinator.Status;
import static java.lang.Long.parseLong;
import static org.onlab.stc.Coordinator.Status.valueOf;
/**
* Represents an event of execution of a scenario step or group.
*/
public class StepEvent {
private static final String SEP = "~";
private final String name;
private final long time;
private final Status status;
private final String command;
/**
* Creates a new step record.
......@@ -34,11 +38,13 @@ public class StepEvent {
* @param name test step or group name
* @param time time in millis since start of epoch
* @param status step completion status
* @param command step command
*/
public StepEvent(String name, long time, Status status) {
public StepEvent(String name, long time, Status status, String command) {
this.name = name;
this.time = time;
this.status = status;
this.command = command;
}
/**
......@@ -46,9 +52,10 @@ public class StepEvent {
*
* @param name test step or group name
* @param status status
* @param command step command
*/
public StepEvent(String name, Status status) {
this(name, System.currentTimeMillis(), status);
public StepEvent(String name, Status status, String command) {
this(name, System.currentTimeMillis(), status, command);
}
/**
......@@ -78,10 +85,19 @@ public class StepEvent {
return status;
}
/**
* Returns the step command.
*
* @return step command
*/
public String command() {
return command;
}
@Override
public String toString() {
return name + ":" + time + ":" + status;
return name + SEP + time + SEP + status + SEP + command;
}
/**
......@@ -91,7 +107,8 @@ public class StepEvent {
* @return step record
*/
public static StepEvent fromString(String string) {
String[] fields = string.split(":");
return new StepEvent(fields[0], parseLong(fields[1]), Status.valueOf(fields[2]));
String[] fields = string.split("~");
return new StepEvent(fields[0], parseLong(fields[1]), valueOf(fields[2]),
fields[3].equals("null") ? null : fields[3]);
}
}
......
......@@ -17,8 +17,8 @@ package org.onlab.stc;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onlab.util.Tools;
import java.io.FileNotFoundException;
import java.io.IOException;
import static org.onlab.stc.CompilerTest.getStream;
......@@ -36,23 +36,26 @@ public class CoordinatorTest {
@BeforeClass
public static void setUpClass() throws IOException {
CompilerTest.setUpClass();
Tools.removeDirectory(StepProcessorTest.DIR);
StepProcessor.launcher = "true ";
}
@Test
public void simple() throws FileNotFoundException, InterruptedException {
public void simple() throws IOException, InterruptedException {
executeTest("simple-scenario.xml");
}
@Test
public void complex() throws FileNotFoundException, InterruptedException {
public void complex() throws IOException, InterruptedException {
executeTest("scenario.xml");
}
private void executeTest(String name) throws FileNotFoundException, InterruptedException {
private void executeTest(String name) throws IOException, InterruptedException {
Scenario scenario = loadScenario(getStream(name));
Compiler compiler = new Compiler(scenario);
compiler.compile();
Tools.removeDirectory(compiler.logDir());
coordinator = new Coordinator(scenario, compiler.processFlow(), compiler.logDir());
coordinator.addListener(listener);
coordinator.reset();
......
......@@ -32,7 +32,7 @@ import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
*/
public class StepProcessorTest {
private static final File DIR = new File("/tmp/stc/foo");
static final File DIR = new File("/tmp/stc/foo");
private final Listener delegate = new Listener();
......