Search in sources :

Example 6 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class CleanupServiceTest method testRemoveDnsEntries.

@Test
public void testRemoveDnsEntries() throws FreeIpaClientException {
    FreeIpaClient client = mock(FreeIpaClient.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(STACK_ID)).thenReturn(client);
    DnsZone dnsZone = new DnsZone();
    String domain = "test.com";
    dnsZone.setIdnsname(domain);
    DnsZone reverseZone = new DnsZone();
    reverseZone.setIdnsname("0.10.in-addr.arpa.");
    DnsZone disappearingZone = new DnsZone();
    disappearingZone.setIdnsname("disappear");
    when(client.findAllDnsZone()).thenReturn(Set.of(dnsZone, reverseZone, disappearingZone));
    DnsRecord deleteMe = new DnsRecord();
    deleteMe.setIdnsname("deleteMe");
    deleteMe.setArecord(List.of("ignored"));
    DnsRecord notFound = new DnsRecord();
    notFound.setIdnsname("notfound");
    notFound.setArecord(List.of("ignored"));
    DnsRecord failed = new DnsRecord();
    failed.setIdnsname("failed");
    failed.setArecord(List.of("ignored"));
    DnsRecord ptrRecord = new DnsRecord();
    ptrRecord.setIdnsname("1.0");
    ptrRecord.setPtrrecord(List.of("ptrRecord"));
    when(client.findAllDnsRecordInZone(dnsZone.getIdnsname())).thenReturn(Set.of(deleteMe, notFound, failed));
    when(client.deleteDnsRecord(failed.getIdnsname(), domain)).thenThrow(new FreeIpaClientException("delete failed"));
    when(client.deleteDnsRecord(notFound.getIdnsname(), domain)).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
    when(client.findAllDnsRecordInZone(reverseZone.getIdnsname())).thenReturn(Set.of(ptrRecord));
    when(client.findAllDnsRecordInZone(disappearingZone.getIdnsname())).thenThrow(new FreeIpaClientException("Not found zone", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
    Pair<Set<String>, Map<String, String>> result = cleanupService.removeDnsEntries(STACK_ID, Set.of(deleteMe.getIdnsname(), notFound.getIdnsname(), failed.getIdnsname(), "ptrRecord"), Set.of("10.0.0.1", "10.1.0.1"), domain);
    verify(client).deleteDnsRecord(deleteMe.getIdnsname(), domain);
    assertTrue(result.getFirst().containsAll(Set.of(deleteMe.getIdnsname(), notFound.getIdnsname(), "10.0.0.1")));
    assertTrue(result.getSecond().containsKey(failed.getIdnsname()));
    assertEquals("delete failed", result.getSecond().get(failed.getIdnsname()));
    assertEquals(1, result.getSecond().size());
    assertEquals(3, result.getFirst().size());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Set(java.util.Set) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) Map(java.util.Map) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Test(org.junit.Test)

Example 7 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord 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 8 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testCnameRecordExists.

@Test
public void testCnameRecordExists() throws FreeIpaClientException {
    AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setCname("Asdf");
    request.setTargetFqdn(TARGET_FQDN);
    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.setCnamerecord(List.of(request.getTargetFqdn()));
    dnsRecord.setIdnsname(request.getCname());
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getCname())).thenReturn(dnsRecord);
    underTest.addDnsCnameRecord(ACCOUNT_ID, request);
    verify(freeIpaClient, times(0)).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 9 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method createDnsRecords.

private Set<DnsRecord> createDnsRecords() {
    DnsRecord dnsRecord = new DnsRecord();
    dnsRecord.setIdnsname("www.example.com");
    dnsRecord.setPtrrecord(List.of("www.example.com."));
    DnsRecord srvRecord = new DnsRecord();
    srvRecord.setIdnsname("foo.example.com");
    srvRecord.setSrvrecord(SRV_RECORDS);
    return Set.of(dnsRecord, srvRecord);
}
Also used : DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord)

Example 10 with DnsRecord

use of com.sequenceiq.freeipa.client.model.DnsRecord in project cloudbreak by hortonworks.

the class DnsRecordServiceTest method testCnameRecordExistsNotCname.

@Test
public void testCnameRecordExistsNotCname() throws FreeIpaClientException {
    AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setCname("Asdf");
    request.setTargetFqdn(TARGET_FQDN);
    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.getCname());
    when(freeIpaClient.showDnsRecord(DOMAIN, request.getCname())).thenReturn(dnsRecord);
    Assertions.assertThrows(DnsRecordConflictException.class, () -> underTest.addDnsCnameRecord(ACCOUNT_ID, request));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

DnsRecord (com.sequenceiq.freeipa.client.model.DnsRecord)14 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)8 Stack (com.sequenceiq.freeipa.entity.Stack)8 Test (org.junit.jupiter.api.Test)6 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)5 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)5 DnsZone (com.sequenceiq.freeipa.client.model.DnsZone)4 Measure (com.sequenceiq.cloudbreak.aspect.Measure)3 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)3 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 Set (java.util.Set)3 Retryable (org.springframework.retry.annotation.Retryable)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)2 FreeIpaClientExceptionUtil (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil)2 FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreEmptyModExceptionWithValue)2 FreeIpaClientExceptionUtil.ignoreNotFoundException (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundException)2 FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue (com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue)2 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)2 FreeIpaClientFactory (com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory)2