Search in sources :

Example 21 with Image

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.

the class StackToDescribeFreeIpaResponseConverterTest method convertTest.

@ParameterizedTest(name = "tunnel={0}")
@EnumSource(Tunnel.class)
@NullSource
void convertTest(Tunnel tunnel) {
    FreeIpaServerResponse freeIpaServerResponse = new FreeIpaServerResponse();
    Stack stack = createStack(tunnel);
    ImageEntity image = new ImageEntity();
    FreeIpa freeIpa = new FreeIpa();
    freeIpa.setDomain(DOMAIN);
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    when(authenticationResponseConverter.convert(stack.getStackAuthentication())).thenReturn(STACK_AUTHENTICATION_RESPONSE);
    when(imageSettingsResponseConverter.convert(image)).thenReturn(IMAGE_SETTINGS_RESPONSE);
    when(freeIpaServerResponseConverter.convert(freeIpa)).thenReturn(freeIpaServerResponse);
    when(instanceGroupConverter.convert(stack.getInstanceGroups(), true)).thenReturn(INSTANCE_GROUP_RESPONSES);
    when(userSyncStatusConverter.convert(userSyncStatus)).thenReturn(USERSYNC_STATUS_RESPONSE);
    when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
    when(stackToAvailabilityStatusConverter.convert(stack)).thenReturn(AvailabilityStatus.AVAILABLE);
    DescribeFreeIpaResponse result = underTest.convert(stack, image, freeIpa, Optional.of(userSyncStatus), true);
    assertThat(result).returns(NAME, DescribeFreeIpaResponse::getName).returns(ENV_CRN, DescribeFreeIpaResponse::getEnvironmentCrn).returns(RESOURCE_CRN, DescribeFreeIpaResponse::getCrn).returns(CLOUD_PLATFORM, DescribeFreeIpaResponse::getCloudPlatform).returns(STACK_AUTHENTICATION_RESPONSE, DescribeFreeIpaResponse::getAuthentication).returns(IMAGE_SETTINGS_RESPONSE, DescribeFreeIpaResponse::getImage).returns(freeIpaServerResponse, DescribeFreeIpaResponse::getFreeIpa).returns(INSTANCE_GROUP_RESPONSES, DescribeFreeIpaResponse::getInstanceGroups).returns(STATUS, DescribeFreeIpaResponse::getStatus).returns(STATUS_REASON, DescribeFreeIpaResponse::getStatusReason).returns(STATUS_STRING, DescribeFreeIpaResponse::getStatusString).returns(APP_VERSION, DescribeFreeIpaResponse::getAppVersion).returns(VARIANT, DescribeFreeIpaResponse::getVariant).returns(USERSYNC_STATUS_RESPONSE, DescribeFreeIpaResponse::getUserSyncStatus).returns(tunnel, DescribeFreeIpaResponse::getTunnel);
    assertThat(freeIpaServerResponse).returns(Set.of(SERVER_IP), FreeIpaServerResponse::getServerIp).returns(FREEIPA_HOST, FreeIpaServerResponse::getFreeIpaHost).returns(GATEWAY_PORT, FreeIpaServerResponse::getFreeIpaPort);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) FreeIpaServerResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerResponse) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Stack(com.sequenceiq.freeipa.entity.Stack) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NullSource(org.junit.jupiter.params.provider.NullSource)

Example 22 with Image

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.

the class ImageServiceTest method testGenerateForStack.

@Test
void testGenerateForStack() throws NoSuchFieldException {
    ReflectionUtils.setField(ImageService.class.getDeclaredField("freeIpaVersion"), underTest, FREEIPA_VERSION);
    Stack stack = new Stack();
    stack.setRegion(DEFAULT_REGION);
    stack.setCloudPlatform(DEFAULT_PLATFORM);
    ImageEntity imageEntity = new ImageEntity();
    imageEntity.setImageId(IMAGE_UUID);
    imageEntity.setOs(DEFAULT_OS);
    imageEntity.setImageCatalogName(IMAGE_CATALOG);
    imageEntity.setImageCatalogUrl(IMAGE_CATALOG_URL);
    when(imageRepository.getByStack(stack)).thenReturn(imageEntity);
    when(imageProviderFactory.getImageProvider(IMAGE_CATALOG)).thenReturn(imageProvider);
    Image image = new Image(123L, "now", "desc", DEFAULT_OS, IMAGE_UUID, Map.of(), "os", Map.of(), true);
    ImageWrapper imageWrapper = new ImageWrapper(image, IMAGE_CATALOG_URL, IMAGE_CATALOG);
    when(imageProvider.getImage(any(), any(), any())).thenReturn(Optional.of(imageWrapper));
    ImageCatalog result = underTest.generateImageCatalogForStack(stack);
    verify(imageProvider).getImage(imageSettingsRequestCaptor.capture(), eq(DEFAULT_REGION), eq(DEFAULT_PLATFORM));
    assertThat(imageSettingsRequestCaptor.getValue()).returns(IMAGE_CATALOG, ImageSettingsBase::getCatalog).returns(IMAGE_UUID, ImageSettingsBase::getId);
    assertThat(result.getImages().getFreeipaImages()).containsExactly(image);
    assertThat(result.getVersions()).isNull();
}
Also used : ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImageSettingsBase(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsBase) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 23 with Image

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.

