use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHost.
@Test
public void testAddHost() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null)));
when(ipaClient.addHost(HOST)).thenReturn(host);
Host result = underTest.addHost(HOST, roleRequest, ipaClient);
verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
assertTrue(serviceCaptor.getValue().isEmpty());
assertEquals(host, hostCaptor.getValue().get());
assertEquals(host, result);
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHostAlreadyExists.
@Test
public void testAddHostAlreadyExists() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(HOST)).thenReturn(host);
Host result = underTest.addHost(HOST, roleRequest, ipaClient);
verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
assertTrue(serviceCaptor.getValue().isEmpty());
assertEquals(host, hostCaptor.getValue().get());
assertEquals(host, result);
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testAddHostDuplicateEntry.
@Test
public void testAddHostDuplicateEntry() throws FreeIpaClientException {
FreeIpaClient ipaClient = mock(FreeIpaClient.class);
RoleRequest roleRequest = new RoleRequest();
Host host = new Host();
when(ipaClient.showHost(HOST)).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(host);
when(ipaClient.addHost(HOST)).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(DUPLICATE_ENTRY.getValue(), "duplicate", null)));
Host result = underTest.addHost(HOST, roleRequest, ipaClient);
verify(ipaClient).allowHostKeytabRetrieval(HOST, FreeIpaClientFactory.ADMIN_USER);
ArgumentCaptor<Optional<Service>> serviceCaptor = ArgumentCaptor.forClass(Optional.class);
ArgumentCaptor<Optional<Host>> hostCaptor = ArgumentCaptor.forClass(Optional.class);
verify(roleComponent).addRoleAndPrivileges(serviceCaptor.capture(), hostCaptor.capture(), eq(roleRequest), eq(ipaClient));
assertTrue(serviceCaptor.getValue().isEmpty());
assertEquals(host, hostCaptor.getValue().get());
assertEquals(host, result);
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class HostDeletionServiceTest method expectDeleteExceptionWhenOneFailedDeletion.
@Test(expected = DeleteException.class)
public void expectDeleteExceptionWhenOneFailedDeletion() throws FreeIpaClientException {
Set<String> hosts = Set.of("host1", "host2");
Host host1 = new Host();
host1.setFqdn("host1");
Host host2 = new Host();
host2.setFqdn("host2");
when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException("not handled"));
underTest.deleteHostsWithDeleteException(freeIpaClient, hosts);
}
use of com.sequenceiq.freeipa.client.model.Host in project cloudbreak by hortonworks.
the class HostDeletionServiceTest method testOneAlreadyDeleted.
@Test
public void testOneAlreadyDeleted() throws FreeIpaClientException {
Set<String> hosts = Set.of("host1", "host2");
Host host1 = new Host();
host1.setFqdn("host1");
Host host2 = new Host();
host2.setFqdn("host2");
when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
String message = "already deleted";
when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException(message, new JsonRpcClientException(NOT_FOUND, message, null)));
Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
assertEquals(2, result.getFirst().size());
assertEquals(0, result.getSecond().size());
assertTrue(result.getFirst().contains(host1.getFqdn()));
assertTrue(result.getFirst().contains(host2.getFqdn()));
}
Aggregations