Search in sources :

Example 31 with FreeIpa

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

the class DnsRecordServiceTest method testDeleteIgnoreNotFound.

@Test
public void testDeleteIgnoreNotFound() throws FreeIpaClientException {
    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.deleteDnsRecord("asdf", DOMAIN)).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
    underTest.deleteDnsRecord(ACCOUNT_ID, ENV_CRN, null, "asdf");
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 32 with FreeIpa

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

the class KerberosConfigRegisterServiceTest method testRegister.

@Test
void testRegister() {
    Stack stack = new Stack();
    stack.setEnvironmentCrn("env");
    stack.setAccountId("acc");
    stack.setName("name");
    stack.setAppVersion("2.20.0");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN("fqdn");
    instanceMetaData.setPrivateIp("1.1.1.1");
    instanceGroup.setInstanceMetaData(Collections.singleton(instanceMetaData));
    stack.setInstanceGroups(Collections.singleton(instanceGroup));
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("testdomain.local");
    freeIpa.setAdminPassword("asdf");
    when(freeIpaService.findByStackId(anyLong())).thenReturn(freeIpa);
    when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
    underTest.register(1L);
    ArgumentCaptor<KerberosConfig> kerberosConfigArgumentCaptor = ArgumentCaptor.forClass(KerberosConfig.class);
    ArgumentCaptor<String> accountIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(kerberosConfigService).createKerberosConfig(kerberosConfigArgumentCaptor.capture(), accountIdArgumentCaptor.capture());
    assertEquals(stack.getAccountId(), accountIdArgumentCaptor.getValue());
    KerberosConfig kerberosConfig = kerberosConfigArgumentCaptor.getValue();
    assertEquals(stack.getName(), kerberosConfig.getName());
    assertEquals(stack.getEnvironmentCrn(), kerberosConfig.getEnvironmentCrn());
    assertEquals("kdc.testdomain.local", kerberosConfig.getUrl());
    assertEquals("kerberos.testdomain.local", kerberosConfig.getAdminUrl());
    assertEquals(instanceMetaData.getPrivateIp(), kerberosConfig.getNameServers());
    assertEquals(freeIpa.getAdminPassword(), kerberosConfig.getPassword());
    assertEquals(freeIpa.getDomain(), kerberosConfig.getDomain());
    assertEquals(freeIpa.getDomain().toUpperCase(), kerberosConfig.getRealm());
    assertEquals(KerberosType.FREEIPA, kerberosConfig.getType());
    assertEquals(KerberosConfigRegisterService.FREEIPA_DEFAULT_ADMIN, kerberosConfig.getPrincipal());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 33 with FreeIpa

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

the class FreeIpaClientFactoryTest method getFreeIpaClientForStackShouldReturnClientWhenStackStatusIsValid.

@Test
void getFreeIpaClientForStackShouldReturnClientWhenStackStatusIsValid() throws FreeIpaClientException {
    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);
    when(clusterProxyService.isCreateConfigForClusterProxy(stack)).thenReturn(false);
    FreeIpaClientException exception = Assertions.assertThrows(FreeIpaClientException.class, () -> underTest.getFreeIpaClientForStack(stack));
    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 34 with FreeIpa

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

the class FreeIpaClientFactoryTest method getFreeIpaClientForStackForLegacyHealthCheckShouldReturnClientWhenStackStatusIsUnreachable.

@Test
void getFreeIpaClientForStackForLegacyHealthCheckShouldReturnClientWhenStackStatusIsUnreachable() {
    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.FREEIPA_UNREACHABLE_STATUSES.stream().findAny().get();
    StackStatus stackStatus = new StackStatus(stack, unreachableState, "The FreeIPA instance is unreachable.", DetailedStackStatus.UNREACHABLE);
    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 35 with FreeIpa

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

the class FreeIpaToListFreeIpaResponseConverterTest method createFreeIpa.

private FreeIpa createFreeIpa(String domain, Stack stack) {
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain(domain);
    freeIpa.setStack(stack);
    return freeIpa;
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa)

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