Search in sources :

Example 6 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAzureImageEnumerationTask method testPrivateImageEnumeration_single.

/**
 * That's the private image we are testing:
 * {@link /resourceGroups/Images/providers/Microsoft.Compute/images/LinuxImageWithOsAndDataUnmanaged/overview}
 */
@Test
@Ignore("For now run the test manually. Will enable it once the image is created programatically, but not hardcoded")
public void testPrivateImageEnumeration_single() throws Throwable {
    Assume.assumeFalse(this.isMock);
    kickOffImageEnumeration(this.endpointState, PRIVATE, AZURE_ALL_IMAGES_FILTER);
    // Validate at least 1 image state is CREATED
    QueryTop<ImageState> queryAll = new QueryTop<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, this.endpointState.tenantLinks, this.endpointState.documentSelfLink);
    List<ImageState> images = PhotonModelUtils.waitToComplete(queryAll.collectDocuments(Collectors.toList()));
    Assert.assertTrue("Expected at least " + 1 + " private image, but found " + images.size(), images.size() >= 1);
    ImageState image = images.stream().filter(imageState -> {
        return imageState.name.equalsIgnoreCase(PRIVATE_IMAGE_NAME);
    }).findFirst().orElse(null);
    // Validate created image is correctly populated
    Assert.assertNotNull("Private image with '" + PRIVATE_IMAGE_NAME + "' name must have been enumerated.", image);
    Assert.assertNull("Private image must NOT have endpointType set.", image.endpointType);
    Assert.assertEquals("Private image must have endpointLink set.", this.endpointState.documentSelfLink, image.endpointLink);
    Assert.assertNotNull("Private image must have endpointLinks set.", image.endpointLinks);
    Assert.assertTrue("Private image must have endpointLinks set.", image.endpointLinks.contains(this.endpointState.documentSelfLink));
    Assert.assertEquals("Private image must have tenantLinks set.", this.endpointState.tenantLinks, image.tenantLinks);
    Assert.assertTrue("Image.id is invalid", image.id.endsWith(PRIVATE_IMAGE_NAME));
    Assert.assertEquals("Image.name is invalid", PRIVATE_IMAGE_NAME, image.name);
    Assert.assertEquals("Image.description is invalid", PRIVATE_IMAGE_NAME, image.description);
    Assert.assertNotNull("Image.diskConfigs", image.diskConfigs);
    Assert.assertEquals("Image.diskConfigs.size", 2, image.diskConfigs.size());
    {
        DiskConfiguration osDiskConfig = image.diskConfigs.get(0);
        Assert.assertNotNull("Image.osDiskConfig.properties", osDiskConfig.properties);
        Assert.assertNotNull("Image.osDiskConfig.properties.blobUri", osDiskConfig.properties.get(AzureConstants.AZURE_DISK_BLOB_URI));
        Assert.assertNull("Image.osDiskConfig.properties.lun", osDiskConfig.properties.get(AzureConstants.AZURE_DISK_LUN));
    }
    {
        DiskConfiguration dataDiskConfig = image.diskConfigs.get(1);
        Assert.assertNotNull("Image.dataDiskConfig.properties", dataDiskConfig.properties);
        Assert.assertNotNull("Image.dataDiskConfig.properties.blobUri", dataDiskConfig.properties.get(AzureConstants.AZURE_DISK_BLOB_URI));
        Assert.assertEquals("Image.dataDiskConfig.properties.lun", "0", dataDiskConfig.properties.get(AzureConstants.AZURE_DISK_LUN));
    }
}
Also used : DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Ignore(org.junit.Ignore) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 7 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class AzureTestUtil method createPrivateImageSource.

public static ImageSource createPrivateImageSource(VerificationHost host, EndpointState endpointState) throws Throwable {
    ImageState bootImage = new ImageState();
    // Change id and name according to your custom image details
    bootImage.id = "/subscriptions/817776f9-ef2a-4681-9774-a66f9be11e22/resourceGroups/Images/providers/Microsoft.Compute/images/SourceImageLinuxUnmanagedAPI";
    bootImage.name = "SourceImageLinuxUnmanagedAPI";
    bootImage.osFamily = "Linux";
    bootImage.tenantLinks = endpointState.tenantLinks;
    bootImage.endpointLink = endpointState.documentSelfLink;
    bootImage.endpointLinks = new HashSet<>();
    bootImage.endpointLinks.add(endpointState.documentSelfLink);
    List<DiskConfiguration> imageDisks = new ArrayList<>();
    DiskConfiguration osDiskConfig = new DiskConfiguration();
    imageDisks.add(osDiskConfig);
    // Add/Remove data disks and also map correct LUN values based on your private image configuration
    DiskConfiguration dataDiskConfig1 = new DiskConfiguration();
    dataDiskConfig1.properties = new HashMap<>();
    dataDiskConfig1.properties.put(AzureConstants.AZURE_DISK_LUN, "0");
    imageDisks.add(dataDiskConfig1);
    DiskConfiguration dataDiskConfig2 = new DiskConfiguration();
    dataDiskConfig2.properties = new HashMap<>();
    dataDiskConfig2.properties.put(AzureConstants.AZURE_DISK_LUN, "1");
    imageDisks.add(dataDiskConfig2);
    bootImage.diskConfigs = imageDisks;
    bootImage = TestUtils.doPost(host, bootImage, ImageState.class, UriUtils.buildUri(host, ImageService.FACTORY_LINK));
    return ImageSource.fromImageState(bootImage);
}
Also used : DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) ArrayList(java.util.ArrayList) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 8 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method afterTest.

