use of com.sequenceiq.freeipa.entity.ImageEntity 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.ImageEntity 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.ImageEntity in project cloudbreak by hortonworks.
the class ImageCatalogChangeServiceTest method init.
@BeforeAll
static void init() {
STACK.setId(STACK_ID);
STACK.setName(STACK_NAME);
final ImageEntity image = new ImageEntity();
image.setImageId(IMAGE_ID);
image.setOs(OS);
STACK.setImage(image);
}
use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class ImageServiceTest method testImageChange.
@Test
public void testImageChange() {
Stack stack = new Stack();
stack.setCloudPlatform(DEFAULT_PLATFORM);
stack.setRegion(DEFAULT_REGION);
ImageSettingsRequest imageRequest = new ImageSettingsRequest();
when(imageProviderFactory.getImageProvider(any())).thenReturn(imageProvider);
when(imageProvider.getImage(imageRequest, stack.getRegion(), stack.getCloudPlatform())).thenReturn(Optional.of(new ImageWrapper(image, IMAGE_CATALOG_URL, IMAGE_CATALOG)));
when(image.getImageSetsByProvider()).thenReturn(Collections.singletonMap(DEFAULT_PLATFORM, Collections.singletonMap(DEFAULT_REGION, EXISTING_ID)));
when(imageRepository.getByStack(stack)).thenReturn(new ImageEntity());
when(image.getUuid()).thenReturn(IMAGE_UUID);
when(imageRepository.save(any(ImageEntity.class))).thenAnswer(invocation -> invocation.getArgument(0, ImageEntity.class));
ImageEntity imageEntity = underTest.changeImage(stack, imageRequest);
assertEquals(EXISTING_ID, imageEntity.getImageName());
assertEquals(IMAGE_CATALOG_URL, imageEntity.getImageCatalogUrl());
assertEquals(IMAGE_CATALOG, imageEntity.getImageCatalogName());
assertEquals(IMAGE_UUID, imageEntity.getImageId());
}
use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testBuildInstance.
@Test
public void testBuildInstance() throws Exception {
InstanceMetaData instanceMetaData = mock(InstanceMetaData.class);
InstanceGroup instanceGroup = mock(InstanceGroup.class);
ImageEntity imageEntity = mock(ImageEntity.class);
when(imageService.getByStack(any())).thenReturn(imageEntity);
when(imageEntity.getImageName()).thenReturn(IMAGE_NAME);
when(instanceMetaData.getInstanceId()).thenReturn(INSTANCE_ID);
when(instanceGroup.getGroupName()).thenReturn(GROUP_NAME);
Template template = mock(Template.class);
when(instanceGroup.getTemplate()).thenReturn(template);
when(template.getVolumeCount()).thenReturn(VOLUME_COUNT);
CloudInstance cloudInstance = underTest.buildInstance(stack, instanceMetaData, instanceGroup, stackAuthentication, 0L, InstanceStatus.CREATED);
assertEquals(INSTANCE_ID, cloudInstance.getInstanceId());
}
Aggregations