fixed aws-ec2 template tests

This commit is contained in:
Adrian Cole 2011-11-13 13:28:28 +02:00
parent ae92c8005b
commit 8569771712
2 changed files with 47 additions and 33 deletions

View File

@ -231,7 +231,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
context = new ComputeServiceContextFactory().createContext(provider, context = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
assertEquals(context.getComputeService().templateBuilder().build(), defaultTemplate); assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString());
} finally { } finally {
if (context != null) if (context != null)
context.close(); context.close();
@ -245,7 +245,7 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseVersionedServiceLi
context = new ComputeServiceContextFactory().createContext(provider, context = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
assertEquals(context.getComputeService().templateBuilder().build(), defaultTemplate); assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString());
} finally { } finally {
if (context != null) if (context != null)
context.close(); context.close();

View File

@ -64,16 +64,18 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
@Override @Override
public boolean apply(OsFamilyVersion64Bit input) { public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) { switch (input.family) {
case UBUNTU: case UBUNTU:
return true; return true;
case DEBIAN: case DEBIAN:
return true; return true;
case CENTOS: case CENTOS:
return input.version.matches("5.[246]") || input.version.equals(""); return input.version.matches("5.[246]") || (input.version.equals("5.0") && !input.is64Bit)
case WINDOWS: || input.version.equals("");
return input.version.matches("200[38]") || input.version.equals(""); case WINDOWS:
default: return input.version.matches("200[38]") || (input.version.equals("7") && !input.is64Bit)
return false; || input.version.equals("");
default:
return false;
} }
} }
@ -81,14 +83,20 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
} }
@Test @Test
public void testTemplateBuilderM1SMALLWithDescriptionPrecise() { public void testTemplateBuilderM1SMALLWithNegativeLookaroundDoesntMatchTestImages() {
Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL)
.osVersionMatches("1[012].[10][04]").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU) .osVersionMatches("1[012].[10][04]")
.build(); // negative lookahead for daily and testing, but ensure match
// ubuntu-images
// http://www.regular-expressions.info/lookaround.html
.imageDescriptionMatches("^(?!.*(daily|testing)).*ubuntu-images.*$").osFamily(OsFamily.UBUNTU).build();
assert (template.getImage().getProviderId().startsWith("ami-")) : template; assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "12.04"); assert template.getImage().getDescription().indexOf("test") == -1 : template;
assert template.getImage().getDescription().indexOf("daily") == -1 : template;
assertEquals(template.getImage().getVersion(), "20111011");
assertEquals(template.getImage().getOperatingSystem().getVersion(), "11.10");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
@ -99,15 +107,20 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
} }
@Test @Test
public void testUbuntuInstanceStoreGoesM1SmallPrecise() { public void testUbuntuInstanceStoreGoesM1SmallNegativeLookaroundDoesntMatchTestImages() {
Template template = context.getComputeService().templateBuilder() Template template = context.getComputeService().templateBuilder()
.imageMatches(EC2ImagePredicates.rootDeviceType(RootDeviceType.INSTANCE_STORE)) .imageMatches(EC2ImagePredicates.rootDeviceType(RootDeviceType.INSTANCE_STORE))
.osVersionMatches("1[012].[10][04]").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU) .osVersionMatches("1[012].[10][04]")
.build(); // negative lookahead for daily and testing, but ensure match
// ubuntu-images
// http://www.regular-expressions.info/lookaround.html
.imageDescriptionMatches("^(?!.*(daily|testing)).*ubuntu-images.*$").osFamily(OsFamily.UBUNTU).build();
assert (template.getImage().getProviderId().startsWith("ami-")) : template; assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "12.04"); assert template.getImage().getDescription().indexOf("test") == -1 : template;
assert template.getImage().getDescription().indexOf("daily") == -1 : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "11.10");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), false); assertEquals(template.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
@ -116,11 +129,12 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
assertEquals(template.getHardware().getId(), InstanceType.M1_SMALL); assertEquals(template.getHardware().getId(), InstanceType.M1_SMALL);
assertEquals(template.getImage().getOperatingSystem().getArch(), "paravirtual"); assertEquals(template.getImage().getOperatingSystem().getArch(), "paravirtual");
} }
@Test @Test
public void testTemplateBuilderCanUseImageIdAndhardwareIdAndAZ() { public void testTemplateBuilderCanUseImageIdAndhardwareIdAndAZ() {
Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").hardwareId( Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5")
InstanceType.M2_2XLARGE).locationId("us-east-1a").build(); .hardwareId(InstanceType.M2_2XLARGE).locationId("us-east-1a").build();
System.out.println(template.getHardware()); System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template; assert (template.getImage().getProviderId().startsWith("ami-")) : template;
@ -150,7 +164,6 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
assertEquals(defaultTemplate.getImage().getOperatingSystem().getArch(), "paravirtual"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getArch(), "paravirtual");
} }
@Test @Test
public void testAmazonLinuxInstanceStore() throws IOException { public void testAmazonLinuxInstanceStore() throws IOException {
@ -169,7 +182,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
@Test @Test
public void testFastestTemplateBuilder() throws IOException { public void testFastestTemplateBuilder() throws IOException {
Template fastestTemplate = context.getComputeService().templateBuilder().fastest().osFamily(OsFamily.AMZN_LINUX) Template fastestTemplate = context.getComputeService().templateBuilder().fastest().osFamily(OsFamily.AMZN_LINUX)
.build(); .build();
assert (fastestTemplate.getImage().getProviderId().startsWith("ami-")) : fastestTemplate; assert (fastestTemplate.getImage().getProviderId().startsWith("ami-")) : fastestTemplate;
assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.CC1_4XLARGE); assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.CC1_4XLARGE);
assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "2011.09.2"); assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "2011.09.2");
@ -197,7 +210,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public void testTemplateBuilderMicro() throws IOException { public void testTemplateBuilderMicro() throws IOException {
Template microTemplate = context.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO) Template microTemplate = context.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO)
.osFamily(OsFamily.UBUNTU).osVersionMatches("10.10").os64Bit(true).build(); .osFamily(OsFamily.UBUNTU).osVersionMatches("10.10").os64Bit(true).build();
assert (microTemplate.getImage().getProviderId().startsWith("ami-")) : microTemplate; assert (microTemplate.getImage().getProviderId().startsWith("ami-")) : microTemplate;
assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "10.10"); assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "10.10");
@ -218,8 +231,8 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, ""); overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY, "");
overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY, ""); overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY, "");
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet context = new ComputeServiceContextFactory().createContext(provider,
.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
assertEquals(context.getComputeService().listImages().size(), 0); assertEquals(context.getComputeService().listImages().size(), 0);
@ -254,8 +267,8 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMIs, ""); overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_CC_AMIs, "");
overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "");
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet context = new ComputeServiceContextFactory().createContext(provider,
.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
assertEquals(context.getComputeService().listImages().size(), 0); assertEquals(context.getComputeService().listImages().size(), 0);
@ -289,8 +302,8 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
// set regions to only 1 // set regions to only 1
overrides.setProperty(PROPERTY_REGIONS, Region.US_EAST_1); overrides.setProperty(PROPERTY_REGIONS, Region.US_EAST_1);
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet context = new ComputeServiceContextFactory().createContext(provider,
.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
assert context.getComputeService().listImages().size() < this.context.getComputeService().listImages().size(); assert context.getComputeService().listImages().size() < this.context.getComputeService().listImages().size();
@ -304,7 +317,8 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 2.0d); assertEquals(getCores(template.getHardware()), 2.0d);
assertEquals(template.getHardware().getId(), "m1.large"); // because it is 64bit assertEquals(template.getHardware().getId(), "m1.large"); // because it
// is 64bit
} finally { } finally {
if (context != null) if (context != null)
@ -314,7 +328,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
@Override @Override
protected Set<String> getIso3166Codes() { protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of("US-VA", "US-CA", "IE", "SG", "JP-13"); return ImmutableSet.<String> of("US-VA", "US-CA", "US-OR", "IE", "SG", "JP-13");
} }
} }