use of io.cucumber.java.Scenario in project syndesis-qe by syndesisio.
the class TestHooks method getLogs.
@AfterStep
public void getLogs(Scenario scenario) {
if (scenario.isFailed()) {
TestUtils.printPods(scenario);
log.warn("Scenario {} failed, saving integration logs to scenario", scenario.getName());
// There can be multiple integration pods for one test
List<Pod> integrationPods = OpenShiftUtils.getInstance().pods().list().getItems().stream().filter(p -> p.getMetadata().getName().startsWith("i-") && !p.getMetadata().getName().contains("deploy") && !p.getMetadata().getName().contains("build")).collect(Collectors.toList());
for (Pod integrationPod : integrationPods) {
try {
scenario.attach(OpenShiftUtils.getInstance().getPodLog(integrationPod).getBytes(), "text/plain", String.format("Integration %s log", integrationPod.getMetadata().getName()));
} catch (KubernetesClientException ex) {
// when the build failed, the integration pod is not ready (`ImagePullBackOff`) In that case, the pod doesn't contain log. That
// causes that OpenShiftUtils has thrown KubernetesClientException
}
}
log.info("Adding all failed build to the log");
List<Pod> failedBuilds = OpenShiftUtils.getInstance().pods().list().getItems().stream().filter(p -> p.getMetadata().getName().contains("build") && p.getStatus().getContainerStatuses().stream().anyMatch(c -> c.getState().getTerminated().getReason().equals("Error"))).collect(Collectors.toList());
for (Pod failedBuild : failedBuilds) {
scenario.attach(String.format("%s\n\n%s", failedBuild.getMetadata().getName(), OpenShiftUtils.getInstance().getPodLog(failedBuild)).getBytes(), "text/plain", "Log of failed build " + failedBuild.getMetadata().getName());
}
}
}
use of io.cucumber.java.Scenario in project abort-mission by nagyesta.
the class LaunchAbortHook method getThrowable.
@SuppressWarnings("unchecked")
private Optional<Throwable> getThrowable(final Scenario scenario) {
try {
final Field delegate = scenario.getClass().getDeclaredField("delegate");
delegate.setAccessible(true);
final Object testCaseState = delegate.get(scenario);
final Field stepResults = testCaseState.getClass().getDeclaredField("stepResults");
stepResults.setAccessible(true);
final List<Result> results = (List<Result>) stepResults.get(testCaseState);
return Optional.ofNullable(results).flatMap(r -> r.stream().filter(res -> res.getStatus() == Status.FAILED).map(Result::getError).findFirst());
} catch (final Exception e) {
LOGGER.error("Couldn't find throwable, substituting with an Exception for reporting.\n" + "Failure suppression will not be accurate. Caused by: {}", e.getMessage(), e);
return Optional.empty();
}
}
use of io.cucumber.java.Scenario in project abort-mission by nagyesta.
the class LaunchAbortHook method findEvaluators.
private Set<MissionHealthCheckEvaluator> findEvaluators(final Scenario scenario) {
final Optional<String> context = scenario.getSourceTagNames().stream().filter(tag -> tag.startsWith("@AbortMission_Context_")).map(tag -> tag.replaceFirst("^@AbortMission_Context_", "")).findFirst();
final AbortMissionCommandOps commandOps = context.map(MissionControl::commandOps).orElse(MissionControl.commandOps());
return Objects.requireNonNull(commandOps, "Mission context is not found: " + context.orElse("'- DEFAULT - '")).matchingEvaluators(scenario);
}
Aggregations