Adding ability to dump logs for failed steps.
Change-Id: Ib3cb6552018d45c0bb4066e15a6e9bc8f69e97e0
Showing
3 changed files
with
26 additions
and
5 deletions
... | @@ -13,8 +13,7 @@ | ... | @@ -13,8 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | - | ||
17 | /** | 16 | /** |
18 | - * Implementations of OpenFlow extensions. | 17 | + * Processing of Nicira extensions. |
19 | */ | 18 | */ |
20 | package org.onosproject.driver.extensions; | 19 | package org.onosproject.driver.extensions; | ... | ... |
... | @@ -20,6 +20,7 @@ scenario=${1:-smoke} | ... | @@ -20,6 +20,7 @@ scenario=${1:-smoke} |
20 | 20 | ||
21 | # If stcColor is not set, we will enable color if this is an interactive session | 21 | # If stcColor is not set, we will enable color if this is an interactive session |
22 | [ -t 1 ] && interactive=true || interactive=false | 22 | [ -t 1 ] && interactive=true || interactive=false |
23 | +[ -t 1 ] && notInteractive=false || notInteractive=true | ||
23 | 24 | ||
24 | # stc requires that ONOS_USE_SSH=true, but we will store the old value and reset it after | 25 | # stc requires that ONOS_USE_SSH=true, but we will store the old value and reset it after |
25 | sshSet=$([ -z ${ONOS_USE_SSH+x} ]) && oldSSH=$ONOS_USE_SSH | 26 | sshSet=$([ -z ${ONOS_USE_SSH+x} ]) && oldSSH=$ONOS_USE_SSH |
... | @@ -27,7 +28,8 @@ export ONOS_USE_SSH=true | ... | @@ -27,7 +28,8 @@ export ONOS_USE_SSH=true |
27 | 28 | ||
28 | # Run stc | 29 | # Run stc |
29 | [ -z "$stcDebug" ] && DEBUG_OPTS="" | 30 | [ -z "$stcDebug" ] && DEBUG_OPTS="" |
30 | -stcColor=${stcColor:-$interactive} java $DEBUG_OPTS -jar $JAR $scenario "$@" | 31 | +stcColor=${stcColor:-$interactive} stcDumpLogs=${stcDumpLogs:-$notInteractive} \ |
32 | + java $DEBUG_OPTS -jar $JAR $scenario "$@" | ||
31 | 33 | ||
32 | # Reset the old value of ONOS_USE_SSH | 34 | # Reset the old value of ONOS_USE_SSH |
33 | [ $sshSet ] && export ONOS_USE_SSH=oldSSH || unset ONOS_USE_SSH | 35 | [ $sshSet ] && export ONOS_USE_SSH=oldSSH || unset ONOS_USE_SSH | ... | ... |
... | @@ -16,13 +16,16 @@ | ... | @@ -16,13 +16,16 @@ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | +import com.google.common.io.Files; | ||
19 | import org.eclipse.jetty.server.Server; | 20 | import org.eclipse.jetty.server.Server; |
20 | import org.eclipse.jetty.servlet.ServletHandler; | 21 | import org.eclipse.jetty.servlet.ServletHandler; |
21 | import org.eclipse.jetty.util.log.Logger; | 22 | import org.eclipse.jetty.util.log.Logger; |
22 | import org.onlab.stc.Coordinator.Status; | 23 | import org.onlab.stc.Coordinator.Status; |
23 | 24 | ||
25 | +import java.io.File; | ||
24 | import java.io.FileInputStream; | 26 | import java.io.FileInputStream; |
25 | import java.io.FileNotFoundException; | 27 | import java.io.FileNotFoundException; |
28 | +import java.io.IOException; | ||
26 | import java.text.SimpleDateFormat; | 29 | import java.text.SimpleDateFormat; |
27 | import java.util.Date; | 30 | import java.util.Date; |
28 | import java.util.List; | 31 | import java.util.List; |
... | @@ -64,10 +67,12 @@ public final class Main { | ... | @@ -64,10 +67,12 @@ public final class Main { |
64 | private String runToPatterns = ""; | 67 | private String runToPatterns = ""; |
65 | 68 | ||
66 | private Coordinator coordinator; | 69 | private Coordinator coordinator; |
70 | + private Compiler compiler; | ||
67 | private Monitor monitor; | 71 | private Monitor monitor; |
68 | private Listener delegate = new Listener(); | 72 | private Listener delegate = new Listener(); |
69 | 73 | ||
70 | private static boolean useColor = Objects.equals("true", System.getenv("stcColor")); | 74 | private static boolean useColor = Objects.equals("true", System.getenv("stcColor")); |
75 | + private static boolean dumpLogs = Objects.equals("true", System.getenv("stcDumpLogs")); | ||
71 | 76 | ||
72 | // usage: stc [<scenario-file>] [run] | 77 | // usage: stc [<scenario-file>] [run] |
73 | // usage: stc [<scenario-file>] run [from <from-patterns>] [to <to-patterns>]] | 78 | // usage: stc [<scenario-file>] run [from <from-patterns>] [to <to-patterns>]] |
... | @@ -113,7 +118,7 @@ public final class Main { | ... | @@ -113,7 +118,7 @@ public final class Main { |
113 | Scenario scenario = Scenario.loadScenario(new FileInputStream(scenarioFile)); | 118 | Scenario scenario = Scenario.loadScenario(new FileInputStream(scenarioFile)); |
114 | 119 | ||
115 | // Elaborate scenario | 120 | // Elaborate scenario |
116 | - Compiler compiler = new Compiler(scenario); | 121 | + compiler = new Compiler(scenario); |
117 | compiler.compile(); | 122 | compiler.compile(); |
118 | 123 | ||
119 | // Setup the process flow coordinator | 124 | // Setup the process flow coordinator |
... | @@ -221,7 +226,7 @@ public final class Main { | ... | @@ -221,7 +226,7 @@ public final class Main { |
221 | /** | 226 | /** |
222 | * Internal delegate to monitor the process execution. | 227 | * Internal delegate to monitor the process execution. |
223 | */ | 228 | */ |
224 | - private static class Listener implements StepProcessListener { | 229 | + private class Listener implements StepProcessListener { |
225 | @Override | 230 | @Override |
226 | public void onStart(Step step, String command) { | 231 | public void onStart(Step step, String command) { |
227 | logStatus(currentTimeMillis(), step.name(), IN_PROGRESS, command); | 232 | logStatus(currentTimeMillis(), step.name(), IN_PROGRESS, command); |
... | @@ -230,6 +235,9 @@ public final class Main { | ... | @@ -230,6 +235,9 @@ public final class Main { |
230 | @Override | 235 | @Override |
231 | public void onCompletion(Step step, Status status) { | 236 | public void onCompletion(Step step, Status status) { |
232 | logStatus(currentTimeMillis(), step.name(), status, null); | 237 | logStatus(currentTimeMillis(), step.name(), status, null); |
238 | + if (dumpLogs && !(step instanceof Group) && status == FAILED) { | ||
239 | + dumpLogs(step); | ||
240 | + } | ||
233 | } | 241 | } |
234 | 242 | ||
235 | @Override | 243 | @Override |
... | @@ -246,6 +254,18 @@ public final class Main { | ... | @@ -246,6 +254,18 @@ public final class Main { |
246 | } | 254 | } |
247 | } | 255 | } |
248 | 256 | ||
257 | + // Dumps the step logs to standard output. | ||
258 | + private void dumpLogs(Step step) { | ||
259 | + File logFile = new File(compiler.logDir(), step.name() + ".log"); | ||
260 | + try { | ||
261 | + print(">>>>>"); | ||
262 | + Files.copy(logFile, System.out); | ||
263 | + print("<<<<<"); | ||
264 | + } catch (IOException e) { | ||
265 | + print("Unable to dump log file %s", logFile.getName()); | ||
266 | + } | ||
267 | + } | ||
268 | + | ||
249 | // Produces a description of event using the specified step status. | 269 | // Produces a description of event using the specified step status. |
250 | private static String action(Status status) { | 270 | private static String action(Status status) { |
251 | return status == IN_PROGRESS ? "started" : | 271 | return status == IN_PROGRESS ? "started" : | ... | ... |
-
Please register or login to post a comment