@After
public final void afterTest() throws Throwable {
    QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, null);
    queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
    AtomicInteger counter = new AtomicInteger(0);
    waitToComplete(queryAll.queryLinks(imageLink -> {
        try {
            deleteServiceSynchronously(imageLink);
            counter.incrementAndGet();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }));
    getHost().log(Level.INFO, "[" + this.currentTestName.getMethodName() + "] Deleted " + counter + " ImageStates");
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockDeviceMapping(com.amazonaws.services.ec2.model.BlockDeviceMapping) DescribeImagesRequest(com.amazonaws.services.ec2.model.DescribeImagesRequest) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) After(org.junit.After) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) ProvisioningUtils.queryDocumentsAndAssertExpectedCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.queryDocumentsAndAssertExpectedCount) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) Description(org.junit.runner.Description) Collectors(java.util.stream.Collectors) List(java.util.List) EbsBlockDevice(com.amazonaws.services.ec2.model.EbsBlockDevice) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelUtils.waitToComplete(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.waitToComplete) TaskState(com.vmware.xenon.common.TaskState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Stopwatch(org.junit.rules.Stopwatch) HashMap(java.util.HashMap) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) Level(java.util.logging.Level) HashSet(java.util.HashSet) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) TestName(org.junit.rules.TestName) Image(com.amazonaws.services.ec2.model.Image) Filter(com.amazonaws.services.ec2.model.Filter) PaginatingIterator(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSImageEnumerationAdapterService.PaginatingIterator) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) Assume(org.junit.Assume) Before(org.junit.Before) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ImageEnumerationTaskService(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService) Test(org.junit.Test) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Ignore(org.junit.Ignore) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Assert(org.junit.Assert) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) After(org.junit.After)

Example 9 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method testPrivateImageEnumeration_single.

/*
     * The image that must be returned:
     *
     * https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Images:visibility=private-images;
     * imageId=ami-caf25eb0;sort=name
     *
     * under prelude_test @ https://537227425989.signin.aws.amazon.com/console
     */
@Test
@Ignore("https://jira-hzn.eng.vmware.com/browse/VCOM-832")
public void testPrivateImageEnumeration_single() throws Throwable {
    Assume.assumeFalse(this.isMock);
    final EndpointState endpointState = createEndpointState();
    kickOffImageEnumeration(endpointState, PRIVATE, AMAZON_PRIVATE_IMAGE_FILTER);
    // Validate 1 image state is CREATED
    ServiceDocumentQueryResult images = queryDocumentsAndAssertExpectedCount(getHost(), 1, ImageService.FACTORY_LINK, EXACT_COUNT);
    ImageState image = Utils.fromJson(images.documents.values().iterator().next(), ImageState.class);
    // Validate created image is correctly populated
    Assert.assertNull("Private image must NOT have endpointType set.", image.endpointType);
    Assert.assertEquals("Private image must have endpointLink set.", endpointState.documentSelfLink, image.endpointLink);
    Assert.assertEquals("Private image must have tenantLinks set.", endpointState.tenantLinks, image.tenantLinks);
    Assert.assertEquals("Private image id is incorrect.", "ami-caf25eb0", image.id);
    Assert.assertEquals("Private image name is incorrect.", "tapestryPipelineServiceTestService", image.name);
    Assert.assertEquals("Private image 'Name' tag is missing.", 1, image.tagLinks.size());
    TagState nameTag = getServiceSynchronously(image.tagLinks.iterator().next(), TagState.class);
    Assert.assertEquals(image.name, nameTag.value);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Ignore(org.junit.Ignore) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 10 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method createImageState.

/**
 * @param endpoint
 *            the end-point of the image to create
 * @param epRegion
 *            a flag indicating whether to create the image in the region of the end-point or in
 *            a different region
 * @param isPublic
 *            a flag indicating whether to create public or private image
 * @return the actual image created
 */
private ImageState createImageState(EndpointState endpoint, boolean epRegion, boolean isPublic) throws Throwable {
    ImageState image = new ImageState();
    if (isPublic == PUBLIC) {
        image.endpointType = endpoint.endpointType;
    } else {
        image.endpointLink = endpoint.documentSelfLink;
        image.tenantLinks = endpoint.tenantLinks;
    }
    image.endpointLinks = new HashSet<>();
    image.endpointLinks.add(endpoint.documentSelfLink);
    image.id = "dummy-" + this.currentTestName.getMethodName();
    image.regionId = epRegion ? this.regionId : this.regionId + "_diff";
    return postServiceSynchronously(ImageService.FACTORY_LINK, image, ImageState.class);
}
Also used : ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Aggregations

ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)31 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)12 Test (org.junit.Test)12 List (java.util.List)9 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)7 HashSet (java.util.HashSet)7 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)6 QueryTop (com.vmware.photon.controller.model.query.QueryUtils.QueryTop)6 DiskConfiguration (com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration)6 ImageEnumerationTaskState (com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)6 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)5 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)5 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)5 ImageService (com.vmware.photon.controller.model.resources.ImageService)5 Operation (com.vmware.xenon.common.Operation)5 Utils (com.vmware.xenon.common.Utils)5 Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)5 DeferredResult (com.vmware.xenon.common.DeferredResult)4 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)3 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)3