Committed by
Gerrit Code Review
Adding support for SKIPPED state to STC.
Change-Id: I5a90bedb6272f0bb1d76f0bc5e19e67e8d05eec8
Showing
7 changed files
with
42 additions
and
49 deletions
... | @@ -23,5 +23,5 @@ | ... | @@ -23,5 +23,5 @@ |
23 | <dependency name="Archetypes" requires="Setup"/> | 23 | <dependency name="Archetypes" requires="Setup"/> |
24 | 24 | ||
25 | <import file="${ONOS_ROOT}/tools/test/scenarios/wrapup.xml"/> | 25 | <import file="${ONOS_ROOT}/tools/test/scenarios/wrapup.xml"/> |
26 | - <dependency name="Wrapup" requires="~Archetypes,Setup"/> | 26 | + <dependency name="Wrapup" requires="~Archetypes,~Setup"/> |
27 | </scenario> | 27 | </scenario> | ... | ... |
... | @@ -204,19 +204,20 @@ public class Coordinator { | ... | @@ -204,19 +204,20 @@ public class Coordinator { |
204 | */ | 204 | */ |
205 | private synchronized void execute(Step step) { | 205 | private synchronized void execute(Step step) { |
206 | Directive directive = nextAction(step); | 206 | Directive directive = nextAction(step); |
207 | - if (directive == RUN || directive == SKIP) { | 207 | + if (directive == RUN) { |
208 | store.markStarted(step); | 208 | store.markStarted(step); |
209 | if (step instanceof Group) { | 209 | if (step instanceof Group) { |
210 | Group group = (Group) step; | 210 | Group group = (Group) step; |
211 | delegate.onStart(group); | 211 | delegate.onStart(group); |
212 | - if (directive == RUN) { | 212 | + executeRoots(group); |
213 | - executeRoots(group); | ||
214 | - } else { | ||
215 | - group.children().forEach(child -> delegate.onCompletion(child, 1)); | ||
216 | - } | ||
217 | } else { | 213 | } else { |
218 | - executor.execute(new StepProcessor(step, directive == SKIP, | 214 | + executor.execute(new StepProcessor(step, logDir, delegate)); |
219 | - logDir, delegate)); | 215 | + } |
216 | + } else if (directive == SKIP) { | ||
217 | + if (step instanceof Group) { | ||
218 | + Group group = (Group) step; | ||
219 | + group.children().forEach(child -> delegate.onCompletion(child, SKIPPED)); | ||
220 | + delegate.onCompletion(step, SKIPPED); | ||
220 | } | 221 | } |
221 | } | 222 | } |
222 | } | 223 | } |
... | @@ -237,7 +238,8 @@ public class Coordinator { | ... | @@ -237,7 +238,8 @@ public class Coordinator { |
237 | Status depStatus = store.getStatus(dependency.dst()); | 238 | Status depStatus = store.getStatus(dependency.dst()); |
238 | if (depStatus == WAITING || depStatus == IN_PROGRESS) { | 239 | if (depStatus == WAITING || depStatus == IN_PROGRESS) { |
239 | return NOOP; | 240 | return NOOP; |
240 | - } else if (depStatus == FAILED && !dependency.isSoft()) { | 241 | + } else if ((depStatus == FAILED || depStatus == SKIPPED) && |
242 | + !dependency.isSoft()) { | ||
241 | return SKIP; | 243 | return SKIP; |
242 | } | 244 | } |
243 | } | 245 | } |
... | @@ -270,7 +272,7 @@ public class Coordinator { | ... | @@ -270,7 +272,7 @@ public class Coordinator { |
270 | failed = failed || status == FAILED; | 272 | failed = failed || status == FAILED; |
271 | } | 273 | } |
272 | if (done) { | 274 | if (done) { |
273 | - delegate.onCompletion(group, failed ? 1 : 0); | 275 | + delegate.onCompletion(group, failed ? FAILED : SUCCEEDED); |
274 | } | 276 | } |
275 | } | 277 | } |
276 | } | 278 | } |
... | @@ -296,9 +298,9 @@ public class Coordinator { | ... | @@ -296,9 +298,9 @@ public class Coordinator { |
296 | } | 298 | } |
297 | 299 | ||
298 | @Override | 300 | @Override |
299 | - public void onCompletion(Step step, int exitCode) { | 301 | + public void onCompletion(Step step, Status status) { |
300 | - store.markComplete(step, exitCode == 0 ? SUCCEEDED : FAILED); | 302 | + store.markComplete(step, status); |
301 | - listeners.forEach(listener -> listener.onCompletion(step, exitCode)); | 303 | + listeners.forEach(listener -> listener.onCompletion(step, status)); |
302 | executeSucessors(step); | 304 | executeSucessors(step); |
303 | latch.countDown(); | 305 | latch.countDown(); |
304 | } | 306 | } | ... | ... |
... | @@ -172,8 +172,8 @@ public final class Main { | ... | @@ -172,8 +172,8 @@ public final class Main { |
172 | } | 172 | } |
173 | 173 | ||
174 | @Override | 174 | @Override |
175 | - public void onCompletion(Step step, int exitCode) { | 175 | + public void onCompletion(Step step, Status status) { |
176 | - logStatus(currentTimeMillis(), step.name(), exitCode == 0 ? SUCCEEDED : FAILED); | 176 | + logStatus(currentTimeMillis(), step.name(), status); |
177 | } | 177 | } |
178 | 178 | ||
179 | @Override | 179 | @Override | ... | ... |
... | @@ -31,10 +31,10 @@ public interface StepProcessListener { | ... | @@ -31,10 +31,10 @@ public interface StepProcessListener { |
31 | /** | 31 | /** |
32 | * Indicates that process step has completed. | 32 | * Indicates that process step has completed. |
33 | * | 33 | * |
34 | - * @param step subject step | 34 | + * @param step subject step |
35 | - * @param exitCode step process exit exitCode | 35 | + * @param status step completion status |
36 | */ | 36 | */ |
37 | - default void onCompletion(Step step, int exitCode) { | 37 | + default void onCompletion(Step step, Coordinator.Status status) { |
38 | } | 38 | } |
39 | 39 | ||
40 | /** | 40 | /** | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | +import org.onlab.stc.Coordinator.Status; | ||
19 | + | ||
18 | import java.io.BufferedReader; | 20 | import java.io.BufferedReader; |
19 | import java.io.File; | 21 | import java.io.File; |
20 | import java.io.IOException; | 22 | import java.io.IOException; |
... | @@ -23,6 +25,8 @@ import java.io.InputStreamReader; | ... | @@ -23,6 +25,8 @@ import java.io.InputStreamReader; |
23 | import java.io.PrintWriter; | 25 | import java.io.PrintWriter; |
24 | 26 | ||
25 | import static java.lang.String.format; | 27 | import static java.lang.String.format; |
28 | +import static org.onlab.stc.Coordinator.Status.FAILED; | ||
29 | +import static org.onlab.stc.Coordinator.Status.SUCCEEDED; | ||
26 | import static org.onlab.stc.Coordinator.print; | 30 | import static org.onlab.stc.Coordinator.print; |
27 | 31 | ||
28 | /** | 32 | /** |
... | @@ -30,12 +34,12 @@ import static org.onlab.stc.Coordinator.print; | ... | @@ -30,12 +34,12 @@ import static org.onlab.stc.Coordinator.print; |
30 | */ | 34 | */ |
31 | class StepProcessor implements Runnable { | 35 | class StepProcessor implements Runnable { |
32 | 36 | ||
37 | + private static final String IGNORE_CODE = "~"; | ||
33 | private static final int FAIL = -1; | 38 | private static final int FAIL = -1; |
34 | 39 | ||
35 | static String launcher = "stc-launcher "; | 40 | static String launcher = "stc-launcher "; |
36 | 41 | ||
37 | private final Step step; | 42 | private final Step step; |
38 | - private final boolean skip; | ||
39 | private final File logDir; | 43 | private final File logDir; |
40 | 44 | ||
41 | private Process process; | 45 | private Process process; |
... | @@ -45,25 +49,22 @@ class StepProcessor implements Runnable { | ... | @@ -45,25 +49,22 @@ class StepProcessor implements Runnable { |
45 | * Creates a process monitor. | 49 | * Creates a process monitor. |
46 | * | 50 | * |
47 | * @param step step or group to be executed | 51 | * @param step step or group to be executed |
48 | - * @param skip indicates the process should not actually execute | ||
49 | * @param logDir directory where step process log should be stored | 52 | * @param logDir directory where step process log should be stored |
50 | * @param delegate process lifecycle listener | 53 | * @param delegate process lifecycle listener |
51 | */ | 54 | */ |
52 | - StepProcessor(Step step, boolean skip, File logDir, StepProcessListener delegate) { | 55 | + StepProcessor(Step step, File logDir, StepProcessListener delegate) { |
53 | this.step = step; | 56 | this.step = step; |
54 | - this.skip = skip; | ||
55 | this.logDir = logDir; | 57 | this.logDir = logDir; |
56 | this.delegate = delegate; | 58 | this.delegate = delegate; |
57 | } | 59 | } |
58 | 60 | ||
59 | @Override | 61 | @Override |
60 | public void run() { | 62 | public void run() { |
61 | - int code = FAIL; | ||
62 | delegate.onStart(step); | 63 | delegate.onStart(step); |
63 | - if (!skip) { | 64 | + int code = execute(); |
64 | - code = execute(); | 65 | + boolean ignoreCode = step.env() != null && step.env.equals(IGNORE_CODE); |
65 | - } | 66 | + Status status = ignoreCode || code == 0 ? SUCCEEDED : FAILED; |
66 | - delegate.onCompletion(step, code); | 67 | + delegate.onCompletion(step, status); |
67 | } | 68 | } |
68 | 69 | ||
69 | /** | 70 | /** | ... | ... |
... | @@ -68,8 +68,8 @@ public class CoordinatorTest { | ... | @@ -68,8 +68,8 @@ public class CoordinatorTest { |
68 | } | 68 | } |
69 | 69 | ||
70 | @Override | 70 | @Override |
71 | - public void onCompletion(Step step, int exitCode) { | 71 | + public void onCompletion(Step step, Coordinator.Status status) { |
72 | - print("< %s: %s", step.name(), exitCode == 0 ? "completed" : "failed"); | 72 | + print("< %s: %s", step.name(), status == Coordinator.Status.SUCCEEDED ? "completed" : "failed"); |
73 | } | 73 | } |
74 | 74 | ||
75 | @Override | 75 | @Override | ... | ... |
... | @@ -23,7 +23,9 @@ import org.onlab.util.Tools; | ... | @@ -23,7 +23,9 @@ import org.onlab.util.Tools; |
23 | import java.io.File; | 23 | import java.io.File; |
24 | import java.io.IOException; | 24 | import java.io.IOException; |
25 | 25 | ||
26 | -import static org.junit.Assert.*; | 26 | +import static org.junit.Assert.assertEquals; |
27 | +import static org.junit.Assert.assertTrue; | ||
28 | +import static org.onlab.stc.Coordinator.Status.SUCCEEDED; | ||
27 | 29 | ||
28 | /** | 30 | /** |
29 | * Test of the step processor. | 31 | * Test of the step processor. |
... | @@ -46,31 +48,19 @@ public class StepProcessorTest { | ... | @@ -46,31 +48,19 @@ public class StepProcessorTest { |
46 | } | 48 | } |
47 | 49 | ||
48 | @Test | 50 | @Test |
49 | - public void executed() { | 51 | + public void basics() { |
50 | Step step = new Step("foo", "ls /tmp", null, null, null); | 52 | Step step = new Step("foo", "ls /tmp", null, null, null); |
51 | - StepProcessor processor = new StepProcessor(step, false, DIR, delegate); | 53 | + StepProcessor processor = new StepProcessor(step, DIR, delegate); |
52 | processor.run(); | 54 | processor.run(); |
53 | assertTrue("should be started", delegate.started); | 55 | assertTrue("should be started", delegate.started); |
54 | assertTrue("should have output", delegate.output); | 56 | assertTrue("should have output", delegate.output); |
55 | assertTrue("should be stopped", delegate.stopped); | 57 | assertTrue("should be stopped", delegate.stopped); |
56 | - assertEquals("incorrect code", 0, delegate.code); | 58 | + assertEquals("incorrect status", SUCCEEDED, delegate.status); |
57 | - } | ||
58 | - | ||
59 | - | ||
60 | - @Test | ||
61 | - public void skipped() { | ||
62 | - Step step = new Step("foo", "ls /tmp", null, null, null); | ||
63 | - StepProcessor processor = new StepProcessor(step, true, DIR, delegate); | ||
64 | - processor.run(); | ||
65 | - assertTrue("should be started", delegate.started); | ||
66 | - assertFalse("should have output", delegate.output); | ||
67 | - assertTrue("should be stopped", delegate.stopped); | ||
68 | - assertEquals("incorrect code", -1, delegate.code); | ||
69 | } | 59 | } |
70 | 60 | ||
71 | private class Listener implements StepProcessListener { | 61 | private class Listener implements StepProcessListener { |
72 | 62 | ||
73 | - private int code = 123; | 63 | + private Coordinator.Status status; |
74 | private boolean started, stopped, output; | 64 | private boolean started, stopped, output; |
75 | 65 | ||
76 | @Override | 66 | @Override |
... | @@ -79,9 +69,9 @@ public class StepProcessorTest { | ... | @@ -79,9 +69,9 @@ public class StepProcessorTest { |
79 | } | 69 | } |
80 | 70 | ||
81 | @Override | 71 | @Override |
82 | - public void onCompletion(Step step, int exitCode) { | 72 | + public void onCompletion(Step step, Coordinator.Status status) { |
83 | stopped = true; | 73 | stopped = true; |
84 | - this.code = exitCode; | 74 | + this.status = status; |
85 | } | 75 | } |
86 | 76 | ||
87 | @Override | 77 | @Override | ... | ... |
-
Please register or login to post a comment