Search in sources :

Example 76 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class TestContext method then.

public <T extends CloudbreakTestDto> T then(T entity, Class<? extends MicroserviceClient> clientClass, Assertion<T, ? extends MicroserviceClient> assertion, RunningParameter runningParameter) {
    checkShutdown();
    String key = getKey(assertion.getClass(), runningParameter);
    if (!getExceptionMap().isEmpty() && runningParameter.isSkipOnFail()) {
        LOGGER.info("Should be skipped because of previous error. when [{}]", key);
        return entity;
    }
    CloudbreakUser who = setActingUser(runningParameter);
    Log.then(LOGGER, assertion.getClass().getSimpleName() + " assertion on " + entity + " by " + who);
    try {
        CloudbreakTestDto cloudbreakTestDto = resourceNames.get(key);
        if (cloudbreakTestDto != null) {
            return assertion.doAssertion(this, (T) cloudbreakTestDto, getMicroserviceClient(entity.getClass(), who.getAccessKey()));
        } else {
            assertion.doAssertion(this, entity, getMicroserviceClient(entity.getClass(), who.getAccessKey()));
        }
    } catch (Exception e) {
        if (runningParameter.isLogError()) {
            LOGGER.error("then [{}] assertion is failed: {}, name: {}", key, ResponseUtil.getErrorMessage(e), entity.getName(), e);
            Log.then(null, assertion.getClass().getSimpleName() + " assertion is failed: " + ResponseUtil.getErrorMessage(e));
        }
        getExceptionMap().put(key, e);
    } catch (Error e) {
        getExceptionMap().put(key, new TestFailException(e.getMessage(), e));
    }
    return entity;
}
Also used : CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudbreakUser(com.sequenceiq.it.cloudbreak.actor.CloudbreakUser) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BeansException(org.springframework.beans.BeansException)

Example 77 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class TestContext method handleExceptionsDuringTest.

public void handleExceptionsDuringTest(TestErrorLog testErrorLog) {
    validated = true;
    checkShutdown();
    if (!exceptionMap.isEmpty()) {
        List<Clue> clues = resourceNames.values().stream().filter(Investigable.class::isInstance).peek(cloudbreakTestDto -> {
            try {
                cloudbreakTestDto.refresh();
            } catch (Exception e) {
                LOGGER.warn("Failed to refresh {}, continue with using its last known state.", cloudbreakTestDto, e);
            }
        }).map(Investigable.class::cast).map(Investigable::investigate).filter(Objects::nonNull).collect(Collectors.toList());
        String errorMessage = errorLogMessageProvider.getMessage(exceptionMap, clues);
        ITestResult testResult = Reporter.getCurrentTestResult();
        Throwable testFailException = errorLogMessageProvider.getException(exceptionMap);
        if (testFailException != null) {
            testResult.setThrowable(testFailException);
            testResult.setTestName(getTestMethodName().orElse("undefinedMethod"));
            testResult.setStatus(ITestResult.FAILURE);
            String methodName = testResult.getName();
            String testFailureType = testResult.getThrowable().getCause() != null ? testResult.getThrowable().getCause().getClass().getName() : testResult.getThrowable().getClass().getName();
            String testName = String.join("_", commonCloudProperties.getCloudProvider().toLowerCase(), methodName);
            testResult.getTestContext().setAttribute(testName + OUTPUT_FAILURE_TYPE, testFailureType);
            testResult.getTestContext().setAttribute(testName + OUTPUT_FAILURE, testResult.getThrowable());
            LOGGER.info("Failed test result have been pushed to: Test Name: {} | Type Attribute: {} | Failure Attribute: {} | Failure Type: {} | Failure: ", testName, testName + OUTPUT_FAILURE_TYPE, testName + OUTPUT_FAILURE, testFailureType, testResult.getThrowable());
        } else {
            LOGGER.error("Test Context TestFailException is null! So cannot get the correct test fail result!");
        }
        testErrorLog.report(LOGGER, errorMessage);
        exceptionMap.clear();
    }
}
Also used : ITestResult(org.testng.ITestResult) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BeansException(org.springframework.beans.BeansException)

Example 78 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class TestContext method whenException.

