mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 06:56:45 +00:00
minor volume test-related changes
This commit is contained in:
parent
c624c88274
commit
1f7211d32d
@ -284,28 +284,20 @@ public class Volume {
|
|||||||
return Collections.unmodifiableMap(this.metadata);
|
return Collections.unmodifiableMap(this.metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keeping fields short in eq/hashCode so that minor state differences don't affect collection membership
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(id, status, size, zone, created, attachments, volumeType, snapshotId, name, description, metadata);
|
return Objects.hashCode(id, zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj)
|
||||||
if (obj == null || getClass() != obj.getClass()) return false;
|
return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
Volume that = Volume.class.cast(obj);
|
Volume that = Volume.class.cast(obj);
|
||||||
return Objects.equal(this.id, that.id)
|
return Objects.equal(this.id, that.id) && Objects.equal(this.zone, that.zone);
|
||||||
&& Objects.equal(this.status, that.status)
|
|
||||||
&& Objects.equal(this.size, that.size)
|
|
||||||
&& Objects.equal(this.zone, that.zone)
|
|
||||||
&& Objects.equal(this.created, that.created)
|
|
||||||
&& Objects.equal(this.attachments, that.attachments)
|
|
||||||
&& Objects.equal(this.volumeType, that.volumeType)
|
|
||||||
&& Objects.equal(this.snapshotId, that.snapshotId)
|
|
||||||
&& Objects.equal(this.name, that.name)
|
|
||||||
&& Objects.equal(this.description, that.description)
|
|
||||||
&& Objects.equal(this.metadata, that.metadata)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ToStringHelper string() {
|
protected ToStringHelper string() {
|
||||||
|
@ -67,6 +67,9 @@ public class NovaErrorHandler implements HttpErrorHandler {
|
|||||||
exception = new ResourceNotFoundException(message, exception);
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 413:
|
||||||
|
exception = new InsufficientResourcesException(message, exception);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,6 @@ public class NovaErrorHandlerTest {
|
|||||||
IllegalStateException.class);
|
IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400MakesInsufficientResourcesExceptionOnQuotaExceeded() {
|
public void test400MakesInsufficientResourcesExceptionOnQuotaExceeded() {
|
||||||
assertCodeMakes(
|
assertCodeMakes(
|
||||||
@ -87,6 +86,17 @@ public class NovaErrorHandlerTest {
|
|||||||
"{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}",
|
"{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}",
|
||||||
InsufficientResourcesException.class);
|
InsufficientResourcesException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test413MakesInsufficientResourcesException() {
|
||||||
|
assertCodeMakes(
|
||||||
|
"POST",
|
||||||
|
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/os-volumes"),
|
||||||
|
413,
|
||||||
|
"HTTP/1.1 413 Request Entity Too Large",
|
||||||
|
"{\"badRequest\": {\"message\": \"Volume quota exceeded. You cannot create a volume of size 1G\", \"code\": 413, \"retryAfter\": 0}}",
|
||||||
|
InsufficientResourcesException.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test404MakesResourceNotFoundException() {
|
public void test404MakesResourceNotFoundException() {
|
||||||
|
@ -28,15 +28,11 @@ import java.util.Set;
|
|||||||
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.Server.Status;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.features.ImageClient;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.features.ServerClient;
|
import org.jclouds.openstack.nova.v1_1.features.ServerClient;
|
||||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
|
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,8 +106,7 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
continue;
|
continue;
|
||||||
FloatingIPClient client = clientOption.get();
|
FloatingIPClient client = clientOption.get();
|
||||||
ServerClient serverClient = novaContext.getApi().getServerClientForZone(zoneId);
|
ServerClient serverClient = novaContext.getApi().getServerClientForZone(zoneId);
|
||||||
Server server = serverClient.createServer("test", imageIdForZone(zoneId), flavorRefForZone(zoneId));
|
Server server = createServerInZone(zoneId);
|
||||||
blockUntilServerActive(server.getId(), serverClient);
|
|
||||||
FloatingIP floatingIP = client.allocate();
|
FloatingIP floatingIP = client.allocate();
|
||||||
assertNotNull(floatingIP);
|
assertNotNull(floatingIP);
|
||||||
try {
|
try {
|
||||||
@ -124,25 +119,6 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String imageIdForZone(String zoneId) {
|
|
||||||
ImageClient imageClient = novaContext.getApi().getImageClientForZone(zoneId);
|
|
||||||
return Iterables.getLast(imageClient.listImages()).getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String flavorRefForZone(String zoneId) {
|
|
||||||
FlavorClient flavorClient = novaContext.getApi().getFlavorClientForZone(zoneId);
|
|
||||||
return Iterables.getLast(flavorClient.listFlavors()).getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void blockUntilServerActive(String serverId, ServerClient client) throws InterruptedException {
|
|
||||||
Server currentDetails = null;
|
|
||||||
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != Status.ACTIVE; currentDetails = client
|
|
||||||
.getServer(serverId)) {
|
|
||||||
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
|
||||||
Thread.sleep(5 * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void assertEventually(Runnable assertion) {
|
protected static void assertEventually(Runnable assertion) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
AssertionError error = null;
|
AssertionError error = null;
|
||||||
|
@ -18,17 +18,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.v1_1.extensions;
|
package org.jclouds.openstack.nova.v1_1.extensions;
|
||||||
|
|
||||||
import static org.testng.Assert.*;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.openstack.domain.Resource;
|
import org.jclouds.openstack.nova.v1_1.domain.Volume;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.VolumeAttachment;
|
import org.jclouds.openstack.nova.v1_1.domain.VolumeAttachment;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.VolumeSnapshot;
|
import org.jclouds.openstack.nova.v1_1.domain.VolumeSnapshot;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.Volume;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
|
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
|
||||||
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeSnapshotOptions;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeOptions;
|
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeOptions;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeSnapshotOptions;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
@ -41,13 +42,13 @@ import com.google.common.collect.Iterables;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of VolumeClient
|
* Tests behavior of VolumeClient
|
||||||
*
|
*
|
||||||
* @author Adam Lowe
|
* @author Adam Lowe
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", testName = "VolumeClientLiveTest", singleThreaded = true)
|
@Test(groups = "live", testName = "VolumeClientLiveTest", singleThreaded = true)
|
||||||
public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
||||||
|
|
||||||
private VolumeClient client;
|
private Optional<VolumeClient> volumeOption;
|
||||||
private String zone;
|
private String zone;
|
||||||
|
|
||||||
private Volume testVolume;
|
private Volume testVolume;
|
||||||
@ -57,58 +58,61 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
@Override
|
@Override
|
||||||
public void setupContext() {
|
public void setupContext() {
|
||||||
super.setupContext();
|
super.setupContext();
|
||||||
zone = Iterables.getFirst(novaContext.getApi().getConfiguredZones(), "nova");
|
zone = Iterables.getLast(novaContext.getApi().getConfiguredZones(), "nova");
|
||||||
Optional<VolumeClient> optClient = novaContext.getApi().getVolumeExtensionForZone(zone);
|
volumeOption = novaContext.getApi().getVolumeExtensionForZone(zone);
|
||||||
if (optClient.isPresent()) {
|
|
||||||
client = optClient.get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(groups = "live", alwaysRun = true)
|
@AfterGroups(groups = "live", alwaysRun = true)
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() {
|
protected void tearDown() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
if (testSnapshot != null) {
|
if (testSnapshot != null) {
|
||||||
final String snapshotId = testSnapshot.getId();
|
final String snapshotId = testSnapshot.getId();
|
||||||
assertTrue(client.deleteSnapshot(snapshotId));
|
assertTrue(volumeOption.get().deleteSnapshot(snapshotId));
|
||||||
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(VolumeClient volumeClient) {
|
public boolean apply(VolumeClient volumeClient) {
|
||||||
return client.getSnapshot(snapshotId) == null;
|
return volumeOption.get().getSnapshot(snapshotId) == null;
|
||||||
}
|
}
|
||||||
}, 30 * 1000L).apply(client));
|
}, 30 * 1000L).apply(volumeOption.get()));
|
||||||
}
|
}
|
||||||
if (testVolume != null) {
|
if (testVolume != null) {
|
||||||
final String volumeId = testVolume.getId();
|
final String volumeId = testVolume.getId();
|
||||||
assertTrue(client.deleteVolume(volumeId));
|
assertTrue(volumeOption.get().deleteVolume(volumeId));
|
||||||
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(VolumeClient volumeClient) {
|
public boolean apply(VolumeClient volumeClient) {
|
||||||
return client.getVolume(volumeId) == null;
|
return volumeOption.get().getVolume(volumeId) == null;
|
||||||
}
|
}
|
||||||
}, 180 * 1000L).apply(client));
|
}, 180 * 1000L).apply(volumeOption.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateVolume() throws Exception {
|
public void testCreateVolume() {
|
||||||
testVolume = client.createVolume(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume").availabilityZone(zone));
|
if (volumeOption.isPresent()) {
|
||||||
for (int i=0; i<100 && testVolume.getStatus() == Volume.Status.CREATING; i++) {
|
testVolume = volumeOption.get().createVolume(
|
||||||
Thread.sleep(100);
|
1,
|
||||||
testVolume = client.getVolume(testVolume.getId());
|
CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume")
|
||||||
|
.availabilityZone(zone));
|
||||||
|
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(VolumeClient volumeClient) {
|
||||||
|
return volumeOption.get().getVolume(testVolume.getId()).getStatus() == Volume.Status.AVAILABLE;
|
||||||
|
}
|
||||||
|
}, 180 * 1000L).apply(volumeOption.get()));
|
||||||
}
|
}
|
||||||
assertEquals(testVolume.getStatus(), Volume.Status.AVAILABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateVolume")
|
@Test(dependsOnMethods = "testCreateVolume")
|
||||||
public void testListVolumes() throws Exception {
|
public void testListVolumes() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
Set<Volume> volumes = client.listVolumes();
|
Set<Volume> volumes = volumeOption.get().listVolumes();
|
||||||
assertNotNull(volumes);
|
assertNotNull(volumes);
|
||||||
boolean foundIt = false;
|
boolean foundIt = false;
|
||||||
for (Volume vol : volumes) {
|
for (Volume vol : volumes) {
|
||||||
Volume details = client.getVolume(vol.getId());
|
Volume details = volumeOption.get().getVolume(vol.getId());
|
||||||
assertNotNull(details);
|
assertNotNull(details);
|
||||||
if (Objects.equal(details.getId(), testVolume.getId())) {
|
if (Objects.equal(details.getId(), testVolume.getId())) {
|
||||||
foundIt = true;
|
foundIt = true;
|
||||||
@ -119,14 +123,14 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateVolume")
|
@Test(dependsOnMethods = "testCreateVolume")
|
||||||
public void testListVolumesInDetail() throws Exception {
|
public void testListVolumesInDetail() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
Set<Volume> volumes = client.listVolumesInDetail();
|
Set<Volume> volumes = volumeOption.get().listVolumesInDetail();
|
||||||
assertNotNull(volumes);
|
assertNotNull(volumes);
|
||||||
assertTrue(volumes.contains(testVolume));
|
assertTrue(volumes.contains(testVolume));
|
||||||
boolean foundIt = false;
|
boolean foundIt = false;
|
||||||
for (Volume vol : volumes) {
|
for (Volume vol : volumes) {
|
||||||
Volume details = client.getVolume(vol.getId());
|
Volume details = volumeOption.get().getVolume(vol.getId());
|
||||||
assertNotNull(details);
|
assertNotNull(details);
|
||||||
assertNotNull(details.getId());
|
assertNotNull(details.getId());
|
||||||
assertNotNull(details.getCreated());
|
assertNotNull(details.getCreated());
|
||||||
@ -146,9 +150,12 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateVolume")
|
@Test(dependsOnMethods = "testCreateVolume")
|
||||||
public void testCreateSnapshot() throws Exception {
|
public void testCreateSnapshot() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
testSnapshot = client.createSnapshot(testVolume.getId(), CreateVolumeSnapshotOptions.Builder.name("jclouds-live-test").description("jclouds live test snapshot").force());
|
testSnapshot = volumeOption.get().createSnapshot(
|
||||||
|
testVolume.getId(),
|
||||||
|
CreateVolumeSnapshotOptions.Builder.name("jclouds-live-test").description(
|
||||||
|
"jclouds live test snapshot").force());
|
||||||
assertNotNull(testSnapshot);
|
assertNotNull(testSnapshot);
|
||||||
assertNotNull(testSnapshot.getId());
|
assertNotNull(testSnapshot.getId());
|
||||||
final String snapshotId = testSnapshot.getId();
|
final String snapshotId = testSnapshot.getId();
|
||||||
@ -159,20 +166,20 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(VolumeClient volumeClient) {
|
public boolean apply(VolumeClient volumeClient) {
|
||||||
return client.getSnapshot(snapshotId).getStatus() == Volume.Status.AVAILABLE;
|
return volumeOption.get().getSnapshot(snapshotId).getStatus() == Volume.Status.AVAILABLE;
|
||||||
}
|
}
|
||||||
}, 30 * 1000L).apply(client));
|
}, 30 * 1000L).apply(volumeOption.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateSnapshot")
|
@Test(dependsOnMethods = "testCreateSnapshot")
|
||||||
public void testListSnapshots() throws Exception {
|
public void testListSnapshots() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
Set<VolumeSnapshot> snapshots = client.listSnapshots();
|
Set<VolumeSnapshot> snapshots = volumeOption.get().listSnapshots();
|
||||||
assertNotNull(snapshots);
|
assertNotNull(snapshots);
|
||||||
boolean foundIt = false;
|
boolean foundIt = false;
|
||||||
for (VolumeSnapshot snap : snapshots) {
|
for (VolumeSnapshot snap : snapshots) {
|
||||||
VolumeSnapshot details = client.getSnapshot(snap.getId());
|
VolumeSnapshot details = volumeOption.get().getSnapshot(snap.getId());
|
||||||
if (Objects.equal(snap.getVolumeId(), testVolume.getId())) {
|
if (Objects.equal(snap.getVolumeId(), testVolume.getId())) {
|
||||||
foundIt = true;
|
foundIt = true;
|
||||||
}
|
}
|
||||||
@ -185,24 +192,24 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testCreateSnapshot")
|
@Test(dependsOnMethods = "testCreateSnapshot")
|
||||||
public void testListSnapshotsInDetail() throws Exception {
|
public void testListSnapshotsInDetail() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
Set<VolumeSnapshot> snapshots = client.listSnapshotsInDetail();
|
Set<VolumeSnapshot> snapshots = volumeOption.get().listSnapshotsInDetail();
|
||||||
assertNotNull(snapshots);
|
assertNotNull(snapshots);
|
||||||
boolean foundIt = false;
|
boolean foundIt = false;
|
||||||
for (VolumeSnapshot snap : snapshots) {
|
for (VolumeSnapshot snap : snapshots) {
|
||||||
VolumeSnapshot details = client.getSnapshot(snap.getId());
|
VolumeSnapshot details = volumeOption.get().getSnapshot(snap.getId());
|
||||||
if (Objects.equal(snap.getVolumeId(), testVolume.getId())) {
|
if (Objects.equal(snap.getVolumeId(), testVolume.getId())) {
|
||||||
foundIt = true;
|
foundIt = true;
|
||||||
assertSame(details, testSnapshot);
|
assertSame(details, testSnapshot);
|
||||||
}
|
}
|
||||||
assertSame(details, snap);
|
assertSame(details, snap);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(foundIt, "Failed to find the snapshot we created in listSnapshotsInDetail() response");
|
assertTrue(foundIt, "Failed to find the snapshot we created in listSnapshotsInDetail() response");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertSame(VolumeSnapshot a, VolumeSnapshot b) {
|
private void assertSame(VolumeSnapshot a, VolumeSnapshot b) {
|
||||||
assertNotNull(a);
|
assertNotNull(a);
|
||||||
assertNotNull(b);
|
assertNotNull(b);
|
||||||
@ -212,36 +219,39 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
assertEquals(a.getVolumeId(), b.getVolumeId());
|
assertEquals(a.getVolumeId(), b.getVolumeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled=false, dependsOnMethods = "testCreateVolume") // disabled as it alters an existing server
|
@Test(dependsOnMethods = "testCreateVolume")
|
||||||
public void testAttachments() throws Exception {
|
public void testAttachments() {
|
||||||
if (client != null) {
|
if (volumeOption.isPresent()) {
|
||||||
Set<Resource> servers = novaContext.getApi().getServerClientForZone(zone).listServers();
|
String server_id = null;
|
||||||
if (!servers.isEmpty()) {
|
try {
|
||||||
final String serverId = Iterables.getFirst(servers, null).getId();
|
final String serverId = server_id = createServerInZone(zone).getId();
|
||||||
Set<VolumeAttachment> attachments = client.listAttachmentsOnServer(serverId);
|
|
||||||
|
Set<VolumeAttachment> attachments = volumeOption.get().listAttachmentsOnServer(serverId);
|
||||||
assertNotNull(attachments);
|
assertNotNull(attachments);
|
||||||
final int before = attachments.size();
|
final int before = attachments.size();
|
||||||
|
|
||||||
VolumeAttachment testAttachment = client.attachVolumeToServerAsDevice(testVolume.getId(), serverId, "/dev/vdf");
|
VolumeAttachment testAttachment = volumeOption.get().attachVolumeToServerAsDevice(testVolume.getId(),
|
||||||
|
serverId, "/dev/vdf");
|
||||||
assertNotNull(testAttachment.getId());
|
assertNotNull(testAttachment.getId());
|
||||||
assertEquals(testAttachment.getVolumeId(), testVolume.getId());
|
assertEquals(testAttachment.getVolumeId(), testVolume.getId());
|
||||||
|
|
||||||
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(VolumeClient volumeClient) {
|
public boolean apply(VolumeClient volumeClient) {
|
||||||
return client.listAttachmentsOnServer(serverId).size() == before+1;
|
return volumeOption.get().listAttachmentsOnServer(serverId).size() == before + 1;
|
||||||
}
|
}
|
||||||
}, 60 * 1000L).apply(client));
|
}, 60 * 1000L).apply(volumeOption.get()));
|
||||||
|
|
||||||
attachments = client.listAttachmentsOnServer(serverId);
|
attachments = volumeOption.get().listAttachmentsOnServer(serverId);
|
||||||
assertNotNull(attachments);
|
assertNotNull(attachments);
|
||||||
assertEquals(attachments.size(), before+1);
|
assertEquals(attachments.size(), before + 1);
|
||||||
|
|
||||||
assertEquals(client.getVolume(testVolume.getId()).getStatus(), Volume.Status.IN_USE);
|
assertEquals(volumeOption.get().getVolume(testVolume.getId()).getStatus(), Volume.Status.IN_USE);
|
||||||
|
|
||||||
boolean foundIt = false;
|
boolean foundIt = false;
|
||||||
for (VolumeAttachment att : attachments) {
|
for (VolumeAttachment att : attachments) {
|
||||||
VolumeAttachment details = client.getAttachmentForVolumeOnServer(att.getVolumeId(), serverId);
|
VolumeAttachment details = volumeOption.get()
|
||||||
|
.getAttachmentForVolumeOnServer(att.getVolumeId(), serverId);
|
||||||
assertNotNull(details);
|
assertNotNull(details);
|
||||||
assertNotNull(details.getId());
|
assertNotNull(details.getId());
|
||||||
assertNotNull(details.getServerId());
|
assertNotNull(details.getServerId());
|
||||||
@ -255,14 +265,19 @@ public class VolumeClientLiveTest extends BaseNovaClientLiveTest {
|
|||||||
|
|
||||||
assertTrue(foundIt, "Failed to find the attachment we created in listAttachments() response");
|
assertTrue(foundIt, "Failed to find the attachment we created in listAttachments() response");
|
||||||
|
|
||||||
client.detachVolumeFromServer(testVolume.getId(), serverId);
|
volumeOption.get().detachVolumeFromServer(testVolume.getId(), serverId);
|
||||||
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
assertTrue(new RetryablePredicate<VolumeClient>(new Predicate<VolumeClient>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(VolumeClient volumeClient) {
|
public boolean apply(VolumeClient volumeClient) {
|
||||||
return client.listAttachmentsOnServer(serverId).size() == before;
|
return volumeOption.get().listAttachmentsOnServer(serverId).size() == before;
|
||||||
}
|
}
|
||||||
}, 60 * 1000L).apply(client));
|
}, 60 * 1000L).apply(volumeOption.get()));
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (server_id != null)
|
||||||
|
novaContext.getApi().getServerClientForZone(zone).deleteServer(server_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,19 @@ import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
|||||||
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
||||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||||
import org.jclouds.openstack.nova.v1_1.config.NovaProperties;
|
import org.jclouds.openstack.nova.v1_1.config.NovaProperties;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.domain.Server.Status;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.features.ImageClient;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.features.ServerClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code NovaClient}
|
* Tests behavior of {@code NovaClient}
|
||||||
*
|
*
|
||||||
@ -64,5 +72,35 @@ public class BaseNovaClientLiveTest extends BaseComputeServiceContextLiveTest {
|
|||||||
if (novaContext != null)
|
if (novaContext != null)
|
||||||
novaContext.close();
|
novaContext.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Server createServerInZone(String zoneId) {
|
||||||
|
ServerClient serverClient = novaContext.getApi().getServerClientForZone(zoneId);
|
||||||
|
Server server = serverClient.createServer("test", imageIdForZone(zoneId), flavorRefForZone(zoneId));
|
||||||
|
blockUntilServerActive(server.getId(), serverClient);
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void blockUntilServerActive(String serverId, ServerClient client) {
|
||||||
|
Server currentDetails = null;
|
||||||
|
for (currentDetails = client.getServer(serverId); currentDetails.getStatus() != Status.ACTIVE; currentDetails = client
|
||||||
|
.getServer(serverId)) {
|
||||||
|
System.out.printf("blocking on status active%n%s%n", currentDetails);
|
||||||
|
try {
|
||||||
|
Thread.sleep(5 * 1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String imageIdForZone(String zoneId) {
|
||||||
|
ImageClient imageClient = novaContext.getApi().getImageClientForZone(zoneId);
|
||||||
|
return Iterables.getLast(imageClient.listImages()).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String flavorRefForZone(String zoneId) {
|
||||||
|
FlavorClient flavorClient = novaContext.getApi().getFlavorClientForZone(zoneId);
|
||||||
|
return Iterables.getLast(flavorClient.listFlavors()).getId();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.hpcloud.compute.features;
|
||||||
|
|
||||||
|
import org.jclouds.openstack.nova.v1_1.extensions.VolumeClientLiveTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", testName = "HPCloudComputeVolumeClientLiveTest")
|
||||||
|
public class HPCloudComputeVolumeClientLiveTest extends VolumeClientLiveTest {
|
||||||
|
public HPCloudComputeVolumeClientLiveTest() {
|
||||||
|
provider = "hpcloud-compute";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user