You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/03/31 09:13:50 UTC
[37/52] [partial] Moving jclouds dependencies to accurate parent
directories
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java
new file mode 100644
index 0000000..ab9be8d
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiExpectTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.VirtualInterface;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests parsing and guice wiring of VirtualInterfaceApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "VirtualInterfaceApiLiveTest")
+public class VirtualInterfaceApiExpectTest extends BaseNovaApiExpectTest {
+
+ public void testListVirtualInterfaces() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/os-virtual-interfaces");
+ VirtualInterfaceApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/virtual_interfaces_list.json")).build()
+ ).getVirtualInterfaceExtensionForZone("az-1.region-a.geo-1").get();
+
+ VirtualInterface vif = Iterables.getOnlyElement(api.listOnServer("1"));
+ assertEquals(vif.getId(), "02315827-b05c-4668-9c05-75c68838074a");
+ assertEquals(vif.getMacAddress(), "fa:16:3e:09:71:34");
+ }
+
+ public void testListVirtualInterfacesFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/os-virtual-interfaces");
+ VirtualInterfaceApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVirtualInterfaceExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.listOnServer("1").isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java
new file mode 100644
index 0000000..4f36035
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VirtualInterfaceApiLiveTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.jclouds.openstack.nova.v2_0.domain.VirtualInterface;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of VirtualInterfaceApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "VirtualInterfaceApiLiveTest", singleThreaded = true)
+public class VirtualInterfaceApiLiveTest extends BaseNovaApiLiveTest {
+ private Optional<? extends VirtualInterfaceApi> apiOption;
+ private String zone;
+
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ apiOption = api.getVirtualInterfaceExtensionForZone(zone);
+ }
+
+ public void testListVirtualInterfaces() {
+ if (apiOption.isPresent()) {
+ Server testServer = null;
+ try {
+ testServer = createServerInZone(zone);
+ Set<? extends VirtualInterface> results = apiOption.get().listOnServer(testServer.getId()).toSet();
+ for (VirtualInterface vif : results) {
+ assertNotNull(vif.getId());
+ assertNotNull(vif.getMacAddress());
+ }
+ } finally {
+ if (testServer != null) {
+ api.getServerApiForZone(zone).delete(testServer.getId());
+ }
+ }
+ }
+}
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java
new file mode 100644
index 0000000..c177ce2
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiExpectTest.java
@@ -0,0 +1,460 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.Volume;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeAttachment;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeSnapshot;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeOptions;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeSnapshotOptions;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests VolumeApi guice wiring and parsing
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "VolumeApiExpectTest")
+public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
+ private DateService dateService = new SimpleDateFormatDateService();
+
+ public void testListVolumes() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends Volume> volumes = api.list().toSet();
+ assertEquals(volumes, ImmutableSet.of(testVolume()));
+ }
+
+ public void testListVolumesFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends Volume> volumes = api.list().toSet();
+ assertTrue(volumes.isEmpty());
+ }
+
+ public void testListVolumesInDetail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes/detail");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list_detail.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends Volume> volumes = api.listInDetail().toSet();
+ assertEquals(volumes, ImmutableSet.of(testVolume()));
+ }
+
+ public void testListVolumesInDetailFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes/detail");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends Volume> volumes = api.listInDetail().toSet();
+ assertTrue(volumes.isEmpty());
+ }
+
+ public void testCreateVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint)
+ .method("POST")
+ .payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":1}}", MediaType.APPLICATION_JSON))
+ .build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Volume volume = api.create(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://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(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(),
+ HttpResponse.builder().statusCode(404).payload(payloadFromResource("/volume_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.create(1, CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume"));
+ }
+
+ public void testGetVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Volume volume = api.get("1");
+ assertEquals(volume, testVolume());
+ // double-check equals()
+ assertEquals(volume.getStatus(), Volume.Status.IN_USE);
+ assertEquals(volume.getDescription(), "This is a test volume");
+ assertEquals(volume.getZone(), "nova");
+ assertEquals(volume.getName(), "test");
+ assertEquals(volume.getStatus(), Volume.Status.IN_USE);
+ assertEquals(Iterables.getOnlyElement(volume.getAttachments()), testAttachment());
+ }
+
+ public void testGetVolumeFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.get("1"));
+ }
+
+ public void testDeleteVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.delete("1"));
+ }
+
+ public void testDeleteVolumeFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.delete("1"));
+ }
+
+ public void testListAttachments() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeAttachment> attachments = api.listAttachmentsOnServer("instance-1").toSet();
+ assertEquals(attachments, ImmutableSet.of(testAttachment()));
+ // 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://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-2/os-volume_attachments");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(401).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.listAttachmentsOnServer("instance-2");
+ }
+
+ public void testGetAttachment() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeAttachment attachment = api.getAttachmentForVolumeOnServer("1", "instance-1");
+ assertEquals(attachment, testAttachment());
+ }
+
+ public void testGetAttachmentFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.getAttachmentForVolumeOnServer("1", "instance-1"));
+ }
+
+ public void testAttachVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeAttachment result = api.attachVolumeToServerAsDevice("1", "instance-1", "/dev/vdc");
+ assertEquals(result, testAttachment());
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class)
+ public void testAttachVolumeFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.attachVolumeToServerAsDevice("1", "instance-1","/dev/vdc");
+ }
+
+ public void testDetachVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.detachVolumeFromServer("1", "instance-1"));
+ }
+
+ public void testDetachVolumeFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.detachVolumeFromServer("1", "instance-1"));
+ }
+
+ public void testListSnapshots() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeSnapshot> snapshots = api.listSnapshots().toSet();
+ assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
+ }
+
+ public void testListSnapshotsFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeSnapshot> snapshots = api.listSnapshots().toSet();
+ assertTrue(snapshots.isEmpty());
+ }
+
+ public void testGetSnapshot() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeSnapshot snapshot = api.getSnapshot("1");
+ assertEquals(snapshot, testSnapshot());
+ }
+
+ public void testGetSnapshotFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.getSnapshot("1"));
+ }
+
+ public void testListSnapshotsInDetail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots/detail");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list_detail.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeSnapshot> snapshots = api.listSnapshotsInDetail().toSet();
+ 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://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots/detail");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeSnapshot> snapshots = api.listSnapshotsInDetail().toSet();
+ assertTrue(snapshots.isEmpty());
+ }
+
+ public void testCreateSnapshot() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(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(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeSnapshot snapshot = api.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://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(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(),
+ HttpResponse.builder().statusCode(401).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.createSnapshot("13", CreateVolumeSnapshotOptions.Builder.name("jclouds-live-test").description("jclouds live test snapshot").force());
+ }
+
+ public void testDeleteSnapshot() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_details.json")).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.deleteSnapshot("1"));
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testDeleteSnapshotFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots/1");
+ VolumeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(401).build()
+ ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.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 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();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java
new file mode 100644
index 0000000..a7f14ad
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeApiLiveTest.java
@@ -0,0 +1,274 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.jclouds.util.Predicates2.retry;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.Volume;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeAttachment;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeSnapshot;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeOptions;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeSnapshotOptions;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of VolumeApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "VolumeApiLiveTest", singleThreaded = true)
+public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
+
+ private Optional<? extends VolumeApi> volumeOption;
+ private String zone;
+
+ private Volume testVolume;
+ private VolumeSnapshot testSnapshot;
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ volumeOption = api.getVolumeExtensionForZone(zone);
+ }
+
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDown() {
+ if (volumeOption.isPresent()) {
+ if (testSnapshot != null) {
+ final String snapshotId = testSnapshot.getId();
+ assertTrue(volumeOption.get().deleteSnapshot(snapshotId));
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeOption.get().getSnapshot(snapshotId) == null;
+ }
+ }, 30 * 1000L).apply(volumeOption.get()));
+ }
+ if (testVolume != null) {
+ final String volumeId = testVolume.getId();
+ assertTrue(volumeOption.get().delete(volumeId));
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeOption.get().get(volumeId) == null;
+ }
+ }, 180 * 1000L).apply(volumeOption.get()));
+ }
+ }
+ super.tearDown();
+ }
+
+ public void testCreateVolume() {
+ if (volumeOption.isPresent()) {
+ testVolume = volumeOption.get().create(
+ 1,
+ CreateVolumeOptions.Builder.name("jclouds-test-volume").description("description of test volume")
+ .availabilityZone(zone));
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeOption.get().get(testVolume.getId()).getStatus() == Volume.Status.AVAILABLE;
+ }
+ }, 180 * 1000L).apply(volumeOption.get()));
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolume")
+ public void testListVolumes() {
+ if (volumeOption.isPresent()) {
+ Set<? extends Volume> volumes = volumeOption.get().list().toSet();
+ assertNotNull(volumes);
+ boolean foundIt = false;
+ for (Volume vol : volumes) {
+ Volume details = volumeOption.get().get(vol.getId());
+ assertNotNull(details);
+ if (Objects.equal(details.getId(), testVolume.getId())) {
+ foundIt = true;
+ }
+ }
+ assertTrue(foundIt, "Failed to find the volume we created in list() response");
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolume")
+ public void testListVolumesInDetail() {
+ if (volumeOption.isPresent()) {
+ Set<? extends Volume> volumes = volumeOption.get().listInDetail().toSet();
+ assertNotNull(volumes);
+ boolean foundIt = false;
+ for (Volume vol : volumes) {
+ Volume details = volumeOption.get().get(vol.getId());
+ assertNotNull(details);
+ assertNotNull(details.getId());
+ assertNotNull(details.getCreated());
+ assertTrue(details.getSize() > -1);
+
+ assertEquals(details.getId(), vol.getId());
+ assertEquals(details.getSize(), vol.getSize());
+ assertEquals(details.getName(), vol.getName());
+ assertEquals(details.getDescription(), vol.getDescription());
+ assertEquals(details.getCreated(), vol.getCreated());
+ if (Objects.equal(details.getId(), testVolume.getId())) {
+ foundIt = true;
+ }
+ }
+ assertTrue(foundIt, "Failed to find the volume we previously created in listInDetail() response");
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolume")
+ public void testCreateSnapshot() {
+ if (volumeOption.isPresent()) {
+ testSnapshot = volumeOption.get().createSnapshot(
+ testVolume.getId(),
+ CreateVolumeSnapshotOptions.Builder.name("jclouds-live-test").description(
+ "jclouds live test snapshot").force());
+ assertNotNull(testSnapshot);
+ assertNotNull(testSnapshot.getId());
+ final String snapshotId = testSnapshot.getId();
+ assertNotNull(testSnapshot.getStatus());
+ assertTrue(testSnapshot.getSize() > -1);
+ assertNotNull(testSnapshot.getCreated());
+
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeOption.get().getSnapshot(snapshotId).getStatus() == Volume.Status.AVAILABLE;
+ }
+ }, 30 * 1000L).apply(volumeOption.get()));
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateSnapshot")
+ public void testListSnapshots() {
+ if (volumeOption.isPresent()) {
+ Set<? extends VolumeSnapshot> snapshots = volumeOption.get().listSnapshots().toSet();
+ assertNotNull(snapshots);
+ boolean foundIt = false;
+ for (VolumeSnapshot snap : snapshots) {
+ VolumeSnapshot details = volumeOption.get().getSnapshot(snap.getId());
+ if (Objects.equal(snap.getVolumeId(), testVolume.getId())) {
+ foundIt = true;
+ }
+ assertNotNull(details);
+ assertEquals(details.getId(), snap.getId());
+ assertEquals(details.getVolumeId(), snap.getVolumeId());
+ }
+ assertTrue(foundIt, "Failed to find the snapshot we previously created in listSnapshots() response");
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateSnapshot")
+ public void testListSnapshotsInDetail() {
+ if (volumeOption.isPresent()) {
+ Set<? extends VolumeSnapshot> snapshots = volumeOption.get().listSnapshotsInDetail().toSet();
+ assertNotNull(snapshots);
+ boolean foundIt = false;
+ for (VolumeSnapshot snap : snapshots) {
+ VolumeSnapshot details = volumeOption.get().getSnapshot(snap.getId());
+ if (Objects.equal(snap.getVolumeId(), testVolume.getId())) {
+ foundIt = true;
+ assertSame(details, testSnapshot);
+ }
+ assertSame(details, snap);
+ }
+
+ assertTrue(foundIt, "Failed to find the snapshot we created in listSnapshotsInDetail() response");
+ }
+ }
+
+ private void assertSame(VolumeSnapshot a, VolumeSnapshot b) {
+ assertNotNull(a);
+ assertNotNull(b);
+ assertEquals(a.getId(), b.getId());
+ assertEquals(a.getDescription(), b.getDescription());
+ assertEquals(a.getName(), b.getName());
+ assertEquals(a.getVolumeId(), b.getVolumeId());
+ }
+
+ @Test(dependsOnMethods = "testCreateVolume")
+ public void testAttachments() {
+ if (volumeOption.isPresent()) {
+ String server_id = null;
+ try {
+ final String serverId = server_id = createServerInZone(zone).getId();
+
+ Set<? extends VolumeAttachment> attachments = volumeOption.get().listAttachmentsOnServer(serverId).toSet();
+ assertNotNull(attachments);
+ final int before = attachments.size();
+
+ VolumeAttachment testAttachment = volumeOption.get().attachVolumeToServerAsDevice(testVolume.getId(),
+ serverId, "/dev/vdf");
+ assertNotNull(testAttachment.getId());
+ assertEquals(testAttachment.getVolumeId(), testVolume.getId());
+
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeOption.get().listAttachmentsOnServer(serverId).size() > before;
+ }
+ }, 60 * 1000L).apply(volumeOption.get()));
+
+ attachments = volumeOption.get().listAttachmentsOnServer(serverId).toSet();
+ assertNotNull(attachments);
+ assertEquals(attachments.size(), before + 1);
+
+ assertEquals(volumeOption.get().get(testVolume.getId()).getStatus(), Volume.Status.IN_USE);
+
+ boolean foundIt = false;
+ for (VolumeAttachment att : attachments) {
+ VolumeAttachment details = volumeOption.get()
+ .getAttachmentForVolumeOnServer(att.getVolumeId(), serverId);
+ assertNotNull(details);
+ assertNotNull(details.getId());
+ assertNotNull(details.getServerId());
+ assertNotNull(details.getVolumeId());
+ if (Objects.equal(details.getVolumeId(), testVolume.getId())) {
+ foundIt = true;
+ assertEquals(details.getDevice(), "/dev/vdf");
+ assertEquals(details.getServerId(), serverId);
+ }
+ }
+
+ assertTrue(foundIt, "Failed to find the attachment we created in listAttachments() response");
+
+ volumeOption.get().detachVolumeFromServer(testVolume.getId(), serverId);
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeOption.get().listAttachmentsOnServer(serverId).size() == before;
+ }
+ }, 60 * 1000L).apply(volumeOption.get()));
+
+ } finally {
+ if (server_id != null)
+ api.getServerApiForZone(zone).delete(server_id);
+ }
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiExpectTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiExpectTest.java
new file mode 100644
index 0000000..1b4857d
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiExpectTest.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.Volume;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeAttachment;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests VolumeAttachmentApi Guice wiring and parsing
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "VolumeAttachmentApiExpectTest")
+public class VolumeAttachmentApiExpectTest extends BaseNovaApiExpectTest {
+ private DateService dateService = new SimpleDateFormatDateService();
+
+ public void testListAttachments() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeAttachment> attachments = api.listAttachmentsOnServer("instance-1").toSet();
+ assertEquals(attachments, ImmutableSet.of(testAttachment()));
+ // 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://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-2/os-volume_attachments");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(401).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.listAttachmentsOnServer("instance-2");
+ }
+
+ public void testGetAttachment() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeAttachment attachment = api.getAttachmentForVolumeOnServer("1", "instance-1");
+ assertEquals(attachment, testAttachment());
+ }
+
+ public void testGetAttachmentFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.getAttachmentForVolumeOnServer("1", "instance-1"));
+ }
+
+ public void testAttachVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeAttachment result = api.attachVolumeToServerAsDevice("1", "instance-1", "/dev/vdc");
+ assertEquals(result, testAttachment());
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class)
+ public void testAttachVolumeFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volumeAttachment\":{\"volumeId\":\"1\",\"device\":\"/dev/vdc\"}}", MediaType.APPLICATION_JSON)).endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.attachVolumeToServerAsDevice("1", "instance-1","/dev/vdc");
+ }
+
+ public void testDetachVolume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_details.json")).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.detachVolumeFromServer("1", "instance-1"));
+ }
+
+ public void testDetachVolumeFail() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/instance-1/os-volume_attachments/1");
+ VolumeAttachmentApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeAttachmentExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.detachVolumeFromServer("1", "instance-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 VolumeAttachment testAttachment() {
+ return VolumeAttachment.builder().device("/dev/vdc").serverId("b4785058-cb80-491b-baa3-e4ee6546450e").id("1").volumeId("1").build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiLiveTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiLiveTest.java
new file mode 100644
index 0000000..cc853d8
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeAttachmentApiLiveTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.jclouds.util.Predicates2.retry;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.Volume;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeAttachment;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeOptions;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of Volume Attachment API
+ *
+ * @author Everett Toews
+ */
+@Test(groups = "live", testName = "VolumeAttachmentApiLiveTest", singleThreaded = true)
+public class VolumeAttachmentApiLiveTest extends BaseNovaApiLiveTest {
+
+ private Optional<? extends VolumeApi> volumeApi;
+ private Optional<? extends VolumeAttachmentApi> volumeAttachmentApi;
+
+ private String zone;
+ private Volume testVolume;
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ volumeApi = api.getVolumeExtensionForZone(zone);
+ volumeAttachmentApi = api.getVolumeAttachmentExtensionForZone(zone);
+ }
+
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDown() {
+ if (volumeApi.isPresent()) {
+ if (testVolume != null) {
+ final String volumeId = testVolume.getId();
+ assertTrue(volumeApi.get().delete(volumeId));
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeApi.get(volumeId) == null;
+ }
+ }, 180 * 1000L).apply(volumeApi.get()));
+ }
+ }
+
+ super.tearDown();
+ }
+
+ public void testCreateVolume() {
+ if (volumeApi.isPresent()) {
+ CreateVolumeOptions options = CreateVolumeOptions.Builder
+ .name("jclouds-test-volume")
+ .description("description of test volume")
+ .availabilityZone(zone);
+
+ testVolume = volumeApi.get().create(1, options);
+ assertTrue(retry(new Predicate<VolumeApi>() {
+ public boolean apply(VolumeApi volumeApi) {
+ return volumeApi.get(testVolume.getId()).getStatus() == Volume.Status.AVAILABLE;
+ }
+ }, 180 * 1000L).apply(volumeApi.get()));
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolume")
+ public void testAttachments() {
+ if (volumeApi.isPresent()) {
+ String server_id = null;
+ try {
+ final String serverId = server_id = createServerInZone(zone).getId();
+
+ Set<? extends VolumeAttachment> attachments =
+ volumeAttachmentApi.get().listAttachmentsOnServer(serverId).toSet();
+ assertNotNull(attachments);
+ final int before = attachments.size();
+
+ VolumeAttachment testAttachment = volumeAttachmentApi.get().attachVolumeToServerAsDevice(
+ testVolume.getId(), serverId, "/dev/vdf");
+ assertNotNull(testAttachment.getId());
+ assertEquals(testAttachment.getVolumeId(), testVolume.getId());
+
+ assertTrue(retry(new Predicate<VolumeAttachmentApi>() {
+ public boolean apply(VolumeAttachmentApi volumeAttachmentApi) {
+ return volumeAttachmentApi.listAttachmentsOnServer(serverId).size() > before;
+ }
+ }, 60 * 1000L).apply(volumeAttachmentApi.get()));
+
+ attachments = volumeAttachmentApi.get().listAttachmentsOnServer(serverId).toSet();
+ assertNotNull(attachments);
+ assertEquals(attachments.size(), before + 1);
+
+ assertEquals(volumeApi.get().get(testVolume.getId()).getStatus(), Volume.Status.IN_USE);
+
+ boolean foundIt = false;
+ for (VolumeAttachment att : attachments) {
+ VolumeAttachment details = volumeAttachmentApi.get()
+ .getAttachmentForVolumeOnServer(att.getVolumeId(), serverId);
+ assertNotNull(details);
+ assertNotNull(details.getId());
+ assertNotNull(details.getServerId());
+ assertNotNull(details.getVolumeId());
+ if (Objects.equal(details.getVolumeId(), testVolume.getId())) {
+ foundIt = true;
+ assertEquals(details.getDevice(), "/dev/vdf");
+ assertEquals(details.getServerId(), serverId);
+ }
+ }
+
+ assertTrue(foundIt, "Failed to find the attachment we created in listAttachments() response");
+
+ volumeAttachmentApi.get().detachVolumeFromServer(testVolume.getId(), serverId);
+ assertTrue(retry(new Predicate<VolumeAttachmentApi>() {
+ public boolean apply(VolumeAttachmentApi volumeAttachmentApi) {
+ return volumeAttachmentApi.listAttachmentsOnServer(serverId).size() == before;
+ }
+ }, 60 * 1000L).apply(volumeAttachmentApi.get()));
+
+ } finally {
+ if (server_id != null)
+ api.getServerApiForZone(zone).delete(server_id);
+ }
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java
new file mode 100644
index 0000000..36d8d0f
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiExpectTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.VolumeType;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeTypeOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests guice wiring and parsing of VolumeTypeApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "VolumeTypeApiExpectTest")
+public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest {
+ private DateService dateService = new SimpleDateFormatDateService();
+
+ public void testListVolumeTypes() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_list.json")).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<? extends VolumeType> types = api.list().toSet();
+ assertEquals(types, ImmutableSet.of(testVolumeType()));
+ }
+
+ public void testGetVolumeType() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/8");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeType type = api.get("8");
+ assertEquals(type, testVolumeType());
+ }
+
+ public void testGetVolumeTypeFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/8");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.get("8"));
+ }
+
+ public void testCreateVolumeType() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volume_type\":{\"name\":\"jclouds-test-1\"}}", MediaType.APPLICATION_JSON))
+ .build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeType type = api.create("jclouds-test-1");
+ assertEquals(type, testVolumeType());
+ }
+
+ public void testCreateVolumeTypeWithOptsNONE() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volume_type\":{\"name\":\"jclouds-test-1\",\"extra_specs\":{}}}", MediaType.APPLICATION_JSON))
+ .build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeType type = api.create("jclouds-test-1", CreateVolumeTypeOptions.NONE);
+ assertEquals(type, testVolumeType());
+ }
+
+ public void testCreateVolumeTypeWithOptsSet() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"volume_type\":{\"name\":\"jclouds-test-1\",\"extra_specs\":{\"x\": \"y\"}}}", MediaType.APPLICATION_JSON))
+ .build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type.json")).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ VolumeType type = api.create("jclouds-test-1", CreateVolumeTypeOptions.Builder.specs(ImmutableMap.of("x", "y")));
+ assertEquals(type, testVolumeType());
+ }
+
+ public void testDeleteVolumeType() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/8");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.delete("8"));
+ }
+
+ public void testDeleteVolumeTypeFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/8");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.delete("8"));
+ }
+
+ public void testGetAllExtraSpecs() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/9/extra_specs");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_extra_specs.json")).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.getExtraSpecs("9"), ImmutableMap.of("test", "value1"));
+ }
+
+ public void testGetAllExtraSpecsFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/9/extra_specs");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.getExtraSpecs("9").isEmpty());
+ }
+
+ public void testSetAllExtraSpecs() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/9/extra_specs");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint)
+ .method("POST")
+ .payload(payloadFromStringWithContentType("{\"extra_specs\":{\"test1\":\"somevalue\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.updateExtraSpecs("9", ImmutableMap.of("test1", "somevalue")));
+ }
+
+ public void testSetExtraSpec() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/5/extra_specs/test1");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint)
+ .method("PUT")
+ .payload(payloadFromStringWithContentType("{\"test1\":\"somevalue\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.updateExtraSpec("5", "test1", "somevalue"));
+ }
+
+ public void testGetExtraSpec() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/5/extra_specs/test1");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"test1\":\"another value\"}", MediaType.APPLICATION_JSON)).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.getExtraSpec("5", "test1"), "another value");
+ }
+
+ public void testGetExtraSpecFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/5/extra_specs/test1");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.getExtraSpec("5", "test1"));
+ }
+
+ public void testDeleteExtraSpec() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/5/extra_specs/test1");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.deleteExtraSpec("5", "test1"));
+ }
+
+ public void testDeleteExtraSpecFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volume-types/5/extra_specs/test1");
+ VolumeTypeApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.deleteExtraSpec("5", "test1"));
+ }
+
+ public VolumeType testVolumeType() {
+ return VolumeType.builder().id("8").name("jclouds-test-1").created(dateService.iso8601SecondsDateParse("2012-05-10 12:33:06")).extraSpecs(ImmutableMap.of("test", "value1", "test1", "wibble")).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java
new file mode 100644
index 0000000..02b0f50
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/VolumeTypeApiLiveTest.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.openstack.nova.v2_0.extensions;
+
+import static org.jclouds.util.Predicates2.retry;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.VolumeType;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateVolumeTypeOptions;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of VolumeTypeApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "VolumeTypeApiLiveTest", singleThreaded = true)
+public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest {
+
+ private Optional<? extends VolumeTypeApi> volumeTypeOption;
+ private String zone;
+
+ private VolumeType testVolumeType;
+
+ @BeforeGroups(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ volumeTypeOption = api.getVolumeTypeExtensionForZone(zone);
+ }
+
+
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDown() {
+ if (volumeTypeOption.isPresent()) {
+ if (testVolumeType != null) {
+ final String id = testVolumeType.getId();
+ assertTrue(volumeTypeOption.get().delete(id));
+ assertTrue(retry(new Predicate<VolumeTypeApi>() {
+ public boolean apply(VolumeTypeApi volumeApi) {
+ return volumeApi.get(id) == null;
+ }
+ }, 5 * 1000L).apply(volumeTypeOption.get()));
+ }
+ }
+ super.tearDown();
+ }
+
+ public void testCreateVolumeType() {
+ if (volumeTypeOption.isPresent()) {
+ testVolumeType = volumeTypeOption.get().create(
+ "jclouds-test-1", CreateVolumeTypeOptions.Builder.specs(ImmutableMap.of("test", "value1")));
+ assertTrue(retry(new Predicate<VolumeTypeApi>() {
+ public boolean apply(VolumeTypeApi volumeTypeApi) {
+ return volumeTypeApi.get(testVolumeType.getId()) != null;
+ }
+ }, 180 * 1000L).apply(volumeTypeOption.get()));
+
+ assertEquals(volumeTypeOption.get().get(testVolumeType.getId()).getName(), "jclouds-test-1");
+ assertEquals(volumeTypeOption.get().get(testVolumeType.getId()).getExtraSpecs(), ImmutableMap.of("test", "value1"));
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolumeType")
+ public void testListVolumeTypes() {
+ if (volumeTypeOption.isPresent()) {
+ Set<? extends VolumeType> volumeTypes = volumeTypeOption.get().list().toSet();
+ assertNotNull(volumeTypes);
+ boolean foundIt = false;
+ for (VolumeType vt : volumeTypes) {
+ VolumeType details = volumeTypeOption.get().get(vt.getId());
+ assertNotNull(details);
+ if (Objects.equal(details.getId(), testVolumeType.getId())) {
+ foundIt = true;
+ }
+ }
+ assertTrue(foundIt, "Failed to find the volume type we created in list() response");
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolumeType")
+ public void testExtraSpecs() {
+ if (volumeTypeOption.isPresent()) {
+ assertEquals(volumeTypeOption.get().getExtraSpecs(testVolumeType.getId()), ImmutableMap.of("test", "value1"));
+ assertEquals(volumeTypeOption.get().getExtraSpec(testVolumeType.getId(), "test"), "value1");
+ assertTrue(volumeTypeOption.get().updateExtraSpecs(testVolumeType.getId(), ImmutableMap.of("test1", "wibble")));
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateVolumeType")
+ public void testUpdateIndividualSpec() {
+ if (volumeTypeOption.isPresent()) {
+ assertTrue(volumeTypeOption.get().updateExtraSpec(testVolumeType.getId(), "test1", "freddy"));
+ assertEquals(volumeTypeOption.get().getExtraSpec(testVolumeType.getId(), "test1"), "freddy");
+ }
+ }
+}