use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testRealm.
@Test
public void testRealm() {
Stack stack = new Stack();
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
String result = underTest.getRealm(stack);
assertEquals(DOMAIN.toUpperCase(), result);
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class KeytabCommonServiceTest method testRealmMissingDomain.
@Test
public void testRealmMissingDomain() {
Stack stack = new Stack();
FreeIpa freeIpa = new FreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
assertThrows(KeytabCreationException.class, () -> underTest.getRealm(stack));
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class BootstrapServiceTest method testBootstrapWithInstanceIds.
@Test
public void testBootstrapWithInstanceIds() throws CloudbreakOrchestratorException, IOException {
when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain"), createInstance("filterMe", "filtered" + DOMAIN)));
Stack stack = new Stack();
stack.setCloudPlatform("cloud");
when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
freeIpa.setHostname(HOSTNAME);
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
List<GatewayConfig> gatewayConfigs = List.of();
when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
byte[] bytes = {};
when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenReturn(bytes);
ImageEntity image = new ImageEntity();
image.setOs("ZOS");
when(imageService.getByStack(stack)).thenReturn(image);
when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
underTest.bootstrap(STACK_ID, List.of(INSTANCE_WITH_FQDN, INSTANCE_WO_FQDN, INSTANCE_WRONG_DOMAIN));
ArgumentCaptor<Set<Node>> targetCaptor = ArgumentCaptor.forClass((Class) Set.class);
ArgumentCaptor<Set<Node>> allCaptor = ArgumentCaptor.forClass((Class) Set.class);
ArgumentCaptor<BootstrapParams> bootstrapParamsCaptor = ArgumentCaptor.forClass(BootstrapParams.class);
ArgumentCaptor<ExitCriteriaModel> exitCriteriaModelCaptor = ArgumentCaptor.forClass(ExitCriteriaModel.class);
verify(hostOrchestrator).bootstrapNewNodes(eq(gatewayConfigs), targetCaptor.capture(), allCaptor.capture(), eq(bytes), bootstrapParamsCaptor.capture(), exitCriteriaModelCaptor.capture());
Set<Node> targetNodes = targetCaptor.getValue();
Set<Node> allNodes = allCaptor.getValue();
assertEquals(targetNodes, allNodes);
assertEquals(3, allNodes.size());
assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WITH_FQDN)), hasProperty("hostname", is("instance1")), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WO_FQDN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WRONG_DOMAIN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
BootstrapParams bootstrapParams = bootstrapParamsCaptor.getValue();
assertTrue(bootstrapParams.isSaltBootstrapFpSupported());
assertTrue(bootstrapParams.isRestartNeededFlagSupported());
assertEquals(image.getOs(), bootstrapParams.getOs());
assertEquals(stack.getCloudPlatform(), bootstrapParams.getCloud());
StackBasedExitCriteriaModel exitCriteriaModel = (StackBasedExitCriteriaModel) exitCriteriaModelCaptor.getValue();
assertEquals(STACK_ID, exitCriteriaModel.getStackId().get());
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class BootstrapServiceTest method testIOExceptionConverted.
@Test
public void testIOExceptionConverted() throws CloudbreakOrchestratorException, IOException {
when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain")));
Stack stack = new Stack();
stack.setCloudPlatform("cloud");
when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
freeIpa.setHostname(HOSTNAME);
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
List<GatewayConfig> gatewayConfigs = List.of();
when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
byte[] bytes = {};
when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenReturn(bytes);
ImageEntity image = new ImageEntity();
image.setOs("ZOS");
when(imageService.getByStack(stack)).thenReturn(image);
when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
doThrow(new CloudbreakOrchestratorCancelledException("wow")).when(hostOrchestrator).bootstrapNewNodes(any(), anySet(), anySet(), any(), any(), any());
assertThrows(CloudbreakOrchestratorException.class, () -> underTest.bootstrap(STACK_ID));
}
use of com.sequenceiq.freeipa.entity.FreeIpa in project cloudbreak by hortonworks.
the class LdapConfigRegisterServiceTest method testRegister.
@Test
void testRegister() {
Stack stack = new Stack();
stack.setEnvironmentCrn("env");
stack.setAccountId("acc");
stack.setName("name");
stack.setAppVersion("2.20.0");
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setInstanceGroupType(InstanceGroupType.MASTER);
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setDiscoveryFQDN("fqdn");
instanceMetaData.setPrivateIp("1.1.1.1");
instanceGroup.setInstanceMetaData(Collections.singleton(instanceMetaData));
stack.setInstanceGroups(Collections.singleton(instanceGroup));
when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain("testdomain.local");
freeIpa.setAdminPassword("asdf");
when(freeIpaService.findByStackId(anyLong())).thenReturn(freeIpa);
when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
underTest.register(1L);
ArgumentCaptor<LdapConfig> ldapConfigArgumentCaptor = ArgumentCaptor.forClass(LdapConfig.class);
ArgumentCaptor<String> accountIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
verify(ldapConfigService).createLdapConfig(ldapConfigArgumentCaptor.capture(), accountIdArgumentCaptor.capture());
assertEquals(stack.getAccountId(), accountIdArgumentCaptor.getValue());
LdapConfig ldapConfig = ldapConfigArgumentCaptor.getValue();
assertEquals(ldapConfig.getName(), stack.getName());
assertEquals(ldapConfig.getEnvironmentCrn(), stack.getEnvironmentCrn());
String domainComponent = ",dc=testdomain,dc=local";
assertEquals(ldapConfig.getBindDn(), BIND_DN + domainComponent);
assertEquals(ldapConfig.getUserSearchBase(), USER_SEARCH_BASE + domainComponent);
assertEquals(ldapConfig.getGroupSearchBase(), GROUP_SEARCH_BASE + domainComponent);
assertEquals(ldapConfig.getUserDnPattern(), USER_DN_PATTERN + domainComponent);
assertEquals(ldapConfig.getServerHost(), "ldap.testdomain.local");
assertEquals(ldapConfig.getProtocol(), PROTOCOL);
assertEquals(ldapConfig.getServerPort(), SERVER_PORT);
assertEquals(ldapConfig.getDomain(), freeIpa.getDomain());
assertEquals(ldapConfig.getBindPassword(), freeIpa.getAdminPassword());
assertEquals(ldapConfig.getDirectoryType(), DirectoryType.LDAP);
assertEquals(ldapConfig.getUserNameAttribute(), USER_NAME_ATTRIBUTE);
assertEquals(ldapConfig.getUserObjectClass(), USER_OBJECT_CLASS);
assertEquals(ldapConfig.getGroupMemberAttribute(), GROUP_MEMBER_ATTRIBUTE);
assertEquals(ldapConfig.getGroupNameAttribute(), GROUP_NAME_ATTRIBUTE);
assertEquals(ldapConfig.getGroupObjectClass(), GROUP_OBJECT_CLASS);
}
Aggregations