Search in sources :

Example 1 with TestFailException

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

the class BasicEnvironmentVirtualGroupTest method getEnvironmentVirtualGroups.

private Map<UmsRight, String> getEnvironmentVirtualGroups(TestContext testContext, UmsClient client) {
    String accountId = testContext.getActingUserCrn().getAccountId();
    String environmentCrn = testContext.given(EnvironmentTestDto.class).getCrn();
    Map<UmsRight, String> virtualGroups = new HashMap<>();
    String virtualGroup = null;
    for (UmsRight right : UmsRight.values()) {
        try {
            virtualGroup = client.getDefaultClient().getWorkloadAdministrationGroupName(accountId, MDCUtils.getRequestId(), right.getRight(), environmentCrn);
        } catch (StatusRuntimeException ex) {
            if (Status.Code.NOT_FOUND != ex.getStatus().getCode()) {
                LOGGER.info(String.format(" Virtual groups is missing for right: '%s' ", right.getRight()));
            }
        }
        if (StringUtils.hasText(virtualGroup)) {
            virtualGroups.put(right, virtualGroup);
        }
    }
    if (MapUtils.isNotEmpty(virtualGroups)) {
        Log.then(LOGGER, format(" Virtual groups are present [%s] for environment '%s' ", virtualGroups, environmentCrn));
        LOGGER.info(String.format(" Virtual groups are present [%s] for environment '%s' ", virtualGroups, environmentCrn));
    } else {
        throw new TestFailException(String.format(" Cannot find virtual groups for environment '%s' ", environmentCrn));
    }
    return virtualGroups;
}
Also used : EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) UmsRight(com.sequenceiq.cloudbreak.auth.altus.UmsRight)

Example 2 with TestFailException

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

the class DistroXEncryptedVolumeTest method verifyVolumeEncryptionKey.

private void verifyVolumeEncryptionKey(CloudPlatform cloudPlatform, String resourceName, List<String> instanceIds, CloudFunctionality cloudFunctionality, String environmentName, String resourceGroupName) {
    if (CloudPlatform.AWS.equals(cloudPlatform)) {
        String kmsKeyArn = awsCloudProvider.getEncryptionKeyArn(true);
        List<String> volumeKmsKeyIds = new ArrayList<>(cloudFunctionality.listVolumeEncryptionKeyIds(resourceName, null, instanceIds));
        if (volumeKmsKeyIds.stream().noneMatch(keyId -> keyId.equalsIgnoreCase(kmsKeyArn))) {
            LOGGER.error(format("Volume has not been encrypted with '%s' KMS key!", kmsKeyArn));
            throw new TestFailException(format("Volume has not been encrypted with '%s' KMS key!", kmsKeyArn));
        } else {
            LOGGER.info(format("Volume has been encrypted with '%s' KMS key.", kmsKeyArn));
            Log.then(LOGGER, format(" Volume has been encrypted with '%s' KMS key. ", kmsKeyArn));
        }
    } else if (CloudPlatform.AZURE.equals(cloudPlatform)) {
        String desKeyUrl = azureCloudProvider.getEncryptionKeyUrl();
        List<String> volumesDesId = new ArrayList<>(cloudFunctionality.listVolumeEncryptionKeyIds(resourceName, resourceGroupName, instanceIds));
        volumesDesId.forEach(desId -> {
            if (desId.contains("diskEncryptionSets/" + environmentName)) {
                LOGGER.info(format("Volume has been encrypted with '%s' DES key.", desId));
                Log.then(LOGGER, format(" Volume has been encrypted with '%s' DES key. ", desId));
            } else {
                LOGGER.error(format("Volume has not been encrypted with '%s' key!", desKeyUrl));
                throw new TestFailException(format("Volume has not been encrypted with '%s' key!", desKeyUrl));
            }
        });
    } else {
        LOGGER.warn(format("Disk encryption feature is not available at '%s' currently!", cloudPlatform));
    }
}
Also used : AwsCloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.aws.AwsCloudProvider) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) StringUtils(org.apache.commons.lang3.StringUtils) Description(com.sequenceiq.it.cloudbreak.context.Description) EnvironmentNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentNetworkTestDto) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DistroXInstanceGroupsBuilder(com.sequenceiq.it.cloudbreak.dto.distrox.instancegroup.DistroXInstanceGroupsBuilder) SdxUtil(com.sequenceiq.it.cloudbreak.util.SdxUtil) Tunnel(com.sequenceiq.common.api.type.Tunnel) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances) String.format(java.lang.String.format) List(java.util.List) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroXExternalDatabaseAssertion.validateTemplateContainsExternalDatabaseHostname(com.sequenceiq.it.cloudbreak.assertion.distrox.DistroXExternalDatabaseAssertion.validateTemplateContainsExternalDatabaseHostname) EnvironmentClient(com.sequenceiq.it.cloudbreak.EnvironmentClient) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) FreeIpaUserSyncTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaUserSyncTestDto) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) TelemetryTestDto(com.sequenceiq.it.cloudbreak.dto.telemetry.TelemetryTestDto) DistroXDatabaseAvailabilityType(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseAvailabilityType) AzureCloudFunctionality(com.sequenceiq.it.cloudbreak.util.azure.AzureCloudFunctionality) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) AzureCloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.azure.AzureCloudProvider) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) ResourceGroupTest(com.sequenceiq.it.cloudbreak.ResourceGroupTest) DistroXInstanceGroupTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.instancegroup.DistroXInstanceGroupTestDto) AwsAvailabilityZoneAssertion(com.sequenceiq.it.cloudbreak.assertion.distrox.AwsAvailabilityZoneAssertion) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) MASTER(com.sequenceiq.it.cloudbreak.cloud.HostGroupType.MASTER) Log(com.sequenceiq.it.cloudbreak.log.Log) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) SshEnaDriverCheckActions(com.sequenceiq.it.cloudbreak.util.ssh.action.SshEnaDriverCheckActions) FreeIpaInstanceUtil(com.sequenceiq.it.cloudbreak.util.FreeIpaInstanceUtil) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) SdxClient(com.sequenceiq.it.cloudbreak.SdxClient) DistroXDatabaseRequest(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest) ArrayList(java.util.ArrayList) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with TestFailException

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