public <E extends Exception, T extends CloudbreakTestDto, U extends MicroserviceClient> T whenException(T entity, Class<? extends MicroserviceClient> clientClass, Action<T, U> action, Class<E> expectedException, RunningParameter runningParameter) {
    checkShutdown();
    String key = runningParameter.getKey();
    if (StringUtils.isBlank(key)) {
        key = action.getClass().getSimpleName();
    }
    if (!getExceptionMap().isEmpty() && runningParameter.isSkipOnFail()) {
        LOGGER.info("Should be skipped because of previous error. when [{}]", key);
        return entity;
    }
    CloudbreakUser who = setActingUser(runningParameter);
    LOGGER.info("when exception {} action on {} by {}, name: {}", key, entity, who, entity.getName());
    Log.whenException(LOGGER, action.getClass().getSimpleName() + " action on " + entity + " by " + who);
    try {
        String message = String.format("Expected exception with message (%s) has not been thrown at action (%s)!", runningParameter.getExpectedMessage(), action);
        doAction(entity, clientClass, action, who.getAccessKey());
        getExceptionMap().put("whenException", new TestFailException(message));
        LOGGER.error(message);
        htmlLoggerForExceptionValidation(message, "whenException");
    } catch (Exception e) {
        exceptionValidation(expectedException, e, key, runningParameter, "whenException");
    }
    return entity;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudbreakUser(com.sequenceiq.it.cloudbreak.actor.CloudbreakUser) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BeansException(org.springframework.beans.BeansException)

Example 79 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class AzureCloudProvider method getPreviousPreWarmedImageID.

@Override
public String getPreviousPreWarmedImageID(TestContext testContext, ImageCatalogTestDto imageCatalogTestDto, CloudbreakClient cloudbreakClient) {
    if (azureProperties.getBaseimage().getImageId() == null || azureProperties.getBaseimage().getImageId().isEmpty()) {
        try {
            List<ImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, CloudPlatform.AZURE.name(), null, null, false).getCdhImages();
            ImageV4Response olderImage = images.get(images.size() - 2);
            Log.log(LOGGER, format(" Image Catalog Name: %s ", imageCatalogTestDto.getRequest().getName()));
            Log.log(LOGGER, format(" Image Catalog URL: %s ", imageCatalogTestDto.getRequest().getUrl()));
            Log.log(LOGGER, format(" Selected Pre-warmed Image Date: %s | ID: %s | Description: %s | Stack Version: %s ", olderImage.getDate(), olderImage.getUuid(), olderImage.getStackDetails().getVersion(), olderImage.getDescription()));
            azureProperties.getBaseimage().setImageId(olderImage.getUuid());
            return olderImage.getUuid();
        } catch (Exception e) {
            LOGGER.error("Cannot fetch pre-warmed images of {} image catalog!", imageCatalogTestDto.getRequest().getName());
            throw new TestFailException(" Cannot fetch pre-warmed images of " + imageCatalogTestDto.getRequest().getName() + " image catalog!", e);
        }
    } else {
        Log.log(LOGGER, format(" Image Catalog Name: %s ", commonCloudProperties().getImageCatalogName()));
        Log.log(LOGGER, format(" Image Catalog URL: %s ", commonCloudProperties().getImageCatalogUrl()));
        Log.log(LOGGER, format(" Image ID for SDX create: %s ", azureProperties.getBaseimage().getImageId()));
        return azureProperties.getBaseimage().getImageId();
    }
}
Also used : ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 80 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class AzureCloudProviderAssertion method assertServiceEndpoint.

@Override
public void assertServiceEndpoint(EnvironmentTestDto environmentTestDto) {
    ServiceEndpointCreation serviceEndpointCreationRequest = Optional.ofNullable(environmentTestDto.getRequest().getNetwork().getServiceEndpointCreation()).orElse(ServiceEndpointCreation.DISABLED);
    ServiceEndpointCreation serviceEndpointCreationResponse = environmentTestDto.getResponse().getNetwork().getServiceEndpointCreation();
    if (serviceEndpointCreationRequest != serviceEndpointCreationResponse) {
        String message = String.format("Service endpoint creation in request (%s) does not match that in response (%s)", serviceEndpointCreationRequest, serviceEndpointCreationResponse);
        LOGGER.error(message);
        throw new TestFailException(message);
    }
    String databasePrivateDnsZoneIdRequest = environmentTestDto.getRequest().getNetwork().getAzure().getDatabasePrivateDnsZoneId();
    String databasePrivateDnsZoneIdResponse = environmentTestDto.getResponse().getNetwork().getAzure().getDatabasePrivateDnsZoneId();
    if (StringUtils.isNotEmpty(databasePrivateDnsZoneIdRequest) && !databasePrivateDnsZoneIdRequest.equals(databasePrivateDnsZoneIdResponse)) {
        String message = String.format("Private DNS zone id for database was requested to be %s, but is %s", databasePrivateDnsZoneIdRequest, databasePrivateDnsZoneIdResponse);
        LOGGER.error(message);
        throw new TestFailException(message);
    }
}
Also used : ServiceEndpointCreation(com.sequenceiq.common.api.type.ServiceEndpointCreation) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Aggregations

TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)101 List (java.util.List)15 Inject (javax.inject.Inject)14 Map (java.util.Map)13 Description (com.sequenceiq.it.cloudbreak.context.Description)12 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Test (org.testng.annotations.Test)12 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Log (com.sequenceiq.it.cloudbreak.log.Log)9 String.format (java.lang.String.format)9 Collectors (java.util.stream.Collectors)9 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)8 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)8 IOException (java.io.IOException)8 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8