Search in sources :

Example 1 with Scenario

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());
        }
    }
}
Also used : TestConfiguration(io.syndesis.qe.TestConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) CamelK(io.syndesis.qe.resource.impl.CamelK) AfterStep(io.cucumber.java.AfterStep) Scenario(io.cucumber.java.Scenario) Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) Collectors(java.util.stream.Collectors) Assumptions(org.assertj.core.api.Assumptions) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TestUtils(io.syndesis.qe.utils.TestUtils) After(io.cucumber.java.After) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) Before(io.cucumber.java.Before) Pod(io.fabric8.kubernetes.api.model.Pod) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AfterStep(io.cucumber.java.AfterStep)

Example 2 with Scenario

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();
    }
}
Also used : MissionOutline(com.github.nagyesta.abortmission.core.outline.MissionOutline) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) java.util(java.util) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) Logger(org.slf4j.Logger) Result(io.cucumber.plugin.event.Result) Scenario(io.cucumber.java.Scenario) LoggerFactory(org.slf4j.LoggerFactory) Status(io.cucumber.plugin.event.Status) ScenarioUriMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher) Field(java.lang.reflect.Field) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch) Consumer(java.util.function.Consumer) MissionControl(com.github.nagyesta.abortmission.core.MissionControl) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ScenarioNameMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher) Field(java.lang.reflect.Field) Result(io.cucumber.plugin.event.Result)

Example 3 with Scenario

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);
}
Also used : MissionOutline(com.github.nagyesta.abortmission.core.outline.MissionOutline) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) java.util(java.util) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) Logger(org.slf4j.Logger) Result(io.cucumber.plugin.event.Result) Scenario(io.cucumber.java.Scenario) LoggerFactory(org.slf4j.LoggerFactory) Status(io.cucumber.plugin.event.Status) ScenarioUriMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher) Field(java.lang.reflect.Field) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch) Consumer(java.util.function.Consumer) MissionControl(com.github.nagyesta.abortmission.core.MissionControl) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ScenarioNameMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps)

Aggregations

Scenario (io.cucumber.java.Scenario)3 ScenarioNameMatcher (com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher)2 ScenarioUriMatcher (com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher)2 AbortMissionCommandOps (com.github.nagyesta.abortmission.core.AbortMissionCommandOps)2 MissionControl (com.github.nagyesta.abortmission.core.MissionControl)2 MissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator)2 MissionHealthCheckMatcher (com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)2 MissionOutline (com.github.nagyesta.abortmission.core.outline.MissionOutline)2 StageTimeStopwatch (com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch)2 Result (io.cucumber.plugin.event.Result)2 Status (io.cucumber.plugin.event.Status)2 Field (java.lang.reflect.Field)2 java.util (java.util)2 Consumer (java.util.function.Consumer)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 After (io.cucumber.java.After)1 AfterStep (io.cucumber.java.AfterStep)1 Before (io.cucumber.java.Before)1 Pod (io.fabric8.kubernetes.api.model.Pod)1