JCLOUDS-242. Fix security group creation on aws-ec2.

Contributed by Richard Downer.
This commit is contained in:
Andrew Bayer 2013-08-14 11:01:23 -07:00
parent 66e19a6bce
commit ffff38561a
3 changed files with 6 additions and 5 deletions

View File

@ -117,8 +117,9 @@ public class AWSEC2CreateSecurityGroupIfNeeded extends CacheLoader<RegionAndName
Set<IpPermission> perms = permissions.build(); Set<IpPermission> perms = permissions.build();
if (perms.size() > 0) { if (perms.size() > 0) {
String id = Iterables.get(securityClient.describeSecurityGroupsInRegion(region, name), 0).getId();
logger.debug(">> authorizing securityGroup region(%s) name(%s) IpPermissions(%s)", region, name, perms); logger.debug(">> authorizing securityGroup region(%s) name(%s) IpPermissions(%s)", region, name, perms);
securityClient.authorizeSecurityGroupIngressInRegion(region, name, perms); securityClient.authorizeSecurityGroupIngressInRegion(region, id, perms);
logger.debug("<< authorized securityGroup(%s)", name); logger.debug("<< authorized securityGroup(%s)", name);
} }

View File

@ -65,7 +65,7 @@ public abstract class BaseAWSEC2ComputeServiceExpectTest extends BaseEC2ComputeS
.endpoint("https://ec2." + region + ".amazonaws.com/") .endpoint("https://ec2." + region + ".amazonaws.com/")
.addHeader("Host", "ec2." + region + ".amazonaws.com") .addHeader("Host", "ec2." + region + ".amazonaws.com")
.addFormParam("Action", "AuthorizeSecurityGroupIngress") .addFormParam("Action", "AuthorizeSecurityGroupIngress")
.addFormParam("GroupId", "jclouds#test") .addFormParam("GroupId", "sg-3c6ef654")
.addFormParam("IpPermissions.0.FromPort", "22") .addFormParam("IpPermissions.0.FromPort", "22")
.addFormParam("IpPermissions.0.ToPort", "22") .addFormParam("IpPermissions.0.ToPort", "22")
.addFormParam("IpPermissions.0.IpRanges.0.CidrIp", "0.0.0.0/0") .addFormParam("IpPermissions.0.IpRanges.0.CidrIp", "0.0.0.0/0")

View File

@ -19,7 +19,6 @@ package org.jclouds.aws.ec2.compute.loaders;
import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify; import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -33,7 +32,6 @@ import org.jclouds.ec2.compute.domain.RegionNameAndIngressRules;
import org.jclouds.ec2.domain.IpPermission; import org.jclouds.ec2.domain.IpPermission;
import org.jclouds.ec2.domain.IpProtocol; import org.jclouds.ec2.domain.IpProtocol;
import org.jclouds.ec2.domain.SecurityGroup; import org.jclouds.ec2.domain.SecurityGroup;
import org.jclouds.ec2.domain.UserIdGroupPair;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -81,7 +79,9 @@ public class AWSEC2CreateSecurityGroupIfNeededTest {
client.createSecurityGroupInRegion("region", "group", "group"); client.createSecurityGroupInRegion("region", "group", "group");
expect(group.getOwnerId()).andReturn("ownerId"); expect(group.getOwnerId()).andReturn("ownerId");
client.authorizeSecurityGroupIngressInRegion("region", "group", permissions.build()); expect(group.getId()).andReturn("sg-123456");
expect(client.describeSecurityGroupsInRegion("region", "group")).andReturn(Set.class.cast(groups));
client.authorizeSecurityGroupIngressInRegion("region", "sg-123456", permissions.build());
expect(client.describeSecurityGroupsInRegion("region", "group")).andReturn(Set.class.cast(groups)); expect(client.describeSecurityGroupsInRegion("region", "group")).andReturn(Set.class.cast(groups));