use of com.vmware.photon.controller.model.tasks.ProvisioningUtils.queryComputeInstances in project photon-model by vmware.
the class TestAWSEnumerationTask method testEnumerationPreserveLocalStates.
@Test
public void testEnumerationPreserveLocalStates() throws Throwable {
this.host.log("Running test: " + this.currentTestName.getMethodName());
ComputeState vmState = createAWSVMResource(this.host, this.computeHost, this.endpointState, TestAWSSetupUtils.class, zoneId, regionId, null, this.singleNicSpec, this.awsTestContext);
if (this.isMock) {
// Just make a call to the enumeration service and make sure that the adapter patches
// the parent with completion.
enumerateResourcesPreserveMissing(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_MOCK_MODE);
return;
}
// Overriding the page size to test the pagination logic with limited instances on AWS.
// This is a functional test
// so the latency numbers maybe higher from this test due to low page size.
setQueryPageSize(DEFAULT_TEST_PAGE_SIZE);
setQueryResultLimit(DEFAULT_TEST_PAGE_SIZE);
// Provision a single VM . Check initial state.
vmState = provisionMachine(this.host, vmState, this.isMock, this.instancesToCleanUp);
queryComputeInstances(this.host, count2);
queryDocumentsAndAssertExpectedCount(this.host, count2, ComputeDescriptionService.FACTORY_LINK, false);
// CREATION directly on AWS
List<String> instanceIdsToDelete = provisionAWSVMWithEC2Client(this.client, this.host, count4, T2_MICRO_INSTANCE_TYPE, this.subnetId, this.securityGroupId);
List<String> instanceIds = provisionAWSVMWithEC2Client(this.client, this.host, count1, instanceType, this.subnetId, this.securityGroupId);
instanceIdsToDelete.addAll(instanceIds);
this.instancesToCleanUp.addAll(instanceIdsToDelete);
waitForProvisioningToComplete(instanceIdsToDelete, this.host, this.client, ZERO);
// Xenon does not know about the new instances.
ProvisioningUtils.queryComputeInstances(this.host, count2);
enumerateResourcesPreserveMissing(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_INITIAL);
// 5 new resources should be discovered. Mapping to 2 new compute description and 5 new
// compute states.
// Even though the "t2.micro" is common to the VM provisioned from Xenon
// service and the one directly provisioned on EC2, there is no Compute description
// linking of discovered resources to user defined compute descriptions. So a new system
// generated compute description will be created for "t2.micro"
queryDocumentsAndAssertExpectedCount(this.host, count4, ComputeDescriptionService.FACTORY_LINK, false);
queryDocumentsAndAssertExpectedCount(this.host, count7, ComputeService.FACTORY_LINK, false);
// Verify Deletion flow
// Delete 5 VMs spawned above of type T2_NANO
deleteVMsUsingEC2Client(this.client, this.host, instanceIdsToDelete);
enumerateResourcesPreserveMissing(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_DELETE_VMS);
// Counts should go down 5 compute states.
ServiceDocumentQueryResult queryResult = queryDocumentsAndAssertExpectedCount(this.host, count7, ComputeService.FACTORY_LINK, false);
List<ComputeState> localInstances = queryResult.documents.values().stream().map(d -> Utils.fromJson(d, ComputeState.class)).filter(c -> instanceIdsToDelete.contains(c.id)).collect(Collectors.toList());
assertEquals(instanceIdsToDelete.size(), localInstances.size());
for (ComputeState c : localInstances) {
assertEquals(LifecycleState.RETIRED, c.lifecycleState);
}
}
Aggregations