JCLOUDS-1105: Do not create the default security group if custom groups are specified

This commit is contained in:
Ignasi Barrera 2016-04-21 17:14:56 +02:00
parent 71b3a2b631
commit bde70457d0
3 changed files with 10 additions and 40 deletions

View File

@ -167,19 +167,16 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions {
if (group != null) {
String markerGroup = namingConvention.create().sharedNameForGroup(group);
RegionNameAndIngressRules regionNameAndIngressRulesForMarkerGroup;
if (userSpecifiedTheirOwnGroups(options)) {
regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, new int[] {},
false, vpcId);
groups.addAll(EC2TemplateOptions.class.cast(options).getGroups());
} else {
regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options
RegionNameAndIngressRules regionNameAndIngressRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options
.getInboundPorts(), true, vpcId);
// this will create if not yet exists.
groups.add(securityGroupMap.getUnchecked(regionNameAndIngressRulesForMarkerGroup));
}
// this will create if not yet exists.
groups.add(securityGroupMap.getUnchecked(regionNameAndIngressRulesForMarkerGroup));
}
return groups.build();
}

View File

@ -511,16 +511,12 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest {
verifyStrategy(strategy);
}
public void testGetSecurityGroupsForTagAndOptions_reusesGroupByDefaultWhenNoPortsAreSpecifiedWhenDoesExistAndAcceptsUserSuppliedGroups() {
public void testGetSecurityGroupsForTagAndOptions_DoesNorReuseGroupByDefaultWhenNoPortsAreSpecifiedWhenDoesExistAndAcceptsUserSuppliedGroups() {
// setup constants
String region = Region.AP_SOUTHEAST_1;
String group = "group";
String generatedMarkerGroup = "jclouds#group";
Set<String> groupIds = ImmutableSet.<String> of("group1", "group2");
int[] ports = {};
boolean shouldAuthorizeSelf = true;
boolean groupExisted = true;
Set<String> returnVal = ImmutableSet.<String> of(generatedMarkerGroup, "group1", "group2");
Set<String> returnVal = ImmutableSet.<String> of("group1", "group2");
// create mocks
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy();
@ -528,11 +524,6 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest {
// setup expectations
expect(options.getGroups()).andReturn(groupIds).atLeastOnce();
RegionNameAndIngressRules regionNameAndIngressRules = new RegionNameAndIngressRules(region, generatedMarkerGroup,
ports, shouldAuthorizeSelf, null);
expect(strategy.securityGroupMap.getUnchecked(regionNameAndIngressRules))
.andReturn(groupExisted ? generatedMarkerGroup : null);
// replay mocks
replay(options);

View File

@ -757,16 +757,12 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
verifyStrategy(strategy);
}
public void testGetSecurityGroupsForTagAndOptions_reusesGroupByDefaultWhenNoPortsAreSpecifiedWhenDoesExistAndAcceptsUserSuppliedGroups() {
public void testGetSecurityGroupsForTagAndOptions_DoesNotReuseGroupByDefaultWhenNoPortsAreSpecifiedWhenDoesExistAndAcceptsUserSuppliedGroups() {
// setup constants
String region = Region.AP_SOUTHEAST_1;
String group = "group";
String generatedMarkerGroup = "jclouds#group";
Set<String> groupNames = ImmutableSet.<String> of("group1", "group2");
int[] ports = {};
boolean shouldAuthorizeSelf = true;
boolean groupExisted = true;
Set<String> returnVal = ImmutableSet.<String> of("sg-12345", "group1", "group2");
Set<String> returnVal = ImmutableSet.<String> of("group1", "group2");
// create mocks
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy();
@ -775,11 +771,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
// setup expectations
expect(options.getGroupIds()).andReturn(ImmutableSet.<String> of());
expect(options.getGroups()).andReturn(groupNames).atLeastOnce();
RegionNameAndIngressRules regionNameAndIngressRules = new RegionNameAndIngressRules(region, generatedMarkerGroup,
ports, shouldAuthorizeSelf, null);
expect(strategy.securityGroupMap.getUnchecked(regionNameAndIngressRules))
.andReturn(groupExisted ? "sg-12345" : null);
// replay mocks
replay(options);
@ -793,16 +784,12 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
verifyStrategy(strategy);
}
public void testGetSecurityGroupsForTagAndOptions_reusesGroupByDefaultWhenNoPortsAreSpecifiedWhenDoesExistAndAcceptsUserSuppliedGroupIds() {
public void testGetSecurityGroupsForTagAndOptions_DoesNotReuseGroupByDefaultWhenNoPortsAreSpecifiedWhenDoesExistAndAcceptsUserSuppliedGroupIds() {
// setup constants
String region = Region.AP_SOUTHEAST_1;
String group = "group";
String generatedMarkerGroup = "jclouds#group";
Set<String> groupNames = ImmutableSet.<String> of();
int[] ports = {};
boolean shouldAuthorizeSelf = true;
boolean groupExisted = true;
Set<String> returnVal = ImmutableSet.<String> of("sg-12345");
Set<String> returnVal = ImmutableSet.<String> of();
// create mocks
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy();
@ -811,11 +798,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
// setup expectations
expect(options.getGroupIds()).andReturn(ImmutableSet.<String> of("group1", "group2"));
expect(options.getGroups()).andReturn(groupNames).atLeastOnce();
RegionNameAndIngressRules regionNameAndIngressRules = new RegionNameAndIngressRules(region, generatedMarkerGroup,
ports, shouldAuthorizeSelf, null);
expect(strategy.securityGroupMap.getUnchecked(regionNameAndIngressRules))
.andReturn(groupExisted ? "sg-12345" : null);
// replay mocks
replay(options);