Search in sources :

Example 11 with DistroXTestDto

use of com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto in project cloudbreak by hortonworks.

the class TagsUtilTest method verifyCreatorWithCdpCrnButTestContextHasAltusCrn.

@Test
void verifyCreatorWithCdpCrnButTestContextHasAltusCrn() {
    DistroXTestDto testDto = new DistroXTestDto(mock(TestContext.class));
    StackV4Response response = new StackV4Response();
    TagsV4Response tags = new TagsV4Response();
    tags.setUserDefined(Map.of(TagsUtil.TEST_NAME_TAG, TEST_NAME));
    tags.setDefaults(DEFAULT_TAGS);
    response.setTags(tags);
    testDto.setResponse(response);
    when(testContext.getActingUserCrn()).thenReturn(Crn.fromString("crn:altus:iam:us-west-1:qe-gcp:user:cloudbreak-qe@hortonworks.com"));
    when(gcpLabelUtil.transformLabelKeyOrValue(anyString())).thenReturn(CLOUDERA_CREATOR_RESOURCE_NAME_TAG_KEY);
    assertThatCode(() -> underTest.verifyTags(testDto, testContext)).doesNotThrowAnyException();
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) Test(org.testng.annotations.Test)

Example 12 with DistroXTestDto

use of com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto in project cloudbreak by hortonworks.

the class TagsUtilTest method verifyTagsShouldFailAbstractTestDtoDoesNotHaveAllNeededTags.

@Test
void verifyTagsShouldFailAbstractTestDtoDoesNotHaveAllNeededTags() {
    DistroXTestDto testDto = new DistroXTestDto(mock(TestContext.class));
    StackV4Response response = new StackV4Response();
    TagsV4Response tags = new TagsV4Response();
    tags.setUserDefined(Map.of(TagsUtil.TEST_NAME_TAG, TEST_NAME));
    Map<String, String> defaultTags = new HashMap<>(DEFAULT_TAGS);
    defaultTags.remove("owner");
    tags.setDefaults(defaultTags);
    response.setTags(tags);
    testDto.setResponse(response);
    String expectedMsg = String.format(TagsUtil.TAG_VALUE_IS_NULL_FAILURE_PATTERN, OWNER_TAG_KEY);
    assertThatThrownBy(() -> underTest.verifyTags(testDto, testContext)).hasMessageContaining(expectedMsg).matches(e -> !e.getMessage().contains(TagsUtil.MISSING_TEST_NAME_TAG_MESSAGE)).matches(e -> defaultTags.keySet().stream().noneMatch(tag -> e.getMessage().contains(tag)));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) GcpLabelUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpLabelUtil) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AbstractTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractTestDto) Map(java.util.Map) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) BeforeMethod(org.testng.annotations.BeforeMethod) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.when(org.mockito.Mockito.when) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) Mockito(org.mockito.Mockito) Optional(java.util.Optional) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) HashMap(java.util.HashMap) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) Test(org.testng.annotations.Test)

Example 13 with DistroXTestDto

use of com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto in project cloudbreak by hortonworks.

the class TagsUtilTest method verifyCreatorAsGcpLabelTransformedValue.

@Test
void verifyCreatorAsGcpLabelTransformedValue() {
    DistroXTestDto testDto = new DistroXTestDto(mock(TestContext.class));
    StackV4Response response = new StackV4Response();
    TagsV4Response tags = new TagsV4Response();
    tags.setUserDefined(Map.of(TagsUtil.TEST_NAME_TAG, TEST_NAME));
    Map<String, String> defaultTags = new HashMap<>(DEFAULT_TAGS);
    defaultTags.put(CLOUDERA_CREATOR_RESOURCE_NAME_TAG_KEY, ACTING_USER_CRN);
    tags.setDefaults(defaultTags);
    response.setTags(tags);
    testDto.setResponse(response);
    when(gcpLabelUtil.transformLabelKeyOrValue(anyString())).thenReturn(CLOUDERA_CREATOR_RESOURCE_NAME_TAG_KEY);
    assertThatCode(() -> underTest.verifyTags(testDto, testContext)).doesNotThrowAnyException();
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) HashMap(java.util.HashMap) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TagsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response) Test(org.testng.annotations.Test)

Example 14 with DistroXTestDto

use of com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto in project cloudbreak by hortonworks.

the class ClouderaManagerClientActions method checkCmServicesStartedSuccessfully.

