Search in sources :

Example 1 with AddDnsARecordRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest in project cloudbreak by hortonworks.

the class FreeIpaUpgradeTests method addAndDeleteDnsARecord.

private void addAndDeleteDnsARecord(com.sequenceiq.freeipa.api.client.FreeIpaClient ipaClient, String environmentCrn) {
    try {
        AddDnsARecordRequest aRecordRequest = new AddDnsARecordRequest();
        aRecordRequest.setHostname("test-a-record");
        aRecordRequest.setCreateReverse(true);
        aRecordRequest.setEnvironmentCrn(environmentCrn);
        aRecordRequest.setIp("1.2.3.4");
        ipaClient.getDnsV1Endpoint().addDnsARecord(aRecordRequest);
        ipaClient.getDnsV1Endpoint().deleteDnsARecord(environmentCrn, null, aRecordRequest.getHostname());
    } catch (Exception e) {
        logger.error("DNS A record test failed during upgrade", e);
        throw new TestFailException("DNS A record test failed during upgrade with: " + e.getMessage(), e);
    }
}
Also used : AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) WebApplicationException(javax.ws.rs.WebApplicationException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 2 with AddDnsARecordRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest in project cloudbreak by hortonworks.

the class FreeIPAEndpointManagementServiceTest method testRegisterLoadBalancerWithIP.

@Test
public void testRegisterLoadBalancerWithIP() {
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setType(LoadBalancerType.PUBLIC);
    loadBalancer.setIp(LB_IP);
    loadBalancer.setEndpoint(LB_ENDPOINT);
    when(loadBalancerPersistenceService.findByStackId(any())).thenReturn(Set.of(loadBalancer));
    when(loadBalancerConfigService.selectLoadBalancerForFrontend(any(), any())).thenReturn(Optional.of(loadBalancer));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.registerLoadBalancerDomainWithFreeIPA(stack));
    ArgumentCaptor<AddDnsARecordRequest> requestCaptor = ArgumentCaptor.forClass(AddDnsARecordRequest.class);
    verify(dnsV1Endpoint, times(1)).addDnsARecordInternal(any(), requestCaptor.capture());
    assertEquals(LB_IP, requestCaptor.getValue().getIp());
    assertEquals(LB_ENDPOINT, requestCaptor.getValue().getHostname());
}
Also used : AddDnsARecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Test(org.junit.Test)

Example 3 with AddDnsARecordRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordExists.

@Test
public void testARecordExists() 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.setArecord(List.of(request.getIp()));
    dnsRecord.setIdnsname(request.getHostname());
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getHostname())).thenReturn(dnsRecord);
    underTest.addDnsARecord(ACCOUNT_ID, request);
    verify(freeIpaClient, times(0)).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
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 4 with AddDnsARecordRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordCreateReturnDuplicate.

@Test
public void testARecordCreateReturnDuplicate() 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.addDnsARecord(anyString(), eq(request.getHostname()), eq(request.getIp()), eq(true))).thenThrow(new FreeIpaClientException("Duplicate", new JsonRpcClientException(4002, "Duplicate reverse", null)));
    Assertions.assertThrows(DnsRecordConflictException.class, () -> underTest.addDnsARecord(ACCOUNT_ID, request));
}
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 5 with AddDnsARecordRequest

use of com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testARecordAddSameDomain.

@Test
public void testARecordAddSameDomain() throws FreeIpaClientException {
    AddDnsARecordRequest request = new AddDnsARecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setHostname("Asdf");
    request.setIp("1.1.1.2");
    request.setDnsZone(DOMAIN);
    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);
    underTest.addDnsARecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsARecord(request.getDnsZone(), request.getHostname(), request.getIp(), request.isCreateReverse());
}
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)

Aggregations

AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)13 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)10 Stack (com.sequenceiq.freeipa.entity.Stack)10 Test (org.junit.jupiter.api.Test)10 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)3 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 DnsRecord (com.sequenceiq.freeipa.client.model.DnsRecord)3 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.Test)1