use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState 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.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState 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.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState 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.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.
the class TestAWSEnumerationTask method validateSecurityGroupTagLinks.
/**
* Validates the taglinks for the security group to follow the expected norm
* i.e. /resources/security-groups/UUID
*/
private void validateSecurityGroupTagLinks(Map<String, SecurityGroupState> allSecurityGroupStatesMap) {
for (Map.Entry<String, SecurityGroupState> securityGroupState : allSecurityGroupStatesMap.entrySet()) {
Set<String> tagLinks = securityGroupState.getValue().tagLinks;
if (tagLinks != null) {
for (String tag : tagLinks) {
assertTrue(tag.startsWith(TagService.FACTORY_LINK));
}
}
TagService.TagState expectedInternalTypeTag = newTagState(TAG_KEY_TYPE, AWSConstants.AWSResourceType.ec2_security_group.toString(), false, securityGroupState.getValue().tenantLinks);
assertTrue(tagLinks.contains(expectedInternalTypeTag.documentSelfLink));
}
}
use of com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState in project photon-model by vmware.
the class TestAWSSetupUtils method createAWSNicStates.
/*
* NOTE: It is highly recommended to keep this method in sync with its Azure counterpart:
* AzureTestUtil.createDefaultNicStates
*/
public static List<NetworkInterfaceState> createAWSNicStates(VerificationHost host, ComputeState computeHost, EndpointState endpointState, String vmName, AwsNicSpecs nicSpecs, boolean addNewSecurityGroup, Map<String, Object> awsTestContext) throws Throwable {
// Create network state.
NetworkState networkState;
{
networkState = new NetworkState();
networkState.id = nicSpecs.network.id;
networkState.name = nicSpecs.network.name;
networkState.subnetCIDR = nicSpecs.network.cidr;
networkState.authCredentialsLink = endpointState.authCredentialsLink;
networkState.resourcePoolLink = computeHost.resourcePoolLink;
networkState.instanceAdapterReference = UriUtils.buildUri(host, AWSUriPaths.AWS_NETWORK_ADAPTER);
networkState.regionId = regionId;
networkState.endpointLink = endpointState.documentSelfLink;
networkState.endpointLinks = new HashSet<String>();
networkState.endpointLinks.add(endpointState.documentSelfLink);
networkState.tenantLinks = endpointState.tenantLinks;
networkState.computeHostLink = computeHost.documentSelfLink;
networkState = TestUtils.doPost(host, networkState, NetworkState.class, UriUtils.buildUri(host, NetworkService.FACTORY_LINK));
}
// Create NIC states.
List<NetworkInterfaceState> nics = new ArrayList<>();
for (int i = 0; i < nicSpecs.nicSpecs.size(); i++) {
// Create subnet state per NIC.
SubnetState subnetState;
{
subnetState = new SubnetState();
subnetState.id = nicSpecs.nicSpecs.get(i).subnetSpec.id;
subnetState.name = nicSpecs.nicSpecs.get(i).subnetSpec.name;
subnetState.subnetCIDR = nicSpecs.nicSpecs.get(i).subnetSpec.cidr;
subnetState.zoneId = nicSpecs.nicSpecs.get(i).subnetSpec.zoneId;
subnetState.networkLink = networkState.documentSelfLink;
subnetState.regionId = regionId;
subnetState.endpointLink = endpointState.documentSelfLink;
subnetState.endpointLinks = new HashSet<String>();
subnetState.endpointLinks.add(endpointState.documentSelfLink);
subnetState.tenantLinks = endpointState.tenantLinks;
subnetState = TestUtils.doPost(host, subnetState, SubnetState.class, UriUtils.buildUri(host, SubnetService.FACTORY_LINK));
}
// Create NIC description.
NetworkInterfaceDescription nicDescription;
NicSpec nicSpec = nicSpecs.nicSpecs.get(0);
{
nicDescription = new NetworkInterfaceDescription();
nicDescription.id = "nicDesc" + i;
nicDescription.name = "nicDesc" + i;
nicDescription.deviceIndex = i;
nicDescription.assignment = nicSpec.getIpAssignment();
nicDescription.regionId = regionId;
nicDescription.endpointLink = endpointState.documentSelfLink;
nicDescription.endpointLinks = new HashSet<String>();
nicDescription.endpointLinks.add(endpointState.documentSelfLink);
nicDescription.tenantLinks = endpointState.tenantLinks;
nicDescription = TestUtils.doPost(host, nicDescription, NetworkInterfaceDescription.class, UriUtils.buildUri(host, NetworkInterfaceDescriptionService.FACTORY_LINK));
}
// Create security group state for an existing security group
SecurityGroupState existingSecurityGroupState = createSecurityGroupState(host, computeHost, endpointState, true, awsTestContext);
NetworkInterfaceState nicState = new NetworkInterfaceState();
nicState.id = UUID.randomUUID().toString();
nicState.name = vmName + "-nic-" + i;
nicState.deviceIndex = nicDescription.deviceIndex;
nicState.networkLink = networkState.documentSelfLink;
nicState.subnetLink = subnetState.documentSelfLink;
nicState.networkInterfaceDescriptionLink = nicDescription.documentSelfLink;
nicState.regionId = regionId;
nicState.endpointLink = endpointState.documentSelfLink;
nicState.endpointLinks = new HashSet<String>();
nicState.endpointLinks.add(endpointState.documentSelfLink);
nicState.tenantLinks = endpointState.tenantLinks;
nicState.securityGroupLinks = new ArrayList<>();
nicState.securityGroupLinks.add(existingSecurityGroupState.documentSelfLink);
if (addNewSecurityGroup) {
// Create security group state for a new security group
SecurityGroupState newSecurityGroupState = createSecurityGroupState(host, computeHost, endpointState, false, awsTestContext);
nicState.securityGroupLinks.add(newSecurityGroupState.documentSelfLink);
}
nicState = TestUtils.doPost(host, nicState, NetworkInterfaceState.class, UriUtils.buildUri(host, NetworkInterfaceService.FACTORY_LINK));
nics.add(nicState);
}
return nics;
}
Aggregations