From 2642882f03b8bf0b17f56808c6c75ce1625f914a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 11 Oct 2011 17:52:58 -0700 Subject: [PATCH] Issue 718:update to latest amazon linux --- .../aws/ec2/AWSEC2PropertiesBuilder.java | 5 ++-- .../AWSEC2ComputeServiceContextModule.java | 30 ++++++++++++++----- .../compute/AWSEC2ComputeServiceLiveTest.java | 12 ++++---- .../services/AWSKeyPairClientLiveTest.java | 4 +-- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java index cef6121d8e..53c713569d 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2PropertiesBuilder.java @@ -45,9 +45,8 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde // from stopping->stopped state on an ec2 micro properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + ""); // auth fail sometimes happens in EC2, as the rc.local script that injects the - // authorized key executes after ssh has started. with amazon linux, ssh - // starts after package updates, which means that this value can be higher. - properties.setProperty("jclouds.ssh.max-retries", "10"); + // authorized key executes after ssh has started. + properties.setProperty("jclouds.ssh.max-retries", "7"); properties.setProperty("jclouds.ssh.retry-auth", "true"); properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com"); properties.putAll(Region.regionProperties()); diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java index 8da3c976e0..eb03f19ca7 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java @@ -38,11 +38,13 @@ import org.jclouds.aws.ec2.compute.suppliers.AWSRegionAndNameToImageSupplier; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.options.TemplateOptions; import org.jclouds.ec2.compute.config.EC2BindComputeStrategiesByClass; import org.jclouds.ec2.compute.config.EC2BindComputeSuppliersByClass; import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata; import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl; +import org.jclouds.ec2.compute.options.EC2TemplateOptions; import org.jclouds.ec2.compute.predicates.InstancePresent; import org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions; import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet; @@ -71,7 +73,7 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext install(new EC2BindComputeSuppliersByClass()); bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class); bind(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class).to( - CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class); + CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class); bind(EC2HardwareSupplier.class).to(AWSEC2HardwareSupplier.class); bind(EC2TemplateBuilderImpl.class).to(AWSEC2TemplateBuilderImpl.class); bind(EC2GetNodeMetadataStrategy.class).to(AWSEC2GetNodeMetadataStrategy.class); @@ -89,18 +91,30 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext @Provides @Singleton protected Supplier> provideRegionAndNameToImageSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final AWSRegionAndNameToImageSupplier supplier) { + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final AWSRegionAndNameToImageSupplier supplier) { return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( - authException, seconds, new Supplier>() { - @Override - public Cache get() { - return supplier.get(); - } - }); + authException, seconds, new Supplier>() { + @Override + public Cache get() { + return supplier.get(); + } + }); } @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { return template.osFamily(AMZN_LINUX).os64Bit(true); } + + /** + * With amazon linux 2011.09, ssh starts after package updates, which slows the boot process and + * runs us out of ssh retries (context property {@code "jclouds.ssh.max-retries"}). + * + * @see + * @see AWSEC2PropertiesBuilder#defaultProperties + */ + @Override + protected TemplateOptions provideTemplateOptions(Injector injector, TemplateOptions options) { + return options.as(EC2TemplateOptions.class).userData("#cloud-config\nrepo_upgrade: none\n".getBytes()); + } } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java index e56e401f11..9417c00bca 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceLiveTest.java @@ -78,7 +78,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { @Override @Test(dependsOnMethods = "testCompareSizes") public void testExtendedOptionsAndLogin() throws Exception { - //note that this is sensitive to regions that quickly fill spot requests + // note that this is sensitive to regions that quickly fill spot requests String region = "eu-west-1"; AWSSecurityGroupClient securityGroupClient = AWSEC2Client.class.cast(context.getProviderSpecificContext().getApi()) @@ -137,8 +137,9 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { assert first.getCredentials().identity != null : first; startedId = Iterables.getOnlyElement(nodes).getProviderId(); - - AWSRunningInstance instance = AWSRunningInstance.class.cast(getInstance(instanceClient, startedId)); + + AWSRunningInstance instance = AWSRunningInstance.class.cast(Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient + .describeInstancesInRegion(region, startedId)))); assertEquals(instance.getKeyName(), group); assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED); @@ -160,8 +161,9 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { + instance.getRegion(), group)); // make sure our dummy group has no rules - SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, - "jclouds#" + group + "#" + instance.getRegion())); + SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(instance + .getRegion(), "jclouds#" + group + "#" + instance.getRegion())); + assert secgroup.getIpPermissions().size() == 0 : secgroup; // try to run a script with the original keyPair diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java index d555060648..e292b0e411 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AWSKeyPairClientLiveTest.java @@ -65,7 +65,7 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live", sequential = true) +@Test(groups = "live", singleThreaded = true) public class AWSKeyPairClientLiveTest { private AWSKeyPairClient client; @@ -120,7 +120,7 @@ public class AWSKeyPairClientLiveTest { TemplateOptions options = computeContext.getComputeService().templateOptions(); - options.authorizePublicKey(keyPair.get("public")).as(AWSEC2TemplateOptions.class).spotPrice(0.3f); + options.authorizePublicKey(keyPair.get("public")).as(AWSEC2TemplateOptions.class); ComputeServiceContext noSshContext = null; try {