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