Search in sources :

Example 16 with FreeIpa

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

the class DnsRecordServiceTest method testARecordExistsDifferentValue.

@Test
public void testARecordExistsDifferentValue() 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.setArecord(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 17 with FreeIpa

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

the class DnsRecordServiceTest method testCnameRecordAddEmptyModListIgnored.

@Test
public void testCnameRecordAddEmptyModListIgnored() 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);
    JsonRpcClientException noModEx = new JsonRpcClientException(FreeIpaErrorCodes.EMPTY_MODLIST.getValue(), "no modifications to be performed", null);
    when(freeIpaClient.addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn())).thenThrow(new FreeIpaClientException("can't create", noModEx));
    underTest.addDnsCnameRecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 18 with FreeIpa

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

the class DnsRecordServiceTest method testCnameRecordAddSameDomain.

@Test
public void testCnameRecordAddSameDomain() throws FreeIpaClientException {
    AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
    request.setEnvironmentCrn(ENV_CRN);
    request.setCname("Asdf");
    request.setTargetFqdn(TARGET_FQDN);
    request.setDnsZone(DOMAIN);
    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);
    underTest.addDnsCnameRecord(ACCOUNT_ID, request);
    verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
Also used : FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) AddDnsCnameRecordRequest(com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 19 with FreeIpa

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

the class CcmUserDataServiceTest method testFetchAndSaveCcmParametersWhenCcmV2IsEnabled.

@Test
void testFetchAndSaveCcmParametersWhenCcmV2IsEnabled() {
    Stack stack = getAStack();
    stack.setTunnel(Tunnel.CCMV2);
    DefaultCcmV2Parameters defaultCcmV2Parameters = mock(DefaultCcmV2Parameters.class);
    FreeIpa freeIpa = mock(FreeIpa.class);
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    when(freeIpa.getDomain()).thenReturn("cldr.work.site");
    when(ccmV2ParameterSupplier.getCcmV2Parameters(anyString(), any(Optional.class), anyString(), anyString())).thenReturn(defaultCcmV2Parameters);
    when(defaultCcmV2Parameters.getAgentCrn()).thenReturn("testAgentCrn");
    when(hostDiscoveryService.determineGatewayFqdn(any(), any())).thenReturn("datahub.master0.cldr.work.site");
    CcmConnectivityParameters ccmParameters = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.fetchAndSaveCcmParameters(stack));
    assertEquals(CcmConnectivityMode.CCMV2, ccmParameters.getConnectivityMode(), "CCM V2 should be enabled.");
    assertEquals(defaultCcmV2Parameters, ccmParameters.getCcmV2Parameters(), "CCM V2 Parameters should match.");
    verify(ccmV2ParameterSupplier, times(1)).getCcmV2Parameters(anyString(), any(Optional.class), anyString(), anyString());
    verifyNoInteractions(ccmParameterSupplier);
    verify(stackService, times(1)).setCcmV2AgentCrnByStackId(100L, "testAgentCrn");
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) Optional(java.util.Optional) DefaultCcmV2Parameters(com.sequenceiq.cloudbreak.ccm.cloudinit.DefaultCcmV2Parameters) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 20 with FreeIpa

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

the class InstanceMetaDataServiceTest method testSaveInstanceAndGetUpdatedStackWhenNoAvailabilityZoneDataAvailable.

@Test
public void testSaveInstanceAndGetUpdatedStackWhenNoAvailabilityZoneDataAvailable() {
    Stack stack = initializeStackWithInstanceGroup();
    InstanceGroup instanceGroup = stack.getInstanceGroups().stream().findFirst().get();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setHostname("ipa");
    freeIpa.setDomain("dom");
    when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
    InstanceTemplate template = mock(InstanceTemplate.class);
    when(template.getGroupName()).thenReturn(GROUP_NAME);
    when(template.getPrivateId()).thenReturn(INSTANCE_PRIVATE_ID_3);
    List<CloudInstance> cloudInstances = List.of(new CloudInstance(INSTANCE_ID_3, template, null, "subnet-1", "az1"));
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    when(cachedEnvironmentClientService.getByCrn(ENVIRONMENT_ID)).thenReturn(environmentResponse);
    Map<String, String> subnetAzMap = Map.of();
    when(multiAzCalculatorService.prepareSubnetAzMap(environmentResponse)).thenReturn(subnetAzMap);
    Map<String, Integer> subnetUsage = Map.of();
    when(multiAzCalculatorService.calculateCurrentSubnetUsage(subnetAzMap, instanceGroup)).thenReturn(subnetUsage);
    Stack actualStack = underTest.saveInstanceAndGetUpdatedStack(stack, cloudInstances);
    verify(instanceMetaDataRepository).save(any());
    assertEquals(3, actualStack.getAllInstanceMetaDataList().size());
    InstanceGroup actualInstanceGroup = actualStack.getInstanceGroups().stream().filter(ig -> GROUP_NAME.equals(ig.getGroupName())).findFirst().get();
    InstanceMetaData instanceMetaData = actualInstanceGroup.getInstanceMetaData().stream().filter(im -> INSTANCE_PRIVATE_ID_3 == im.getPrivateId()).findFirst().get();
    assertEquals("ipa3.dom", instanceMetaData.getDiscoveryFQDN());
    verify(multiAzCalculatorService, times(0)).filterSubnetByLeastUsedAz(actualInstanceGroup, subnetAzMap);
    verify(multiAzCalculatorService, times(0)).updateSubnetIdForSingleInstanceIfEligible(subnetAzMap, subnetUsage, instanceMetaData, actualInstanceGroup);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Test(org.junit.jupiter.api.Test)

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