Search in sources :

Example 16 with SecurityGroupState

use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.

the class TestUtils method postSecurityGroup.

public static void postSecurityGroup(VerificationHost host, SecurityGroupState state, Operation response) throws Throwable {
    URI securityGroupFactory = UriUtils.buildUri(host, SecurityGroupService.FACTORY_LINK);
    host.testStart(1);
    Operation startPost = Operation.createPost(securityGroupFactory).setBody(state).setCompletion((o, e) -> {
        if (e != null) {
            host.failIteration(e);
            return;
        }
        response.setBody(o.getBody(SecurityGroupState.class));
        host.completeIteration();
    });
    host.send(startPost);
    host.testWait();
}
Also used : SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI)

Example 17 with SecurityGroupState

use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.

the class AzureTestUtil method createSecurityGroupState.

public static SecurityGroupState createSecurityGroupState(VerificationHost host, EndpointState endpointState, String name, List<Rule> inboundRules, List<Rule> outboudRules) throws Throwable {
    SecurityGroupState securityGroupState = new SecurityGroupState();
    securityGroupState.id = name;
    securityGroupState.name = name;
    securityGroupState.instanceAdapterReference = UriUtils.buildUri(host, AzureSecurityGroupService.SELF_LINK);
    securityGroupState.endpointLink = endpointState.documentSelfLink;
    securityGroupState.endpointLinks = new HashSet<>();
    securityGroupState.endpointLinks.add(endpointState.documentSelfLink);
    securityGroupState.computeHostLink = endpointState.computeHostLink;
    securityGroupState.tenantLinks = endpointState.tenantLinks;
    securityGroupState.ingress = inboundRules;
    securityGroupState.egress = outboudRules;
    securityGroupState.authCredentialsLink = endpointState.authCredentialsLink;
    securityGroupState.resourcePoolLink = "test-resource-pool-link";
    securityGroupState.regionId = AZURE_RESOURCE_GROUP_LOCATION;
    return TestUtils.doPost(host, securityGroupState, SecurityGroupState.class, UriUtils.buildUri(host, SecurityGroupService.FACTORY_LINK));
}
Also used : SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)

Example 18 with SecurityGroupState

use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testCreateSecurityGroupsWithSameRuleNames.

@Test
public void testCreateSecurityGroupsWithSameRuleNames() throws Throwable {
    SecurityGroupState securityGroupState1 = createSecurityGroupState(this.securityGroupName + "-1", Arrays.asList(buildRule("rule-1", SecurityGroupService.ANY, "0.0.0.0/0", Access.Deny, SecurityGroupService.ALL_PORTS)), Arrays.asList(buildRule("rule-2", SecurityGroupService.ANY, "0.0.0.0/0", Access.Deny, SecurityGroupService.ALL_PORTS)));
    startSecurityGroupProvisioning(InstanceRequestType.CREATE, securityGroupState1, TaskStage.FINISHED);
    securityGroupState1 = getServiceSynchronously(securityGroupState1.documentSelfLink, SecurityGroupState.class);
    assertNotNull(securityGroupState1.id);
    assertNotEquals(securityGroupState1.id, this.securityGroupName + "-1");
    SecurityGroupState securityGroupState2 = createSecurityGroupState(this.securityGroupName + "-2", Arrays.asList(buildRule("rule-1", SecurityGroupService.ANY, "0.0.0.0/0", Access.Deny, SecurityGroupService.ALL_PORTS)), Arrays.asList(buildRule("rule-2", SecurityGroupService.ANY, "0.0.0.0/0", Access.Deny, SecurityGroupService.ALL_PORTS)));
    startSecurityGroupProvisioning(InstanceRequestType.CREATE, securityGroupState2, TaskStage.FINISHED);
    securityGroupState2 = getServiceSynchronously(securityGroupState2.documentSelfLink, SecurityGroupState.class);
    assertNotNull(securityGroupState2.id);
    assertNotEquals(securityGroupState2.id, this.securityGroupName + "-2");
    if (!this.isMock) {
        // delete the security groups
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState1, TaskStage.FINISHED);
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState2, TaskStage.FINISHED);
    }
}
Also used : AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 19 with SecurityGroupState

use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method testCreateSecurityGroupFailures.

@Test
public void testCreateSecurityGroupFailures() throws Throwable {
    if (!this.isMock) {
        // test invalid security rule name
        SecurityGroupState securityGroupState = provisionSecurityGroup(buildInvalidNameRules(), buildNonDefaultRules(), TaskStage.FAILED);
        assertNotNull(securityGroupState.id);
        assertNotEquals(securityGroupState.id, this.securityGroupName);
        // Verify that the security group was created without any rules.
        NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
        assertEquals(this.securityGroupName, sgResponse.name());
        assertEquals(securityGroupState.id, sgResponse.id());
        assertEquals(sgResponse.securityRules().size(), 0);
        // delete the security group
        startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
    }
}
Also used : NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 20 with SecurityGroupState

use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.

the class AzureSecurityGroupServiceTest method provisionSecurityGroup.

private SecurityGroupState provisionSecurityGroup(List<Rule> inboundRules, List<Rule> outboundRules, TaskStage taskStage) throws Throwable {
    SecurityGroupState securityGroupState = createSecurityGroupState(this.securityGroupName, inboundRules, outboundRules);
    startSecurityGroupProvisioning(InstanceRequestType.CREATE, securityGroupState, taskStage);
    return getServiceSynchronously(securityGroupState.documentSelfLink, SecurityGroupState.class);
}
Also used : AzureTestUtil.getSecurityGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)

Aggregations

SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)41 Operation (com.vmware.xenon.common.Operation)16 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 URI (java.net.URI)12 AzureTestUtil.getSecurityGroupState (com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getSecurityGroupState)9 UriUtils (com.vmware.xenon.common.UriUtils)9 List (java.util.List)9 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)8 HashSet (java.util.HashSet)8 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)7 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)7 StatelessService (com.vmware.xenon.common.StatelessService)7 HashMap (java.util.HashMap)7 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)6 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)6 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)5