the class AbstractCloudProvider method getLatestBaseImage.

public String getLatestBaseImage(ImageCatalogTestDto imageCatalogTestDto, CloudbreakClient cloudbreakClient, String platform) {
    try {
        List<BaseImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, platform, null, null).getBaseImages();
        if (images.size() == 0) {
            throw new IllegalStateException("Images are empty, there is not any base image on provider " + platform);
        }
        BaseImageV4Response baseImage = images.get(images.size() - 1);
        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 Base Image Date: %s | ID: %s | Description: %s ", baseImage.getDate(), baseImage.getUuid(), baseImage.getDescription()));
        return baseImage.getUuid();
    } catch (Exception e) {
        LOGGER.error("Cannot fetch base images of {} image catalog, because of {}", imageCatalogTestDto.getRequest().getName(), e);
        throw new TestFailException(" Cannot fetch base images of " + imageCatalogTestDto.getRequest().getName() + " image catalog", e);
    }
}
Also used : BaseImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 4 with TestFailException

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

the class SshJClientActions method checkNoEphemeralDisksMounted.

public void checkNoEphemeralDisksMounted(List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames) {
    Map<String, Pair<Integer, String>> deviceMountPointMappingsByIp = getDeviceMountPointMappingsByIp(instanceGroups, hostGroupNames);
    Map<String, Pair<Integer, String>> deviceDiskTypeMappingsByIp = getDeviceDiskTypeMappingsByIp(instanceGroups, hostGroupNames);
    for (Entry<String, Pair<Integer, String>> node : deviceDiskTypeMappingsByIp.entrySet()) {
        Map<String, String> ephemeralDisks = new Json(node.getValue().getValue()).getMap().entrySet().stream().filter(e -> String.valueOf(e.getValue()).contains("Amazon EC2 NVMe Instance Storage")).collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
        if (!ephemeralDisks.isEmpty()) {
            LOGGER.error("Instance store volume unintentionally present on node with IP {}!", node.getKey());
            throw new TestFailException(String.format("Instance store volume unintentionally present on node with IP %s!", node.getKey()));
        }
    }
    for (Entry<String, Pair<Integer, String>> node : deviceMountPointMappingsByIp.entrySet()) {
        Map<String, String> ephemeralMounts = new Json(node.getValue().getValue()).getMap().entrySet().stream().filter(e -> String.valueOf(e.getValue()).contains("ephfs")).collect(Collectors.toMap(Entry::getKey, x -> String.valueOf(x.getValue())));
        if (!ephemeralMounts.isEmpty()) {
            LOGGER.error("Device incorrectly mounted to /hadoopfs/ephfsN on node with IP {}!", node.getKey());
            throw new TestFailException(String.format("Device incorrectly mounted to /hadoopfs/ephfsN on node with IP %s!", node.getKey()));
        }
    }
}
Also used : FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) SshJClient(com.sequenceiq.it.cloudbreak.util.ssh.client.SshJClient) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) Pair(org.apache.commons.lang3.tuple.Pair) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) Collection(java.util.Collection) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) AbstractSdxTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractSdxTestDto) SSHClient(net.schmizz.sshj.SSHClient) Entry(java.util.Map.Entry) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Json(com.sequenceiq.cloudbreak.common.json.Json) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with TestFailException

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

the class DistroXCreateAction method action.

@Override
public DistroXTestDto action(TestContext testContext, DistroXTestDto testDto, CloudbreakClient client) throws Exception {
    if (StringUtils.isEmpty(testDto.getRequest().getEnvironmentName())) {
        Log.when(LOGGER, " Env name cannot be null ");
        throw new TestFailException("Env name cannot be null");
    }
    Log.whenJson(LOGGER, " Distrox create request: ", testDto.getRequest());
    StackV4Response stackV4Response = client.getDefaultClient().distroXV1Endpoint().post(testDto.getRequest());
    testDto.setFlow("Distrox create", stackV4Response.getFlowIdentifier());
    testDto.setResponse(stackV4Response);
    Log.whenJson(LOGGER, " Distrox create response: ", stackV4Response);
    return testDto;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) 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