mirror of https://github.com/apache/jclouds.git
Adding remaining VolumeClientExpectTest methods
This commit is contained in:
parent
58d4de4bbe
commit
0e9153017c
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.extensions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
@ -27,14 +27,16 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Attachment;
|
||||
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.VolumeSnapshot;
|
||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest;
|
||||
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeOptions;
|
||||
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeSnapshotOptions;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
|
@ -52,38 +54,93 @@ public class VolumeClientExpectTest extends BaseNovaClientExpectTest {
|
|||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list.json")).build()
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/volume_list.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<Volume> volumes = client.listVolumes();
|
||||
assertEquals(volumes, ImmutableSet.of(testVolume()));
|
||||
}
|
||||
|
||||
public void testListVolumesFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<Volume> volumes = client.listVolumes();
|
||||
assertTrue(volumes.isEmpty());
|
||||
}
|
||||
|
||||
public void testListVolumesInDetail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes/detail");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list_detail.json")).build()
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/volume_list_detail.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<Volume> volumes = client.listVolumesInDetail();
|
||||
assertEquals(volumes, ImmutableSet.of(testVolume()));
|
||||
}
|
||||
|
||||
public void testListVolumesInDetailFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes/detail");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<Volume> volumes = client.listVolumesInDetail();
|
||||
assertTrue(volumes.isEmpty());
|
||||
}
|
||||
|
||||
public void testCreateVolume() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint)
|
||||
.method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":\"1\"}}", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/volume_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Volume volume = client.createVolume(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume"));
|
||||
assertEquals(volume, testVolume());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testCreateVolumeFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint)
|
||||
.endpoint(endpoint)
|
||||
.method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":\"1\"}}", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
standardResponseBuilder(404).payload(payloadFromResource("/volume_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
client.createVolume(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume"));
|
||||
}
|
||||
|
||||
public void testGetVolume() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_details.json")).build()
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/volume_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Volume volume = client.getVolume("1");
|
||||
|
@ -97,33 +154,305 @@ public class VolumeClientExpectTest extends BaseNovaClientExpectTest {
|
|||
assertEquals(Iterables.getOnlyElement(volume.getAttachments()), testAttachment());
|
||||
}
|
||||
|
||||
public void testGetVolumeFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertNull(client.getVolume("1"));
|
||||
}
|
||||
|
||||
public void testDeleteVolume() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("DELETE").build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/attachment_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(client.deleteVolume("1"));
|
||||
}
|
||||
|
||||
public void testDeleteVolumeFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-volumes/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("DELETE").build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(client.deleteVolume("1"));
|
||||
}
|
||||
|
||||
public void testListAttachments() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
|
||||
.endpoint(endpoint).build(),
|
||||
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build()
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/attachment_list.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<Attachment> attachments = client.listAttachments("instance-1");
|
||||
Set<VolumeAttachment> attachments = client.listAttachments("instance-1");
|
||||
assertEquals(attachments, ImmutableSet.of(testAttachment()));
|
||||
// double-check equals()
|
||||
Attachment attachment = Iterables.getOnlyElement(attachments);
|
||||
// double-check individual fields
|
||||
VolumeAttachment attachment = Iterables.getOnlyElement(attachments);
|
||||
assertEquals(attachment.getDevice(), "/dev/vdc");
|
||||
assertEquals(attachment.getServerId(), "b4785058-cb80-491b-baa3-e4ee6546450e");
|
||||
assertEquals(attachment.getId(), "1");
|
||||
assertEquals(attachment.getVolumeId(), "1");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testListAttachmentsFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-2/os-volume_attachments");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(401).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
client.listAttachments("instance-2");
|
||||
}
|
||||
|
||||
public void testGetAttachment() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/attachment_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
VolumeAttachment attachment = client.getAttachment("instance-1", "1");
|
||||
assertEquals(attachment, testAttachment());
|
||||
}
|
||||
|
||||
public void testGetAttachmentFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertNull(client.getAttachment("instance-1", "1"));
|
||||
}
|
||||
|
||||
public void testAttachVolume() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/attachment_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
VolumeAttachment result = client.attachVolume("instance-1", "1", "/dev/vdc");
|
||||
assertEquals(result, testAttachment());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||
public void testAttachVolumeFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
client.attachVolume("instance-1", "1", "/dev/vdc");
|
||||
}
|
||||
|
||||
public void testDetachVolume() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("DELETE").build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/attachment_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(client.detachVolume("instance-1", "1"));
|
||||
}
|
||||
|
||||
public void testDetachVolumeFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/servers/instance-1/os-volume_attachments/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("DELETE").build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertFalse(client.detachVolume("instance-1", "1"));
|
||||
}
|
||||
|
||||
public void testListSnapshots() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/snapshot_list.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<VolumeSnapshot> snapshots = client.listSnapshots();
|
||||
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
|
||||
}
|
||||
|
||||
public void testListSnapshotsFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<VolumeSnapshot> snapshots = client.listSnapshots();
|
||||
assertTrue(snapshots.isEmpty());
|
||||
}
|
||||
|
||||
public void testGetSnapshot() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/snapshot_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
VolumeSnapshot snapshot = client.getSnapshot("1");
|
||||
assertEquals(snapshot, testSnapshot());
|
||||
}
|
||||
|
||||
public void testGetSnapshotFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertNull(client.getSnapshot("1"));
|
||||
}
|
||||
|
||||
public void testListSnapshotsInDetail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots/detail");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/snapshot_list_detail.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<VolumeSnapshot> snapshots = client.listSnapshotsInDetail();
|
||||
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
|
||||
|
||||
// double-check individual fields
|
||||
VolumeSnapshot snappy = Iterables.getOnlyElement(snapshots);
|
||||
assertEquals(snappy.getId(), "7");
|
||||
assertEquals(snappy.getVolumeId(), "9");
|
||||
assertEquals(snappy.getStatus(), Volume.Status.AVAILABLE);
|
||||
assertEquals(snappy.getDescription(), "jclouds live test snapshot");
|
||||
assertEquals(snappy.getName(), "jclouds-live-test");
|
||||
assertEquals(snappy.getSize(), 1);
|
||||
}
|
||||
|
||||
public void testListSnapshotsInDetailFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots/detail");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).build(),
|
||||
standardResponseBuilder(404).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
Set<VolumeSnapshot> snapshots = client.listSnapshotsInDetail();
|
||||
assertTrue(snapshots.isEmpty());
|
||||
}
|
||||
|
||||
public void testCreateSnapshot() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint)
|
||||
.method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"snapshot\":{\"display_name\":\"jclouds-live-test\",\"volume_id\":\"13\",\"display_description\":\"jclouds live test snapshot\",\"force\":\"true\"}}", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/snapshot_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
VolumeSnapshot snapshot = client.createSnapshot("13", CreateVolumeSnapshotOptions.Builder.name("jclouds-live-test").description("jclouds live test snapshot").force());
|
||||
assertEquals(snapshot, testSnapshot());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testCreateSnapshotFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint)
|
||||
.method("POST")
|
||||
.payload(payloadFromStringWithContentType("{\"snapshot\":{\"display_name\":\"jclouds-live-test\",\"volume_id\":\"13\",\"display_description\":\"jclouds live test snapshot\",\"force\":\"true\"}}", MediaType.APPLICATION_JSON))
|
||||
.build(),
|
||||
standardResponseBuilder(401).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
client.createSnapshot("13", CreateVolumeSnapshotOptions.Builder.name("jclouds-live-test").description("jclouds live test snapshot").force());
|
||||
}
|
||||
|
||||
public void testDeleteSnapshot() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("DELETE").build(),
|
||||
standardResponseBuilder(200).payload(payloadFromResource("/snapshot_details.json")).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
assertTrue(client.deleteSnapshot("1"));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = AuthorizationException.class)
|
||||
public void testDeleteSnapshotFail() {
|
||||
URI endpoint = URI.create("https://compute.north.host/v1.1/3456/os-snapshots/1");
|
||||
VolumeClient client = requestsSendResponses(
|
||||
keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
|
||||
standardRequestBuilder(endpoint).method("DELETE").build(),
|
||||
standardResponseBuilder(401).build()
|
||||
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
|
||||
|
||||
client.deleteSnapshot("1");
|
||||
}
|
||||
|
||||
protected Volume testVolume() {
|
||||
return Volume.builder().status(Volume.Status.IN_USE).description("This is a test volume").zone("nova").name("test")
|
||||
.attachments(ImmutableSet.of(testAttachment())).size(1).id("1").created(dateService.iso8601SecondsDateParse("2012-04-23 12:16:45")).build();
|
||||
}
|
||||
|
||||
protected Attachment testAttachment() {
|
||||
return Attachment.builder().device("/dev/vdc").serverId("b4785058-cb80-491b-baa3-e4ee6546450e").id("1").volumeId("1").build();
|
||||
protected VolumeAttachment testAttachment() {
|
||||
return VolumeAttachment.builder().device("/dev/vdc").serverId("b4785058-cb80-491b-baa3-e4ee6546450e").id("1").volumeId("1").build();
|
||||
}
|
||||
|
||||
protected VolumeSnapshot testSnapshot() {
|
||||
return VolumeSnapshot.builder().id("7").volumeId("9").description("jclouds live test snapshot").status(Volume.Status.AVAILABLE)
|
||||
.name("jclouds-live-test").size(1).created(dateService.iso8601SecondsDateParse("2012-04-24 13:34:42")).build();
|
||||
}
|
||||
}
|
|
@ -20,6 +20,8 @@ package org.jclouds.openstack.nova.v1_1.internal;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.keystone.v2_0.internal.KeystoneFixture;
|
||||
|
@ -68,4 +70,14 @@ public class BaseNovaExpectTest<T> extends BaseRestClientExpectTest<T> {
|
|||
unmatchedExtensionsOfNovaResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/extension_list.json")).build();
|
||||
}
|
||||
|
||||
protected HttpRequest.Builder standardRequestBuilder(URI endpoint) {
|
||||
return HttpRequest.builder().method("GET")
|
||||
.headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken))
|
||||
.endpoint(endpoint);
|
||||
}
|
||||
|
||||
protected HttpResponse.Builder standardResponseBuilder(int status) {
|
||||
return HttpResponse.builder().statusCode(status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"volumeAttachment": {"device": "/dev/vdc", "serverId": "b4785058-cb80-491b-baa3-e4ee6546450e", "id": 1, "volumeId": 1}}
|
|
@ -0,0 +1 @@
|
|||
{"snapshot": {"status": "available", "displayDescription": "jclouds live test snapshot", "displayName": "jclouds-live-test", "volumeId": 9, "id": 7, "createdAt": "2012-04-24 13:34:42", "size": 1}}
|
|
@ -0,0 +1 @@
|
|||
{"snapshots": [{"status": "available", "displayDescription": "jclouds live test snapshot", "displayName": "jclouds-live-test", "volumeId": 9, "id": 7, "createdAt": "2012-04-24 13:34:42", "size": 1}]}
|
|
@ -0,0 +1 @@
|
|||
{"snapshots": [{"status": "available", "displayDescription": "jclouds live test snapshot", "displayName": "jclouds-live-test", "volumeId": 9, "id": 7, "createdAt": "2012-04-24 13:34:42", "size": 1}]}
|
Loading…
Reference in New Issue