use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseVSphereAdapterTest method shutdownGuestOS.
protected void shutdownGuestOS(ComputeState computeState) {
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest shutdownGuestRequest = getResourceOperationRequest("Shutdown", computeState.documentSelfLink, taskLink);
TestContext ctx = this.host.testCreate(1);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Service.Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else {
ctx.completeIteration();
}
return true;
});
TestContext ctx2 = this.host.testCreate(1);
Operation shutdownOp = Operation.createPatch(UriUtils.buildUri(this.host, VSphereAdapterD2PowerOpsService.SELF_LINK)).setBody(shutdownGuestRequest).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx2.failIteration(e);
return;
}
ctx2.completeIteration();
});
this.host.send(shutdownOp);
ctx2.await();
ComputeState[] cState = new ComputeState[1];
this.host.waitFor("Guest shutdown request failed", () -> {
cState[0] = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, computeState.documentSelfLink));
if (cState[0].powerState.equals(ComputeService.PowerState.OFF)) {
assertTrue(cState[0].address.isEmpty());
return true;
} else {
return false;
}
});
assertEquals(ComputeService.PowerState.OFF, cState[0].powerState);
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AWSComputeDiskDay2ServiceTest method setUp.
@Before
public void setUp() throws Exception {
CommandLineArgumentParser.parseFromProperties(this);
setAwsClientMockInfo(this.isAwsClientMock, this.awsMockEndpointReference);
AuthCredentialsService.AuthCredentialsServiceState creds = new AuthCredentialsService.AuthCredentialsServiceState();
creds.privateKey = this.secretKey;
creds.privateKeyId = this.accessKey;
TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getEc2AsyncClient(creds, TestAWSSetupUtils.regionId, getExecutor()).exceptionally(t -> {
ec2WaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
ec2WaitContext.complete();
});
ec2WaitContext.await();
this.awsTestContext = new HashMap<>();
setUpTestVpc(this.client, this.awsTestContext, this.isMock, this.zoneId);
this.singleNicSpec = (TestAWSSetupUtils.AwsNicSpecs) this.awsTestContext.get(TestAWSSetupUtils.NIC_SPECS_KEY);
this.host = VerificationHost.create(0);
try {
this.host.setMaintenanceIntervalMicros(TimeUnit.MILLISECONDS.toMicros(250));
this.host.start();
PhotonModelServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
ServiceMetadata[] serviceMetadata = { factoryService(DiskTaskService.class, DiskTaskService::createFactory) };
StartServicesHelper.startServices(this.host, serviceMetadata);
AWSAdaptersTestUtils.startServicesSynchronously(this.host);
this.host.setTimeoutSeconds(1200);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelMetricServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
initResourcePoolAndComputeHost(this.zoneId);
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AWSLoadBalancerServiceTest method setUp.
@Override
@Before
public void setUp() throws Throwable {
CommandLineArgumentParser.parseFromProperties(this);
try {
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
AWSAdaptersTestUtils.startServicesSynchronously(this.host);
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = this.secretKey;
creds.privateKeyId = this.accessKey;
TestContext lbWaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getAwsLoadBalancingAsyncClient(creds, this.regionId, getExecutor()).exceptionally(t -> {
lbWaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
lbWaitContext.complete();
});
lbWaitContext.await();
TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getEc2AsyncClient(creds, this.regionId, getExecutor()).exceptionally(t -> {
ec2WaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.ec2client = ec2Client;
ec2WaitContext.complete();
});
ec2WaitContext.await();
TestContext secGroupWaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getEc2AsyncClient(creds, this.regionId, getExecutor()).exceptionally(t -> {
secGroupWaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.securityGroupClient = new AWSSecurityGroupClient(ec2Client);
secGroupWaitContext.complete();
});
secGroupWaitContext.await();
this.host.setTimeoutSeconds(this.timeoutSeconds);
this.endpointState = createEndpointState();
String vm1 = "vm1";
String vm2 = "vm2";
if (!this.isMock) {
vm1 = provisionAWSVMWithEC2Client(this.host, this.ec2client, EC2_LINUX_AMI, this.subnetId, null);
this.instancesToCleanUp.add(vm1);
vm2 = provisionAWSVMWithEC2Client(this.host, this.ec2client, EC2_LINUX_AMI, this.subnetId, null);
this.instancesToCleanUp.add(vm2);
}
this.cs1 = createComputeState(vm1);
this.cs2 = createComputeState(vm2);
} catch (Throwable e) {
this.host.log("Error starting up services for the test %s", e.getMessage());
throw new Exception(e);
}
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AWSInstanceTypeServiceTest method testGetInstanceTypesPositive.
@Test
public void testGetInstanceTypesPositive() throws Throwable {
EndpointState ep = createEndpointState();
TestContext ctx = this.host.testCreate(1);
Operation getOperation = Operation.createGet(UriUtils.buildUri(this.host, AWSInstanceTypeService.SELF_LINK + "?endpoint=" + ep.documentSelfLink)).setCompletion((operation, throwable) -> {
try {
if (throwable != null) {
ctx.failIteration(throwable);
return;
}
assertEquals(Operation.STATUS_CODE_OK, operation.getStatusCode());
InstanceTypeList instanceTypes = operation.getBody(InstanceTypeList.class);
assertNotNull("Tenant links should ne set.", instanceTypes.tenantLinks);
assertEquals("Tenant links size equal to endpoint tenant links size is " + "expecteed.", ep.tenantLinks.size(), instanceTypes.tenantLinks.size());
assertNotNull("Instance types should not be null.", instanceTypes.instanceTypes);
instanceTypes.instanceTypes.stream().filter(instanceType -> instanceType.id == null || instanceType.name == null).findFirst().ifPresent(instanceType -> fail("Found instance type without id " + "or name."));
// Validate that all types have cpu and memory extended data set.
instanceTypes.instanceTypes.stream().filter(instanceType -> instanceType.cpuCount == null || instanceType.memoryInMB == null).findFirst().ifPresent(instanceType -> fail("Found instance type without extended data present: " + instanceType.id));
// Check that one of the well known type is present.
InstanceTypeList.InstanceType t2MicroType = instanceTypes.instanceTypes.stream().filter(instanceType -> InstanceType.T2Micro.toString().equals(instanceType.id)).findFirst().orElseThrow(() -> new AssertionError("Unable to " + "find t2.micro instance type."));
assertEquals(1, t2MicroType.cpuCount.intValue());
assertEquals(1024, t2MicroType.memoryInMB.intValue());
assertNotNull(t2MicroType.storageType);
assertNotNull(t2MicroType.networkType);
ctx.completeIteration();
} catch (AssertionError err) {
ctx.failIteration(err);
}
});
this.send(getOperation);
this.testWait(ctx);
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class AWSRebootServiceTest method testReboot.
// Test the reboot operation.
@Test
public void testReboot() throws Throwable {
provisionSingleAWS();
// check that the VM has been created
ProvisioningUtils.queryComputeInstances(this.host, 2);
ComputeState compute = getCompute(this.host, this.vmState.documentSelfLink);
if (!this.isMock) {
List<Instance> instances = getAwsInstancesByIds(this.client, this.host, Collections.singletonList(compute.id));
Instance instance = instances.get(0);
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertAndSetVMSecurityGroupsToBeDeleted(instance, vm);
}
String taskLink = UUID.randomUUID().toString();
ResourceOperationRequest request = new ResourceOperationRequest();
request.isMockRequest = this.isMock;
request.operation = ResourceOperation.REBOOT.operation;
request.payload = new HashMap<>();
request.resourceReference = UriUtils.buildUri(this.host, compute.documentSelfLink);
request.taskReference = UriUtils.buildUri(this.host, taskLink);
TestContext ctx = this.host.testCreate(2);
createTaskResultListener(this.host, taskLink, (u) -> {
if (u.getAction() != Service.Action.PATCH) {
return false;
}
ResourceOperationResponse response = u.getBody(ResourceOperationResponse.class);
if (TaskState.isFailed(response.taskInfo)) {
ctx.failIteration(new IllegalStateException(response.taskInfo.failure.message));
} else if (TaskState.isFinished(response.taskInfo)) {
ctx.completeIteration();
}
return true;
});
Operation rebootOp = Operation.createPatch(UriUtils.buildUri(this.host, AWSRebootService.SELF_LINK)).setBody(request).setReferer(this.host.getReferer()).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ctx.completeIteration();
});
this.host.send(rebootOp);
ctx.await();
ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
assertEquals(ComputeService.PowerState.ON, vm.powerState);
}
Aggregations