added test to aws for unknown instance type

This commit is contained in:
Adrian Cole 2010-09-18 11:20:07 -07:00
parent e94ee94cd4
commit 2b918d5827
1 changed files with 140 additions and 64 deletions

View File

@ -83,7 +83,7 @@ public class RunningInstanceToNodeMetadataTest {
DateService dateService = new SimpleDateFormatDateService(); DateService dateService = new SimpleDateFormatDateService();
@SuppressWarnings( { "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException { public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
@ -92,7 +92,7 @@ public class RunningInstanceToNodeMetadataTest {
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M1_SMALL)); .<Hardware> of(EC2Hardware.M1_SMALL));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -104,7 +104,7 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
expect(instance.getIpAddress()).andReturn("174.129.1.50"); expect(instance.getIpAddress()).andReturn("174.129.1.50");
@ -118,21 +118,24 @@ public class RunningInstanceToNodeMetadataTest {
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn( expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
(Set) ImmutableSet.<Image> of(image)); (Set) ImmutableSet.<Image> of(image));
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn( expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce(); expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
expect(instance.getEbsBlockDevices()).andReturn( expect(instance.getEbsBlockDevices()).andReturn(
ImmutableMap.<String, EbsBlockDevice> of("/dev/sdg", new EbsBlockDevice("vol-1f20d376", ImmutableMap.<String, EbsBlockDevice> of(
Attachment.Status.ATTACHED, dateService.iso8601DateParse("2009-12-11T16:32:46.000Z"), false), "/dev/sdg",
"/dev/sdj", new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService new EbsBlockDevice("vol-1f20d376", Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2010-06-17T10:43:28.000Z"), false))); .iso8601DateParse("2009-12-11T16:32:46.000Z"), false),
"/dev/sdj",
new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2010-06-17T10:43:28.000Z"), false)));
expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE); expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce(); expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce();
@ -145,7 +148,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
@ -157,11 +160,11 @@ public class RunningInstanceToNodeMetadataTest {
assertEquals(metadata.getHardware().getProviderId(), "m1.small"); assertEquals(metadata.getHardware().getProviderId(), "m1.small");
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0))); assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
assertEquals(metadata.getHardware().getRam(), 1740); assertEquals(metadata.getHardware().getRam(), 1740);
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null, assertEquals(metadata.getHardware().getVolumes(),
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),//
new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),// new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),//
new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true))); new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true)));
assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
@ -175,16 +178,16 @@ public class RunningInstanceToNodeMetadataTest {
} }
@SuppressWarnings( { "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyForEucalyptusWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException { public void testApplyForNovaWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M1_SMALL)); .<Hardware> of(EC2Hardware.M1_SMALL));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -196,7 +199,7 @@ public class RunningInstanceToNodeMetadataTest {
Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null); Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(region)); .<Location> of(region));
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
expect(instance.getIpAddress()).andReturn(null); expect(instance.getIpAddress()).andReturn(null);
@ -210,7 +213,7 @@ public class RunningInstanceToNodeMetadataTest {
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn( expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
(Set) ImmutableSet.<Image> of(image)); (Set) ImmutableSet.<Image> of(image));
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
@ -231,7 +234,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
@ -243,9 +246,9 @@ public class RunningInstanceToNodeMetadataTest {
assertEquals(metadata.getHardware().getProviderId(), "m1.small"); assertEquals(metadata.getHardware().getProviderId(), "m1.small");
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0))); assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
assertEquals(metadata.getHardware().getRam(), 1740); assertEquals(metadata.getHardware().getRam(), 1740);
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null, assertEquals(metadata.getHardware().getVolumes(),
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false))); new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
assertEquals(metadata.getCredentials(), new Credentials("user", null)); assertEquals(metadata.getCredentials(), new Credentials("user", null));
@ -259,19 +262,19 @@ public class RunningInstanceToNodeMetadataTest {
} }
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings( { "unchecked", "rawtypes" })
@Test @Test
public void testApplyForEucalyptusWhereImageNotFound() throws UnknownHostException { public void testApplyWhereUnknownInstanceType() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class); AMIClient amiClient = createMock(AMIClient.class);
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M1_SMALL)); .<Hardware> of(EC2Hardware.M1_SMALL));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class);
expect(instance.getId()).andReturn("i-3d640055").atLeastOnce(); expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
@ -280,7 +283,7 @@ public class RunningInstanceToNodeMetadataTest {
Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null); Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(region)); .<Location> of(region));
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
expect(instance.getIpAddress()).andReturn(null); expect(instance.getIpAddress()).andReturn(null);
@ -294,10 +297,83 @@ public class RunningInstanceToNodeMetadataTest {
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn( expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
(Set) ImmutableSet.<Image> of()); (Set) ImmutableSet.<Image> of(image));
expect(credentialProvider.execute(null)).andReturn(new Credentials("root", null));
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
expect(instance.getInstanceType()).andReturn("hhttpp").atLeastOnce();
replay(imageMap);
replay(client);
replay(amiClient);
replay(credentialsMap);
replay(credentialProvider);
replay(instance);
replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getTag(), "NOTAG-i-3d640055");
assertEquals(metadata.getLocation(), region);
assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
assertEquals(metadata.getHardware(), null);
assertEquals(metadata.getCredentials(), new Credentials("user", null));
verify(imageMap);
verify(jcImage);
verify(client);
verify(amiClient);
verify(credentialsMap);
verify(credentialProvider);
verify(instance);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testApplyForNovaWhereImageNotFound() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class);
AMIClient amiClient = createMock(AMIClient.class);
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M1_SMALL));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class);
expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(region));
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
expect(instance.getIpAddress()).andReturn(null);
expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
(Set) ImmutableSet.<Image> of());
expect(credentialProvider.execute(null)).andReturn(new Credentials("root", null));
expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null); expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
@ -316,7 +392,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
@ -328,9 +404,9 @@ public class RunningInstanceToNodeMetadataTest {
assertEquals(metadata.getHardware().getProviderId(), "m1.small"); assertEquals(metadata.getHardware().getProviderId(), "m1.small");
assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0))); assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
assertEquals(metadata.getHardware().getRam(), 1740); assertEquals(metadata.getHardware().getRam(), 1740);
assertEquals(metadata.getHardware().getVolumes(), ImmutableList.<Volume> of(new VolumeImpl(null, assertEquals(metadata.getHardware().getVolumes(),
Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false))); new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
assertEquals(metadata.getCredentials(), new Credentials("root", null)); assertEquals(metadata.getCredentials(), new Credentials("root", null));
@ -357,9 +433,9 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -389,7 +465,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -418,9 +494,9 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -438,7 +514,7 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andThrow(new NullPointerException()) expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andThrow(new NullPointerException())
.atLeastOnce(); .atLeastOnce();
expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
@ -451,7 +527,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -480,9 +556,9 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -517,7 +593,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -547,9 +623,9 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -580,7 +656,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -608,9 +684,9 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -641,7 +717,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -658,7 +734,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(instance); verify(instance);
} }
@SuppressWarnings( { "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException { public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
@ -667,7 +743,7 @@ public class RunningInstanceToNodeMetadataTest {
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -679,7 +755,7 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
@ -693,12 +769,12 @@ public class RunningInstanceToNodeMetadataTest {
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage); expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn( expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
(Set) ImmutableSet.<Image> of(image)); (Set) ImmutableSet.<Image> of(image));
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn( expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
@ -713,7 +789,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getTag(), "tag"); assertEquals(metadata.getTag(), "tag");
@ -732,7 +808,7 @@ public class RunningInstanceToNodeMetadataTest {
} }
@SuppressWarnings( { "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyWithTwoSecurityGroups() throws UnknownHostException { public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
@ -741,7 +817,7 @@ public class RunningInstanceToNodeMetadataTest {
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE)); .<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -753,7 +829,7 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
@ -767,12 +843,12 @@ public class RunningInstanceToNodeMetadataTest {
expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage); expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn( expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
(Set) ImmutableSet.<Image> of(image)); (Set) ImmutableSet.<Image> of(image));
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn( expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
@ -787,7 +863,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, hardwares); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);