From 569c07b982728a456f50eab728c57cf98a10a720 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Wed, 8 Jul 2015 17:44:45 +0200 Subject: [PATCH] Fix AWS and EC2 TemplateBuilder live tests --- .../compute/options/EC2TemplateOptions.java | 4 +- .../ElasticBlockStoreApiLiveTest.java | 54 ++++++++++--------- .../internal/BaseComputeServiceLiveTest.java | 5 ++ .../compute/AWSEC2ComputeServiceLiveTest.java | 23 ++++++++ .../AWSEC2TemplateBuilderLiveTest.java | 26 ++++++++- 5 files changed, 83 insertions(+), 29 deletions(-) diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java index a56d6405cb..2a46b1aeb1 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/options/EC2TemplateOptions.java @@ -104,7 +104,7 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable { EC2TemplateOptions that = EC2TemplateOptions.class.cast(o); return super.equals(that) && equal(this.groupNames, that.groupNames) && equal(this.keyPair, that.keyPair) && equal(this.noKeyPair, that.noKeyPair) && equal(this.userData, that.userData) - && equal(this.blockDeviceMappings, that.blockDeviceMappings) + && equal(this.blockDeviceMappings.build(), that.blockDeviceMappings.build()) && equal(this.maxCount, that.maxCount) && equal(this.clientToken, that.clientToken); } @@ -112,7 +112,7 @@ public class EC2TemplateOptions extends TemplateOptions implements Cloneable { @Override public int hashCode() { return Objects - .hashCode(super.hashCode(), groupNames, keyPair, noKeyPair, userData, userData, blockDeviceMappings, + .hashCode(super.hashCode(), groupNames, keyPair, noKeyPair, userData, userData, blockDeviceMappings.build(), maxCount, clientToken); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/features/ElasticBlockStoreApiLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/features/ElasticBlockStoreApiLiveTest.java index ac3cf2931e..5f8a399b8c 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/features/ElasticBlockStoreApiLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/features/ElasticBlockStoreApiLiveTest.java @@ -17,6 +17,7 @@ package org.jclouds.ec2.features; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.getOnlyElement; import static java.util.concurrent.TimeUnit.SECONDS; import static org.jclouds.ec2.options.CreateVolumeOptions.Builder.fromSnapshotId; import static org.jclouds.ec2.options.CreateVolumeOptions.Builder.withSize; @@ -25,28 +26,30 @@ import static org.jclouds.util.Predicates2.retry; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.util.Set; import java.util.SortedSet; -import com.google.common.base.Predicate; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; import org.jclouds.aws.AWSResponseException; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.ec2.EC2Api; import org.jclouds.ec2.domain.AvailabilityZoneInfo; import org.jclouds.ec2.domain.Snapshot; import org.jclouds.ec2.domain.Volume; +import org.jclouds.ec2.domain.Volume.Status; import org.jclouds.ec2.predicates.SnapshotCompleted; import org.jclouds.ec2.predicates.VolumeAvailable; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.base.Predicate; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + /** * Tests behavior of {@code ElasticBlockStoreApi} */ @@ -112,9 +115,9 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT assertNotNull(allResults); assertFalse(allResults.isEmpty()); Volume volume = allResults.last(); - SortedSet result = Sets.newTreeSet(client.describeVolumesInRegionWithFilter(region, + client.describeVolumesInRegionWithFilter(region, ImmutableMultimap.builder() - .put("invalid-filter", volume.getId()).build())); + .put("invalid-filter", volume.getId()).build()); } @Test @@ -139,7 +142,7 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT Predicate snapshotted = retry(new SnapshotCompleted(client), 600, 10, SECONDS); assert snapshotted.apply(snapshot); - Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(snapshot.getRegion(), + Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegion(defaultRegion, snapshotIds(snapshot.getId()))); assertEquals(result.getProgress(), 100); @@ -154,13 +157,13 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT Predicate availabile = retry(new VolumeAvailable(client), 600, 10, SECONDS); assert availabile.apply(volume); - Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); + Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(defaultRegion, volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); assertEquals(volume.getAvailabilityZone(), defaultZone); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); - client.deleteVolumeInRegion(snapshot.getRegion(), result.getId()); + client.deleteVolumeInRegion(defaultRegion, result.getId()); } @Test(dependsOnMethods = "testCreateVolumeFromSnapshotInAvailabilityZone") @@ -172,13 +175,13 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT Predicate availabile = retry(new VolumeAvailable(client), 600, 10, SECONDS); assert availabile.apply(volume); - Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); + Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(defaultRegion, volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); assertEquals(volume.getAvailabilityZone(), defaultZone); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); - client.deleteVolumeInRegion(snapshot.getRegion(), result.getId()); + client.deleteVolumeInRegion(defaultRegion, result.getId()); } @Test(dependsOnMethods = "testCreateVolumeFromSnapshotInAvailabilityZoneWithOptions") @@ -189,14 +192,14 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT Predicate availabile = retry(new VolumeAvailable(client), 600, 10, SECONDS); assert availabile.apply(volume); - Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(snapshot.getRegion(), volume.getId())); + Volume result = Iterables.getOnlyElement(client.describeVolumesInRegion(defaultRegion, volume.getId())); assertEquals(volume.getId(), result.getId()); assertEquals(volume.getSnapshotId(), snapshot.getId()); assertEquals(volume.getAvailabilityZone(), defaultZone); assertEquals(volume.getSize(), 2); assertEquals(result.getStatus(), Volume.Status.AVAILABLE); - client.deleteVolumeInRegion(snapshot.getRegion(), result.getId()); + client.deleteVolumeInRegion(defaultRegion, result.getId()); } @Test @@ -245,9 +248,9 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT assertNotNull(allResults); if (!allResults.isEmpty()) { Snapshot snapshot = allResults.last(); - Snapshot result = Iterables.getOnlyElement(client.describeSnapshotsInRegionWithFilter(region, + client.describeSnapshotsInRegionWithFilter(region, ImmutableMultimap.builder() - .put("invalid-filter", snapshot.getId()).build())); + .put("invalid-filter", snapshot.getId()).build()); } } @@ -277,29 +280,30 @@ public class ElasticBlockStoreApiLiveTest extends BaseComputeServiceContextLiveT @Test(dependsOnMethods = "testCreateVolumeFromSnapshotInAvailabilityZoneWithSize") public void testGetCreateVolumePermissionForSnapshot() { - client.getCreateVolumePermissionForSnapshotInRegion(snapshot.getRegion(), snapshot.getId()); + client.getCreateVolumePermissionForSnapshotInRegion(defaultRegion, snapshot.getId()); } @Test(dependsOnMethods = "testGetCreateVolumePermissionForSnapshot") void testDeleteVolumeInRegion() { client.deleteVolumeInRegion(defaultRegion, volumeId); - assertEquals(client.describeVolumesInRegionWithFilter(defaultRegion, - ImmutableMultimap.builder() - .put("volume-id", volumeId).build()), - ImmutableSet.of()); + Set volumes = client.describeVolumesInRegionWithFilter(defaultRegion, ImmutableMultimap + . builder().put("volume-id", volumeId).build()); + // The volume may not exist or remain in "deleting" state for a while + Volume volume = getOnlyElement(volumes, null); + assertTrue(volume == null || Status.DELETING == volume.getStatus()); } @Test(dependsOnMethods = "testDeleteVolumeInRegion") void testDeleteSnapshotInRegion() { - client.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId()); - assert client.describeSnapshotsInRegion(snapshot.getRegion(), snapshotIds(snapshot.getId())).size() == 0; + client.deleteSnapshotInRegion(defaultRegion, snapshot.getId()); + assert client.describeSnapshotsInRegion(defaultRegion, snapshotIds(snapshot.getId())).size() == 0; } @AfterClass(groups = { "integration", "live" }) @Override protected void tearDownContext() { try { - client.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId()); + client.deleteSnapshotInRegion(defaultRegion, snapshot.getId()); client.deleteVolumeInRegion(defaultRegion, volumeId); } catch (Exception e) { // we don't really care about any exception here, so just delete away. diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java index a0da138914..49033d2f11 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java @@ -852,6 +852,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte @Test(enabled = true) public void testCompareSizes() throws Exception { + // Allow to override the comparison but keeping testng dependencies happy + doCompareSizes(); + } + + protected void doCompareSizes() throws Exception { Hardware defaultSize = client.templateBuilder().build().getHardware(); Hardware smallest = client.templateBuilder().smallest().build().getHardware(); 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 9c32843994..477ac3c088 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 @@ -20,6 +20,7 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Sets.newTreeSet; import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX; import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.ec2.util.IpPermissions.permit; import static org.testng.Assert.assertEquals; @@ -41,6 +42,7 @@ import org.jclouds.cloudwatch.domain.GetMetricStatisticsResponse; import org.jclouds.cloudwatch.domain.Statistics; import org.jclouds.cloudwatch.domain.Unit; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; import org.jclouds.compute.predicates.NodePredicates; @@ -189,4 +191,25 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest { cleanupExtendedStuffInRegion(region, securityGroupApi, keyPairApi, group); } } + + @Override + protected void doCompareSizes() throws Exception { + Hardware defaultSize = view.getComputeService().templateBuilder().build().getHardware(); + + Hardware smallest = view.getComputeService().templateBuilder().smallest().build().getHardware(); + Hardware fastest = view.getComputeService().templateBuilder().fastest().build().getHardware(); + Hardware biggest = view.getComputeService().templateBuilder().biggest().build().getHardware(); + + assertEquals(defaultSize, smallest); + + assert getCores(smallest) <= getCores(fastest) : String.format("%s ! <= %s", smallest, fastest); + // m4.10xlarge is slower but has more cores than c4.8xlarge + // assert getCores(biggest) <= getCores(fastest) : String.format("%s ! <= %s", biggest, fastest); + // assert getCores(fastest) >= getCores(biggest) : String.format("%s ! >= %s", fastest, biggest); + + assert biggest.getRam() >= fastest.getRam() : String.format("%s ! >= %s", biggest, fastest); + assert biggest.getRam() >= smallest.getRam() : String.format("%s ! >= %s", biggest, smallest); + + assert getCores(fastest) >= getCores(smallest) : String.format("%s ! >= %s", fastest, smallest); + } } 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 a639450a88..af3cc1a004 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 @@ -32,6 +32,7 @@ import org.jclouds.aws.ec2.AWSEC2Api; import org.jclouds.aws.ec2.AWSEC2ProviderMetadata; import org.jclouds.aws.ec2.reference.AWSEC2Constants; import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.ec2.EC2Api; @@ -122,7 +123,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { public void testTemplateBuilderCanUseImageIdAndHardwareIdAndAZ() { Template template = view.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5") - .hardwareId(InstanceType.M2_2XLARGE).locationId("us-east-1a").build(); + .hardwareId(InstanceType.M2_2XLARGE).locationId("us-east-1b").build(); assert template.getImage().getProviderId().startsWith("ami-") : template; assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); @@ -130,7 +131,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { 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-1a"); + assertEquals(template.getLocation().getId(), "us-east-1b"); assertEquals(template.getImage().getLocation().getId(), "us-east-1"); assertEquals(getCores(template.getHardware()), 4.0d); assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE); @@ -326,6 +327,27 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest { assertEquals(defaultTemplate.getImage().getId(), imageId); } + @Override + public void testCompareSizes() throws Exception { + Hardware defaultSize = view.getComputeService().templateBuilder().build().getHardware(); + + Hardware smallest = view.getComputeService().templateBuilder().smallest().build().getHardware(); + Hardware fastest = view.getComputeService().templateBuilder().fastest().build().getHardware(); + Hardware biggest = view.getComputeService().templateBuilder().biggest().build().getHardware(); + + assertEquals(defaultSize, smallest); + + assert getCores(smallest) <= getCores(fastest) : String.format("%s ! <= %s", smallest, fastest); + // m4.10xlarge is slower but has more cores than c4.8xlarge + // assert getCores(biggest) <= getCores(fastest) : String.format("%s ! <= %s", biggest, fastest); + // assert getCores(fastest) >= getCores(biggest) : String.format("%s ! >= %s", fastest, biggest); + + assert biggest.getRam() >= fastest.getRam() : String.format("%s ! >= %s", biggest, fastest); + assert biggest.getRam() >= smallest.getRam() : String.format("%s ! >= %s", biggest, smallest); + + assert getCores(fastest) >= getCores(smallest) : String.format("%s ! >= %s", fastest, smallest); + } + @Test public void testAssignability() { view.unwrapApi(EC2Api.class);