Search in sources :

Example 46 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class FreeIpaClientFactoryTest method getFreeIpaClientForStackForLegacyHealthCheckShouldReturnClientWhenStackStatusIsValid.

@Test
void getFreeIpaClientForStackForLegacyHealthCheckShouldReturnClientWhenStackStatusIsValid() {
    Stack stack = createStack();
    stack.setGatewayport(80);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setAdminPassword(new Secret("", ""));
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(stackService.getByIdWithListsInTransaction(stack.getId())).thenReturn(stack);
    when(tlsSecurityService.buildTLSClientConfig(any(), any(), any())).thenReturn(new HttpClientConfig(FREEIPP_FQDN));
    Status unreachableState = Status.AVAILABLE;
    StackStatus stackStatus = new StackStatus(stack, unreachableState, "The FreeIPA instance is reachable.", DetailedStackStatus.AVAILABLE);
    stack.setStackStatus(stackStatus);
    FreeIpaClientException exception = Assertions.assertThrows(FreeIpaClientException.class, () -> underTest.getFreeIpaClientForStackForLegacyHealthCheck(stack, FREEIPP_FQDN));
    verify(clusterProxyService, times(1)).isCreateConfigForClusterProxy(stack);
    verify(tlsSecurityService, times(1)).buildTLSClientConfig(any(), any(), any());
    Assertions.assertEquals(FreeIpaClientException.class, exception.getCause().getClass());
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) StackStatus(com.sequenceiq.freeipa.entity.StackStatus) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 47 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordExistsNotA.

@Test
public void testARecordExistsNotA() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setCreateReverse(true);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    DnsRecord dnsRecord = new DnsRecord();
    dnsRecord.setPtrrecord(List.of("asdf"));
    dnsRecord.setIdnsname(request.getHostname());
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getHostname())).thenReturn(dnsRecord);
    Assertions.assertThrows(DnsRecordConflictException.class, () -> underTest.addDnsARecord(ACCOUNT_ID, request));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 48 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordAddEmptyModListIgnored.

@Test
public void testARecordAddEmptyModListIgnored() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setCreateReverse(true);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    JsonRpcClientException noModEx = new JsonRpcClientException(FreeIpaErrorCodes.EMPTY_MODLIST.getValue(), "no modifications to be performed", null);
    when(freeIpaClient.addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse())).thenThrow(new FreeIpaClientException("can't create", noModEx));
    underTest.addDnsARecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 49 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordAddDifferentDomainMissing.

@Test
public void testARecordAddDifferentDomainMissing() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setDnsZone(DOMAIN2);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    when(freeIpaClient.findAllDnsZone()).thenReturn(createDnsZones(DOMAIN));
    Assertions.assertThrows(BadRequestException.class, () -> underTest.addDnsARecord(ACCOUNT_ID, request));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 50 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordAddNotFound.

@Test
public void testARecordAddNotFound() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setCreateReverse(true);
    Stack stack = createStack();
    when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
    FreeIpa freeIpa = createFreeIpa();
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getHostname())).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
    underTest.addDnsARecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)75 Stack (com.sequenceiq.freeipa.entity.Stack)62 Test (org.junit.jupiter.api.Test)50 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)10 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)10 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)10 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)8 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)7 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)6 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)6 DnsRecord (com.sequenceiq.freeipa.client.model.DnsRecord)6 Set (java.util.Set)6 ClusterServiceConfig (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig)5 ConfigRegistrationRequest (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest)5 ConfigRegistrationResponse (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse)5 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)5 Optional (java.util.Optional)5