Search in sources :

Example 66 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testClusterProxyRegistrationWhenCCMV2OrJumpgate.

@ParameterizedTest
@EnumSource(value = Tunnel.class, names = { "CCMV2", "CCMV2_JUMPGATE" }, mode = EnumSource.Mode.INCLUDE)
public void testClusterProxyRegistrationWhenCCMV2OrJumpgate(Tunnel ccmv2Mode) {
    Stack aStack = getAStack();
    aStack.setTunnel(ccmv2Mode);
    aStack.setCcmV2AgentCrn("testAgentCrn");
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    GatewayConfig gatewayConfig = new GatewayConfig("connectionAddress", "publicIpAddress", PRIVATE_IP_ADDRESS, ServiceFamilies.GATEWAY.getDefaultPort(), "testInstanceId", true);
    ConfigRegistrationResponse configRegResponse = mock(ConfigRegistrationResponse.class);
    when(stackService.getStackById(STACK_ID)).thenReturn(aStack);
    when(clusterProxyEnablementService.isClusterProxyApplicable(any())).thenReturn(true);
    when(gatewayConfigService.getPrimaryGatewayConfig(aStack)).thenReturn(gatewayConfig);
    when(securityConfigService.findOneByStack(aStack)).thenReturn(null);
    when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(configRegResponse);
    when(stackUpdater.updateClusterProxyRegisteredFlag(aStack, true)).thenReturn(aStack);
    when(freeIpaService.findByStack(aStack)).thenReturn(freeIpa);
    underTest.registerFreeIpaForBootstrap(STACK_ID);
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_RESOURCE_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertFalse(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should not be enabled");
    assertTrue(proxyRegistrationReq.isUseCcmV2(), ccmv2Mode + " should be enabled.");
    assertEquals(List.of(new CcmV2Config("testAgentCrn", PRIVATE_IP_ADDRESS, ServiceFamilies.GATEWAY.getDefaultPort(), "testAgentCrn-testInstanceId", FREEIPA_SERVICE)), proxyRegistrationReq.getCcmV2Configs(), ccmv2Mode + " config should match");
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://privateIpAddress:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.ipadom", List.of("https://privateIpAddress:9443"), List.of(), null));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) CcmV2Config(com.sequenceiq.cloudbreak.clusterproxy.CcmV2Config) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testGetPathWithStackWithServiceNameNotRegistered.

@Test
public void testGetPathWithStackWithServiceNameNotRegistered() {
    when(clusterProxyConfiguration.getClusterProxyBasePath()).thenReturn("basePath");
    Stack stack = getAStack();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    ReadConfigResponse readConfigResponse = new ReadConfigResponse();
    readConfigResponse.setServices(List.of());
    when(clusterProxyRegistrationClient.readConfig(STACK_RESOURCE_CRN)).thenReturn(readConfigResponse);
    String result = underTest.getProxyPath(stack, Optional.of("unregistered"));
    assertEquals("basePath/proxy/resourceCrn/freeipa.ipadom", result);
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ReadConfigResponse(com.sequenceiq.cloudbreak.clusterproxy.ReadConfigResponse) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 68 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testGetPathWithStackWithServiceNameNotRegisteredWithEmptyServices.

@Test
public void testGetPathWithStackWithServiceNameNotRegisteredWithEmptyServices() {
    when(clusterProxyConfiguration.getClusterProxyBasePath()).thenReturn("basePath");
    Stack stack = getAStack();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    ReadConfigResponse readConfigResponse = new ReadConfigResponse();
    when(clusterProxyRegistrationClient.readConfig(STACK_RESOURCE_CRN)).thenReturn(readConfigResponse);
    String result = underTest.getProxyPath(stack, Optional.of("unregistered"));
    assertEquals("basePath/proxy/resourceCrn/freeipa.ipadom", result);
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ReadConfigResponse(com.sequenceiq.cloudbreak.clusterproxy.ReadConfigResponse) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 69 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class ClusterProxyServiceTest method testClusterProxyRegistrationWhenCCMV1.

@Test
public void testClusterProxyRegistrationWhenCCMV1() {
    Stack aStack = getAStack();
    aStack.setTunnel(Tunnel.CCM);
    aStack.setMinaSshdServiceId("minaSshdServiceId");
    GatewayConfig gatewayConfig = new GatewayConfig("connectionAddress", "publicAddress", PRIVATE_ADDRESS, 9443, "instanceId", false);
    ConfigRegistrationResponse configRegResponse = mock(ConfigRegistrationResponse.class);
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain("ipadom");
    when(stackService.getStackById(STACK_ID)).thenReturn(aStack);
    when(clusterProxyEnablementService.isClusterProxyApplicable(any())).thenReturn(true);
    when(gatewayConfigService.getPrimaryGatewayConfig(aStack)).thenReturn(gatewayConfig);
    when(securityConfigService.findOneByStack(aStack)).thenReturn(null);
    when(clusterProxyRegistrationClient.registerConfig(any())).thenReturn(configRegResponse);
    when(stackUpdater.updateClusterProxyRegisteredFlag(aStack, true)).thenReturn(aStack);
    when(freeIpaService.findByStack(aStack)).thenReturn(freeIpa);
    underTest.registerFreeIpaForBootstrap(STACK_ID);
    ArgumentCaptor<ConfigRegistrationRequest> captor = ArgumentCaptor.forClass(ConfigRegistrationRequest.class);
    verify(clusterProxyRegistrationClient).registerConfig(captor.capture());
    ConfigRegistrationRequest proxyRegistrationReq = captor.getValue();
    assertThat(proxyRegistrationReq.getClusterCrn()).isEqualTo(STACK_RESOURCE_CRN);
    assertThat(proxyRegistrationReq.getAccountId()).isEqualTo(TEST_ACCOUNT_ID);
    assertFalse(proxyRegistrationReq.isUseCcmV2(), "CCMV2 should not be enabled.");
    assertTrue(proxyRegistrationReq.isUseTunnel(), "CCMV1 tunnel should be enabled");
    assertEquals(List.of(new TunnelEntry("instanceId", "GATEWAY", PRIVATE_ADDRESS, 9443, "minaSshdServiceId")), proxyRegistrationReq.getTunnels(), "CCMV1 tunnel should be configured.");
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa", List.of("https://privateAddress:9443"), List.of(), null));
    assertThat(proxyRegistrationReq.getServices()).contains(new ClusterServiceConfig("freeipa.ipadom", List.of("https://privateAddress:9443"), List.of(), null));
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) ClusterServiceConfig(com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig) ConfigRegistrationRequest(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) TunnelEntry(com.sequenceiq.cloudbreak.clusterproxy.TunnelEntry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 70 with FreeIpa

use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.

the class StackToCreateFreeIpaRequestConverter method getFreeIpaServerRequest.

private FreeIpaServerRequest getFreeIpaServerRequest(Stack stack) {
    FreeIpaServerRequest request = new FreeIpaServerRequest();
    FreeIpa freeIpa = freeIpaService.findByStack(stack);
    if (freeIpa != null) {
        request.setAdminGroupName(freeIpa.getAdminGroupName());
        request.setAdminPassword(freeIpa.getAdminPassword());
        request.setDomain(freeIpa.getDomain());
        request.setHostname(freeIpa.getHostname());
    }
    LOGGER.debug("Created FreeIPA server request {} from FreeIPA {}", request, freeIpa);
    return request;
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) FreeIpaServerRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)

Aggregations

FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)75 Stack (com.sequenceiq.freeipa.entity.Stack)62 Test (org.junit.jupiter.api.Test)50 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)10 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)10 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)10 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)8 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)7 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)6 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)6 DnsRecord (com.sequenceiq.freeipa.client.model.DnsRecord)6 Set (java.util.Set)6 ClusterServiceConfig (com.sequenceiq.cloudbreak.clusterproxy.ClusterServiceConfig)5 ConfigRegistrationRequest (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationRequest)5 ConfigRegistrationResponse (com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse)5 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)5 Optional (java.util.Optional)5