From 7c31f51ab7e995b305e49347decdace4ada83ad0 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 17 Apr 2012 12:52:24 +0100 Subject: [PATCH] Adjusting openstack-nova-ec2 to handle extended volume status fields (by discarding the extra information) --- .../ec2/config/NovaEC2RestClientModule.java | 8 +++ .../xml/NovaCreateVolumeResponseHandler.java | 48 +++++++++++++ .../BaseNovaEC2RestClientExpectTest.java | 54 +++++++++++++++ .../NovaEC2ElasticBlockStoreClientTest.java | 68 +++++++++++++++++++ .../resources/nova_ec2_availabilityZones.xml | 10 +++ .../resources/nova_ec2_describe_volumes.xml | 17 +++++ 6 files changed, 205 insertions(+) create mode 100644 apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/xml/NovaCreateVolumeResponseHandler.java create mode 100644 apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/internal/BaseNovaEC2RestClientExpectTest.java create mode 100644 apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/services/NovaEC2ElasticBlockStoreClientTest.java create mode 100644 apis/openstack-nova-ec2/src/test/resources/nova_ec2_availabilityZones.xml create mode 100644 apis/openstack-nova-ec2/src/test/resources/nova_ec2_describe_volumes.xml diff --git a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java index f2ff664f35..e9de33d678 100644 --- a/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java +++ b/apis/openstack-nova-ec2/src/main/java/org/jclouds/openstack/nova/ec2/config/NovaEC2RestClientModule.java @@ -22,10 +22,12 @@ import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.config.EC2RestClientModule; import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion; +import org.jclouds.ec2.xml.CreateVolumeResponseHandler; import org.jclouds.location.config.LocationModule; import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier; import org.jclouds.location.suppliers.ZoneIdsSupplier; import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues; +import org.jclouds.openstack.nova.ec2.xml.NovaCreateVolumeResponseHandler; import org.jclouds.rest.ConfiguresRestClient; import com.google.inject.Scopes; @@ -41,6 +43,12 @@ public class NovaEC2RestClientModule extends EC2RestClientModule { + protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z"; + protected DateService dateService = new SimpleDateFormatDateService(); + protected URI endpoint = URI.create("http://localhost:8773/services/Cloud/"); + + protected HttpRequest describeAvailabilityZonesRequest = HttpRequest.builder().method("POST") + .endpoint(endpoint) + .headers(ImmutableMultimap.of("Host", "localhost:8773")) + .payload(payloadFromStringWithContentType("Action=DescribeAvailabilityZones&Signature=S3fa5fybw4KAq4o11IpKHlqwx3cVJdKfeAKw3FIJYvM%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", MediaType.APPLICATION_FORM_URLENCODED)) + .build(); + protected HttpResponse describeAvailabilityZonesResponse = HttpResponse.builder() + .statusCode(200).payload(payloadFromResourceWithContentType("/nova_ec2_availabilityZones.xml", MediaType.APPLICATION_XML)).build(); + + + public BaseNovaEC2RestClientExpectTest() { + provider = "openstack-nova-ec2"; + } + + @ConfiguresRestClient + private static final class TestNovaEC2RestClientModule extends NovaEC2RestClientModule { + @Override + @Provides + protected String provideTimeStamp(final DateService dateService, + @Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) { + return CONSTANT_DATE; + } + } + + @Override + protected Module createModule() { + return new TestNovaEC2RestClientModule(); + } +} diff --git a/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/services/NovaEC2ElasticBlockStoreClientTest.java b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/services/NovaEC2ElasticBlockStoreClientTest.java new file mode 100644 index 0000000000..021ee90a2f --- /dev/null +++ b/apis/openstack-nova-ec2/src/test/java/org/jclouds/openstack/nova/ec2/services/NovaEC2ElasticBlockStoreClientTest.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.openstack.nova.ec2.services; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.ec2.domain.Attachment; +import org.jclouds.ec2.domain.Volume; +import org.jclouds.ec2.services.ElasticBlockStoreClient; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.ec2.internal.BaseNovaEC2RestClientExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "NovaEC2ElasticBlockStoreClientTest") +public class NovaEC2ElasticBlockStoreClientTest extends BaseNovaEC2RestClientExpectTest { + + public void testDescribeVolumesWithNovaEC2Status() { + ElasticBlockStoreClient client = requestsSendResponses( + describeAvailabilityZonesRequest, + describeAvailabilityZonesResponse, + HttpRequest.builder().method("POST") + .endpoint(URI.create("http://localhost:8773/services/Cloud/")) + .headers(ImmutableMultimap.of("Host", "localhost:8773")) + .payload(payloadFromStringWithContentType("Action=DescribeVolumes&Signature=AvRznSzGExM%2Buaj2JJj66wq4v4f%2BakicyLooRDtC0t0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(), + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_describe_volumes.xml")).build() + ).getElasticBlockStoreServices(); + + Set expected = ImmutableSet.of(Volume + .builder() + .status(Volume.Status.AVAILABLE) + .availabilityZone("nova") + .region("nova") + .id("vol-00000007") + .size(1) + .attachments(Attachment.builder().region("nova").build()) + .createTime(dateService.iso8601SecondsDateParse("2012-04-10T10:39:52Z")) + .build()); + + assertEquals(client.describeVolumesInRegion("nova"), expected); + } + +} diff --git a/apis/openstack-nova-ec2/src/test/resources/nova_ec2_availabilityZones.xml b/apis/openstack-nova-ec2/src/test/resources/nova_ec2_availabilityZones.xml new file mode 100644 index 0000000000..4ed528002f --- /dev/null +++ b/apis/openstack-nova-ec2/src/test/resources/nova_ec2_availabilityZones.xml @@ -0,0 +1,10 @@ + + + req-a6cd42f8-b5e5-4c94-a1e0-41d21ea0a032 + + + available + nova + + + \ No newline at end of file diff --git a/apis/openstack-nova-ec2/src/test/resources/nova_ec2_describe_volumes.xml b/apis/openstack-nova-ec2/src/test/resources/nova_ec2_describe_volumes.xml new file mode 100644 index 0000000000..06b9e4897a --- /dev/null +++ b/apis/openstack-nova-ec2/src/test/resources/nova_ec2_describe_volumes.xml @@ -0,0 +1,17 @@ + + + req-9e45299b-980d-4893-a475-a574b1a94ed5 + + + available (f06de98af01446b2ae6bd79f5fbf3b2a, att-openstack1, None, None) + nova + vol-00000007 + + + + + 2012-04-10T10:39:52.000Z + 1 + + + \ No newline at end of file