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());
}
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));
}
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());
}
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);
}
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));
}
Aggregations