the class ImageServiceTest method testGetImageGivenIdInputNotFound.

@Test
public void testGetImageGivenIdInputNotFound() {
    ImageSettingsRequest imageSettings = new ImageSettingsRequest();
    imageSettings.setCatalog(IMAGE_CATALOG);
    imageSettings.setId(FAKE_ID);
    imageSettings.setOs(DEFAULT_OS);
    when(imageProviderFactory.getImageProvider(IMAGE_CATALOG)).thenReturn(imageProvider);
    when(imageProvider.getImage(imageSettings, DEFAULT_REGION, DEFAULT_PLATFORM)).thenReturn(Optional.empty());
    Exception exception = assertThrows(RuntimeException.class, () -> underTest.getImage(imageSettings, DEFAULT_REGION, DEFAULT_PLATFORM));
    String exceptionMessage = "Could not find any image with id: 'fake-ami-0a6931aea1415eb0e' in region 'eu-west-1' with OS 'redhat7'.";
    assertEquals(exceptionMessage, exception.getMessage());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Test(org.junit.jupiter.api.Test)

Example 24 with Image

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.

the class CoreImageProviderTest method shouldReturnResult.

@Test
public void shouldReturnResult() throws Exception {
    when(imageCatalogV4Endpoint.getSingleImageByCatalogNameAndImageId(WORKSPACE_ID_DEFAULT, CATALOG_NAME, IMAGE_ID)).thenReturn(anImageResponse());
    Optional<ImageWrapper> actual = victim.getImage(anImageSettings(), REGION, PLATFORM);
    Image image = actual.get().getImage();
    assertEquals(DATE, image.getDate());
    assertEquals(DESCRIPTION, image.getDescription());
    assertEquals(UUID, image.getUuid());
    assertEquals(OS_TYPE, image.getOsType());
    assertEquals(VM_IMAGE_REFERENCE, image.getImageSetsByProvider().get(PLATFORM).get(REGION));
}
Also used : ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Test(org.junit.jupiter.api.Test)

Example 25 with Image

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.

the class CoreImageProviderTest method testGetImages.

@Test
public void testGetImages() throws Exception {
    ImagesV4Response imagesV4Response = new ImagesV4Response();
    imagesV4Response.setFreeipaImages(List.of(anImageResponse()));
    when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenReturn(imagesV4Response);
    ImageSettingsRequest imageSettings = new ImageSettingsRequest();
    imageSettings.setCatalog(CATALOG_NAME);
    List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
    assertEquals(1, result.size());
    ImageWrapper imageWrapper = result.get(0);
    assertEquals(CATALOG_NAME, imageWrapper.getCatalogName());
    assertNull(imageWrapper.getCatalogUrl());
    Image image = imageWrapper.getImage();
    assertEquals(DATE, image.getDate());
    assertEquals(DESCRIPTION, image.getDescription());
    assertEquals(UUID, image.getUuid());
    assertEquals(OS_TYPE, image.getOsType());
    assertEquals(VM_IMAGE_REFERENCE, image.getImageSetsByProvider().get(PLATFORM).get(REGION));
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Test(org.junit.jupiter.api.Test)

Aggregations

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)32 Test (org.junit.jupiter.api.Test)28 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)27 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)21 Stack (com.sequenceiq.freeipa.entity.Stack)16 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)10 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)9 ImageCatalog (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)7 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)4 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)4 FreeIpaVersions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions)3 List (java.util.List)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)2 Backup (com.sequenceiq.freeipa.api.model.Backup)2 Versions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Versions)2 UsedImagesListV1Response (com.sequenceiq.freeipa.api.v1.util.model.UsedImagesListV1Response)2 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)2 ImageNotFoundException (com.sequenceiq.freeipa.service.image.ImageNotFoundException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1