Thomas Vachuska

Adding ability to dump logs for failed steps.

Change-Id: Ib3cb6552018d45c0bb4066e15a6e9bc8f69e97e0
......@@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Implementations of OpenFlow extensions.
* Processing of Nicira extensions.
*/
package org.onosproject.driver.extensions;
......
......@@ -20,6 +20,7 @@ scenario=${1:-smoke}
# If stcColor is not set, we will enable color if this is an interactive session
[ -t 1 ] && interactive=true || interactive=false
[ -t 1 ] && notInteractive=false || notInteractive=true
# stc requires that ONOS_USE_SSH=true, but we will store the old value and reset it after
sshSet=$([ -z ${ONOS_USE_SSH+x} ]) && oldSSH=$ONOS_USE_SSH
......@@ -27,7 +28,8 @@ export ONOS_USE_SSH=true
# Run stc
[ -z "$stcDebug" ] && DEBUG_OPTS=""
stcColor=${stcColor:-$interactive} java $DEBUG_OPTS -jar $JAR $scenario "$@"
stcColor=${stcColor:-$interactive} stcDumpLogs=${stcDumpLogs:-$notInteractive} \
java $DEBUG_OPTS -jar $JAR $scenario "$@"
# Reset the old value of ONOS_USE_SSH
[ $sshSet ] && export ONOS_USE_SSH=oldSSH || unset ONOS_USE_SSH
......
......@@ -16,13 +16,16 @@
package org.onlab.stc;
import com.google.common.collect.ImmutableList;
import com.google.common.io.Files;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.util.log.Logger;
import org.onlab.stc.Coordinator.Status;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
......@@ -64,10 +67,12 @@ public final class Main {
private String runToPatterns = "";
private Coordinator coordinator;
private Compiler compiler;
private Monitor monitor;
private Listener delegate = new Listener();
private static boolean useColor = Objects.equals("true", System.getenv("stcColor"));
private static boolean dumpLogs = Objects.equals("true", System.getenv("stcDumpLogs"));
// usage: stc [<scenario-file>] [run]
// usage: stc [<scenario-file>] run [from <from-patterns>] [to <to-patterns>]]
......@@ -113,7 +118,7 @@ public final class Main {
Scenario scenario = Scenario.loadScenario(new FileInputStream(scenarioFile));
// Elaborate scenario
Compiler compiler = new Compiler(scenario);
compiler = new Compiler(scenario);
compiler.compile();
// Setup the process flow coordinator
......@@ -221,7 +226,7 @@ public final class Main {
/**
* Internal delegate to monitor the process execution.
*/
private static class Listener implements StepProcessListener {
private class Listener implements StepProcessListener {
@Override
public void onStart(Step step, String command) {
logStatus(currentTimeMillis(), step.name(), IN_PROGRESS, command);
......@@ -230,6 +235,9 @@ public final class Main {
@Override
public void onCompletion(Step step, Status status) {
logStatus(currentTimeMillis(), step.name(), status, null);
if (dumpLogs && !(step instanceof Group) && status == FAILED) {
dumpLogs(step);
}
}
@Override
......@@ -246,6 +254,18 @@ public final class Main {
}
}
// Dumps the step logs to standard output.
private void dumpLogs(Step step) {
File logFile = new File(compiler.logDir(), step.name() + ".log");
try {
print(">>>>>");
Files.copy(logFile, System.out);
print("<<<<<");
} catch (IOException e) {
print("Unable to dump log file %s", logFile.getName());
}
}
// Produces a description of event using the specified step status.
private static String action(Status status) {
return status == IN_PROGRESS ? "started" :
......