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));
}
}
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);
}
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");
}
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);
}
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);
}
Aggregations