Search in sources :

Example 6 with Host

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

the class HostDeletionServiceTest method testOneFailedDeletion.

@Test
public void testOneFailedDeletion() 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"));
    Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
    assertEquals(1, result.getFirst().size());
    assertEquals(1, result.getSecond().size());
    assertTrue(result.getFirst().contains(host1.getFqdn()));
    assertTrue(result.getSecond().keySet().contains(host2.getFqdn()));
    assertTrue(result.getSecond().values().contains("not handled"));
}
Also used : Set(java.util.Set) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) Map(java.util.Map) Test(org.junit.Test)

Example 7 with Host

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

the class HostDeletionServiceTest method successfulDeletionIfAllHostReturned.

@Test
public void successfulDeletionIfAllHostReturned() 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));
    Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
    assertTrue(result.getSecond().isEmpty());
    assertEquals(2, result.getFirst().size());
    assertTrue(result.getFirst().contains(host1.getFqdn()));
    assertTrue(result.getFirst().contains(host2.getFqdn()));
    verify(freeIpaClient).deleteHost(eq("host1"));
    verify(freeIpaClient).deleteHost(eq("host2"));
}
Also used : Set(java.util.Set) Host(com.sequenceiq.freeipa.client.model.Host) Map(java.util.Map) Test(org.junit.Test)

Example 8 with Host

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

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleRaceCondition.

@Test
public void testAddRoleAndPrivilegesForHostWithRoleRaceCondition() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Mockito.when(mockIpaClient.addRole(anyString())).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(FreeIpaErrorCodes.DUPLICATE_ENTRY.getValue(), "duplicate", null)));
    Privilege privilege = new Privilege();
    Set<String> hosts = new HashSet<>();
    hosts.add(HOST);
    Set<String> noServices = new HashSet<>();
    Mockito.when(mockIpaClient.showRole(roleRequest.getRoleName())).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(role);
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRole(ROLE);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with Host

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

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleThatAlreadyExists.

@Test
public void testAddRoleAndPrivilegesForHostWithRoleThatAlreadyExists() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Privilege privilege = new Privilege();
    Set<String> hosts = new HashSet<>();
    hosts.add(HOST);
    Set<String> noServices = new HashSet<>();
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.showRole(anyString())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 10 with Host

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

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithoutRole.

@Test
public void testAddRoleAndPrivilegesForHostWithoutRole() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = null;
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verifyNoInteractions(mockIpaClient);
}
Also used : Host(com.sequenceiq.freeipa.client.model.Host) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Host (com.sequenceiq.freeipa.client.model.Host)25 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)13 Test (org.junit.jupiter.api.Test)13 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)12 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)10 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)5 Role (com.sequenceiq.freeipa.client.model.Role)5 KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)5 Set (java.util.Set)5 Test (org.junit.Test)5 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)4 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)4 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)4 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)4 Privilege (com.sequenceiq.freeipa.client.model.Privilege)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Optional (java.util.Optional)4