Search in sources :

Example 11 with AWSSecurityGroupClient

use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient in project photon-model by vmware.

the class TestProvisionAWSSecurityGroup method validateAWSArtifacts.

private void validateAWSArtifacts(String securityGroupDescriptionLink, AuthCredentialsServiceState creds) throws Throwable {
    SecurityGroupState securityGroup = getSecurityGroupState(securityGroupDescriptionLink);
    AWSSecurityGroupClient client = new AWSSecurityGroupClient(AWSUtils.getAsyncClient(creds, this.region, getExecutor()));
    // if any artifact is not present then an error will be thrown
    SecurityGroup sg = client.getSecurityGroupById(securityGroup.customProperties.get(AWSSecurityGroupService.SECURITY_GROUP_ID));
    assertNotNull(sg);
    assertNotNull(sg.getIpPermissions());
    assertTrue(sg.getIpPermissions().size() == 2);
    // check that there is a rule that enables internal communication
    assertTrue(isInternalRule(sg.getGroupId(), sg.getIpPermissions()));
    assertNotNull(sg.getIpPermissionsEgress());
    // there are two egress rules (one that was added as part of this test, and the default one)
    assertTrue(sg.getIpPermissionsEgress().size() == 2);
    // check that there is a rule that enables internal communication
    assertTrue(isInternalRule(sg.getGroupId(), sg.getIpPermissionsEgress()));
}
Also used : SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup)

Example 12 with AWSSecurityGroupClient

use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient in project photon-model by vmware.

the class TestAWSSecurityGroupService method setUp.

@Before
public void setUp() throws Exception {
    CommandLineArgumentParser.parseFromProperties(this);
    // ignore if any of the required properties are missing
    org.junit.Assume.assumeTrue(TestUtils.isNull(this.privateKey, this.privateKeyId, this.region, this.subnet));
    this.host = VerificationHost.create(0);
    try {
        this.host.start();
        PhotonModelServices.startServices(this.host);
        PhotonModelMetricServices.startServices(this.host);
        PhotonModelTaskServices.startServices(this.host);
        this.svc = new AWSSecurityGroupService();
        this.host.startService(Operation.createPost(UriUtils.buildUri(this.host, AWSSecurityGroupService.class)), this.svc);
        this.client = new AWSSecurityGroupClient(TestUtils.getClient(this.privateKeyId, this.privateKey, this.region, false));
    } catch (Throwable e) {
        throw new Exception(e);
    }
}
Also used : AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) ExpectedException(org.junit.rules.ExpectedException) AmazonServiceException(com.amazonaws.AmazonServiceException) Before(org.junit.Before)

Aggregations

AWSSecurityGroupClient (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient)12 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)6 ArrayList (java.util.ArrayList)6 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)5 Vpc (com.amazonaws.services.ec2.model.Vpc)5 List (java.util.List)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 Filter (com.amazonaws.services.ec2.model.Filter)4 Tag (com.amazonaws.services.ec2.model.Tag)4 DiskService (com.vmware.photon.controller.model.resources.DiskService)4 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)4 DeferredResult (com.vmware.xenon.common.DeferredResult)4 Operation (com.vmware.xenon.common.Operation)4 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)3 UriUtils (com.vmware.xenon.common.UriUtils)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 AsyncHandler (com.amazonaws.handlers.AsyncHandler)2 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)2 CreateSubnetRequest (com.amazonaws.services.ec2.model.CreateSubnetRequest)2