From 648d2f4236efad6572532dd6fa63445336f696e9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 16 Aug 2011 11:12:34 -0700 Subject: [PATCH] Issue 662:ec2 ami query syntax from < 1.1.0 doesn't work on >= 1.1.0 --- .../aws/ec2/AWSEC2PropertiesBuilder.java | 10 +++-- .../AWSEC2TemplateBuilderLiveTest.java | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 4 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 4126123015..b2f0e9e4d9 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 @@ -83,10 +83,12 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde if (props.containsKey(PROPERTY_EC2_AMI_OWNERS)) { StringBuilder query = new StringBuilder(); String owners = properties.remove(PROPERTY_EC2_AMI_OWNERS).toString(); - if (!"*".equals(owners) && !"".equals(owners)) - query.append("owner-id=").append(owners).append(';'); - if (!"".equals(owners)) + if ("*".equals(owners)) query.append("state=available;image-type=machine"); + else if (!"".equals(owners)) + query.append("owner-id=").append(owners).append(";state=available;image-type=machine"); + else if ("".equals(owners)) + query = new StringBuilder(); props.setProperty(PROPERTY_EC2_AMI_QUERY, query.toString()); Logger.getAnonymousLogger().warning( String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS, @@ -97,7 +99,7 @@ public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilde protected void warnAndReplaceIfUsingOldCCImageKey(Properties props) { if (props.containsKey(PROPERTY_EC2_CC_AMIs)) { String amis = properties.remove(PROPERTY_EC2_CC_AMIs).toString(); - String value = "image-id=" + amis.replace("us-east-1/", ""); + String value = ("".equals(amis)) ? "" : "image-id=" + amis.replace("us-east-1/", ""); props.setProperty(PROPERTY_EC2_CC_AMI_QUERY, value); Logger.getAnonymousLogger().warning( String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_CC_AMIs, diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index 459f94a515..406ea0d600 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -37,6 +37,7 @@ import org.jclouds.compute.domain.Template; import org.jclouds.ec2.compute.predicates.EC2ImagePredicates; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.RootDeviceType; +import org.jclouds.ec2.reference.EC2Constants; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.testng.annotations.Test; @@ -243,6 +244,42 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { } } + @Test + public void testTemplateBuilderWithNoOwnersParsesImageOnDemandDeprecated() throws IOException { + ComputeServiceContext context = null; + try { + Properties overrides = setupProperties(); + // set owners to nothing + overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMIs, ""); + overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); + + context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet + . of(new Log4JLoggingModule()), overrides); + + assertEquals(context.getComputeService().listImages().size(), 0); + + Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build(); + System.out.println(template.getHardware()); + assert (template.getImage().getProviderId().startsWith("ami-")) : template; + assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); + assertEquals(template.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); + assertEquals(template.getImage().getVersion(), "4.4.10"); + assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); + assertEquals(template.getLocation().getId(), "us-east-1"); + assertEquals(getCores(template.getHardware()), 2.0d); + assertEquals(template.getHardware().getId(), "m1.large"); // because it + // is 64bit + + // ensure we cache the new image for next time + assertEquals(context.getComputeService().listImages().size(), 1); + + } finally { + if (context != null) + context.close(); + } + } + @Test public void testTemplateBuilderWithLessRegions() throws IOException { ComputeServiceContext context = null;