JCLOUDS-1105: Do not create the default security group if custom groups are specified
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/bde70457 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/bde70457 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/bde70457 Branch: refs/heads/master Commit: bde70457d0e313497eee08175ef9397fcad825df Parents: 71b3a2b Author: Ignasi Barrera <[email protected]> Authored: Thu Apr 21 17:14:56 2016 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Fri Jun 17 22:18:35 2016 +0200 ---------------------------------------------------------------------- ...curityGroupsAsNeededAndReturnRunOptions.java | 11 +++------ ...tyGroupsAsNeededAndReturnRunOptionsTest.java | 13 ++-------- ...tyGroupsAsNeededAndReturnRunOptionsTest.java | 26 +++----------------- 3 files changed, 10 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/bde70457/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java ---------------------------------------------------------------------- diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java index e860fa1..32a6bae 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.java @@ -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(); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/bde70457/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java ---------------------------------------------------------------------- diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 055eebe..8e9f062 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -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); http://git-wip-us.apache.org/repos/asf/jclouds/blob/bde70457/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 27f20b1..f73ebc1 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -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);
