use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner 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.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method testDeleteSecurityGroup.
@Test
public void testDeleteSecurityGroup() throws Throwable {
SecurityGroupState securityGroupState = provisionSecurityGroup(new ArrayList<>(), new ArrayList<>(), TaskStage.FINISHED);
startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
// verify security group state was deleted
try {
getSecurityGroupState(this.host, securityGroupState.documentSelfLink);
} catch (Exception e) {
assertTrue(e instanceof ServiceNotFoundException);
}
if (!this.isMock) {
// Verify that the security group was deleted from Azure.
NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
if (sgResponse != null) {
fail("Security group should not exist in Azure.");
}
}
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method testCreateSecurityGroupWithNonDefaultRules.
@Test
public void testCreateSecurityGroupWithNonDefaultRules() throws Throwable {
SecurityGroupState securityGroupState = provisionSecurityGroup(buildNonDefaultRules(), buildNonDefaultRules(), TaskStage.FINISHED);
assertNotNull(securityGroupState.id);
assertNotEquals(securityGroupState.id, this.securityGroupName);
if (!this.isMock) {
// Verify that the security group was created.
NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
assertEquals(this.securityGroupName, sgResponse.name());
assertEquals(securityGroupState.id, sgResponse.id());
assertEquals(sgResponse.securityRules().size(), 2 * securityGroupState.ingress.size());
validateAzureSecurityRules(sgResponse.securityRules(), securityGroupState.ingress.size());
// delete the security group
startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
}
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method testCreateSecurityGroupWithDefaultRules.
@Test
public void testCreateSecurityGroupWithDefaultRules() throws Throwable {
SecurityGroupState securityGroupState = provisionSecurityGroup(buildDefaultRules(), buildDefaultRules(), TaskStage.FINISHED);
assertNotNull(securityGroupState.id);
assertNotEquals(securityGroupState.id, this.securityGroupName);
if (!this.isMock) {
// Verify that the security group was created.
NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
assertEquals(this.securityGroupName, sgResponse.name());
assertEquals(securityGroupState.id, sgResponse.id());
assertEquals(sgResponse.securityRules().size(), securityGroupState.ingress.size());
validateAzureSecurityRules(sgResponse.securityRules(), securityGroupState.ingress.size() - 1);
// delete the security group
startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
}
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureLoadBalancerService method updateSecurityGroupRules.
/**
* Update isolation security group with rule to allow traffic on load balancing ports for VMs
* being load balanced
*
* @param context Azure load balancer context
* @return DeferredResult
*/
private DeferredResult<AzureLoadBalancerContext> updateSecurityGroupRules(AzureLoadBalancerContext context) {
if (CollectionUtils.isEmpty(context.securityGroupInners)) {
return DeferredResult.completed(context);
}
// Add security group firewall rules to allow traffic to flow through load balancer routes
updateSecurityRules(context);
NetworkSecurityGroupsInner azureSecurityGroupClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
List<DeferredResult<NetworkSecurityGroupInner>> networkSecurityGroupInnerList = context.securityGroupInners.stream().map(networkSecurityGroupInner -> {
final String msg = "Updating security group rules for [" + networkSecurityGroupInner.name() + "] for load balancer [" + context.loadBalancerStateExpanded.name + "].";
logInfo(() -> msg);
return AzureSecurityGroupUtils.createOrUpdateSecurityGroup(this, azureSecurityGroupClient, AzureUtils.getResourceGroupName(networkSecurityGroupInner.id()), networkSecurityGroupInner.name(), networkSecurityGroupInner, msg);
}).collect(Collectors.toList());
return DeferredResult.allOf(networkSecurityGroupInnerList).thenApply(ignored -> context);
}
Aggregations