public DistroXTestDto checkCmServicesStartedSuccessfully(DistroXTestDto testDto, String user, String password) {
    String serverIp = testDto.getResponse().getCluster().getServerIp();
    ApiClient apiClient = getCmApiClientWithTimeoutDisabledDirect(serverIp, testDto.getName(), V_43, user, password);
    // CHECKSTYLE:OFF
    HostsResourceApi hostsResourceApi = new HostsResourceApi(apiClient);
    // CHECKSTYLE:ON
    try {
        Set<String> masterHostnames = testDto.getResponse().getInstanceGroups().stream().filter(ig -> "master".equals(ig.getName())).flatMap(ig -> ig.getMetadata().stream()).map(InstanceMetaDataV4Response::getDiscoveryFQDN).collect(Collectors.toSet());
        List<ApiHost> apiHosts = hostsResourceApi.readHosts(null, null, "FULL_WITH_HEALTH_CHECK_EXPLANATION").getItems();
        Set<String> servicesNotStarted = apiHosts.stream().filter(apiHost -> masterHostnames.contains(apiHost.getHostname())).flatMap(apiHost -> collectNotStartedServicesOnHost(apiHost).stream()).filter(serviceName -> REQUIRED_SERVICES.contains(serviceName)).collect(Collectors.toSet());
        if (!servicesNotStarted.isEmpty()) {
            LOGGER.error("There are not started required services: {}", servicesNotStarted);
            throw new TestFailException(String.format("There are not started required services: %s", servicesNotStarted));
        }
    } catch (ApiException e) {
        LOGGER.error("Exception when calling HostsResourceApi#readHosts. Response: {}", e.getResponseBody(), e);
        String message = format("Exception when calling HostsResourceApi#readHosts at %s. Response: %s", apiClient.getBasePath(), e.getResponseBody());
        throw new TestFailException(message, e);
    } catch (Exception e) {
        LOGGER.error("Can't read host statuses at: '{}'!", apiClient.getBasePath());
        throw new TestFailException("Can't read host statuses at: " + apiClient.getBasePath(), e);
    }
    return testDto;
}
Also used : Logger(org.slf4j.Logger) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ApiException(com.cloudera.api.swagger.client.ApiException) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Value(org.springframework.beans.factory.annotation.Value) RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) SdxInternalTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxInternalTestDto) List(java.util.List) Component(org.springframework.stereotype.Component) ClouderaManagerClient(com.sequenceiq.it.cloudbreak.util.clouderamanager.client.ClouderaManagerClient) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiHost(com.cloudera.api.swagger.model.ApiHost) ListUtils.emptyIfNull(org.apache.commons.collections4.ListUtils.emptyIfNull) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiException(com.cloudera.api.swagger.client.ApiException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 15 with DistroXTestDto

use of com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto in project cloudbreak by hortonworks.

the class SshJClientActions method checkMeteringStatus.

public DistroXTestDto checkMeteringStatus(DistroXTestDto testDto, List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames) {
    String meteringStatusCommand = "sudo cdp-doctor metering status --format json";
    Map<String, Pair<Integer, String>> meteringStatusReportByIp = getInstanceGroupIps(instanceGroups, hostGroupNames, false).stream().collect(Collectors.toMap(ip -> ip, ip -> executeSshCommand(ip, meteringStatusCommand)));
    for (Entry<String, Pair<Integer, String>> meteringStatusReport : meteringStatusReportByIp.entrySet()) {
        List<Integer> heartbeatEventCounts = new Json(meteringStatusReport.getValue().getValue()).getMap().entrySet().stream().filter(status -> String.valueOf(status.getKey()).contains("heartbeatEventCount")).map(Entry::getValue).collect(Collectors.toList()).stream().map(countObject -> (Integer) countObject).collect(Collectors.toList());
        LOGGER.info(format("heartbeatEventCounts: %s", heartbeatEventCounts));
        Log.log(LOGGER, format(" Found '%s' Metering Heartbeat Events at '%s' instance. ", heartbeatEventCounts, meteringStatusReport.getKey()));
        if (CollectionUtils.isEmpty(heartbeatEventCounts) || heartbeatEventCounts.contains(0)) {
            LOGGER.error("Metering Heartbeat Events does NOT generated on '{}' instance!", meteringStatusReport.getKey());
            throw new TestFailException(format("Metering Heartbeat Events does NOT generated on '%s' instance!", meteringStatusReport.getKey()));
        }
    }
    for (Entry<String, Pair<Integer, String>> meteringStatusReport : meteringStatusReportByIp.entrySet()) {
        List<String> heartbeatStatusesNotOk = new Json(meteringStatusReport.getValue().getValue()).getMap().entrySet().stream().filter(status -> String.valueOf(status.getValue()).contains("NOK")).map(Entry::getKey).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(heartbeatStatusesNotOk)) {
            heartbeatStatusesNotOk.forEach(event -> {
                if (StringUtils.containsIgnoreCase(event, "databusReachable")) {
                    Log.log(LOGGER, format(" Found 'databusReachable' status is not OK at '%s' instance. However this is acceptable!", meteringStatusReport.getKey()));
                    LOGGER.warn("Found 'databusReachable' status is not OK at '{}' instance. However this is acceptable!", meteringStatusReport.getKey());
                } else {
                    Log.log(LOGGER, format(" Found '%s' not OK at '%s' instance. ", event, meteringStatusReport.getKey()));
                    LOGGER.error("There is 'Not OK' Metering Heartbeat status {} is present on '{}' instance!", event, meteringStatusReport.getKey());
                    throw new TestFailException(format("There is 'Not OK' Metering Heartbeat status %s is present on '%s' instance!", event, meteringStatusReport.getKey()));
                }
            });
        }
    }
    return testDto;
}
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) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) 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) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) 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) 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)

Aggregations

DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)16 Test (org.testng.annotations.Test)11 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)7 MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)7 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)7 TagsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.tags.TagsV4Response)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Description (com.sequenceiq.it.cloudbreak.context.Description)4 HashMap (java.util.HashMap)3 DistroXClusterTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.cluster.DistroXClusterTestDto)2 DistroXImageTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXImageTestDto)2 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)2 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)2 Log (com.sequenceiq.it.cloudbreak.log.Log)2 AbstractClouderaManagerTest (com.sequenceiq.it.cloudbreak.testcase.mock.clouderamanager.AbstractClouderaManagerTest)2 String.format (java.lang.String.format)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2