From b77a3bf0c8af5fe7919a021bfec0e4be277d8afe Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 29 Sep 2012 14:02:33 -0700 Subject: [PATCH] cleanup and example of overriding nova api version --- .../keystone/v2_0/domain/Endpoint.java | 2 +- .../openstack/nova/v2_0/NovaApiMetadata.java | 2 + .../v2_0/config/NovaRestClientModule.java | 1 - .../v2_0/OverrideApiVersionExpectTest.java | 72 +++++++++++++++++++ .../test/resources/access_version_uids.json | 1 + 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/OverrideApiVersionExpectTest.java create mode 100644 apis/openstack-nova/src/test/resources/access_version_uids.json diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java index fe5e38d98d..9dfd2e845d 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java @@ -252,7 +252,7 @@ public class Endpoint { } protected ToStringHelper string() { - return Objects.toStringHelper(this) + return Objects.toStringHelper(this).omitNullValues() .add("versionId", versionId).add("region", region).add("publicURL", publicURL).add("internalURL", internalURL) .add("adminURL", adminURL).add("versionInfo", versionInfo).add("versionList", versionList).add("tenantId", tenantId); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApiMetadata.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApiMetadata.java index 780eb81706..0445321e51 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApiMetadata.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/NovaApiMetadata.java @@ -33,6 +33,7 @@ import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.ZoneModule; import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule; +import org.jclouds.openstack.nova.v2_0.config.NovaParserModule; import org.jclouds.openstack.nova.v2_0.config.NovaRestClientModule; import org.jclouds.openstack.v2_0.ServiceType; import org.jclouds.rest.RestContext; @@ -101,6 +102,7 @@ public class NovaApiMetadata extends BaseRestApiMetadata { .defaultModules(ImmutableSet.>builder() .add(KeystoneAuthenticationModule.class) .add(ZoneModule.class) + .add(NovaParserModule.class) .add(NovaRestClientModule.class) .add(NovaComputeServiceContextModule.class).build()); } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java index 597451daad..e6b242e20c 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java @@ -126,7 +126,6 @@ public class NovaRestClientModule ext @Override protected void configure() { - install(new NovaParserModule()); bind(ImplicitOptionalConverter.class).to(PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.class); super.configure(); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/OverrideApiVersionExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/OverrideApiVersionExpectTest.java new file mode 100644 index 0000000000..5b2c021de0 --- /dev/null +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/OverrideApiVersionExpectTest.java @@ -0,0 +1,72 @@ +/** + * 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.v2_0; + +import static org.testng.Assert.assertEquals; + +import java.util.Properties; + +import org.jclouds.Constants; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "OverrideApiVersionExpectTest") +public class OverrideApiVersionExpectTest extends BaseNovaApiExpectTest { + + public OverrideApiVersionExpectTest() { + this.identity = "demo:demo"; + this.credential = "password"; + } + + @Override + protected Properties setupProperties() { + Properties overrides = super.setupProperties(); + overrides.setProperty(Constants.PROPERTY_ENDPOINT, "http://10.10.10.10:5000/v2.0/"); + overrides.setProperty(provider + ".api-version", "bb3ce9ccdc5045909882688b90cc3ff0"); + return overrides; + } + + public void testVersionMatchOnConfiguredZonesWhenResponseIs2xx() { + + HttpRequest authenticate = HttpRequest.builder().method("POST") + .endpoint("http://10.10.10.10:5000/v2.0/tokens") + .addHeader("Accept", "application/json") + .payload(payloadFromStringWithContentType( + "{\"auth\":{\"passwordCredentials\":{\"username\":\"demo\",\"password\":\"password\"},\"tenantName\":\"demo\"}}" + , "application/json")).build(); + + + HttpResponse authenticationResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/access_version_uids.json", "application/json")).build(); + + NovaApi whenNovaRegionExists = requestSendsResponse(authenticate, authenticationResponse); + + assertEquals(whenNovaRegionExists.getConfiguredZones(), ImmutableSet.of("RegionOne")); + + } + +} diff --git a/apis/openstack-nova/src/test/resources/access_version_uids.json b/apis/openstack-nova/src/test/resources/access_version_uids.json new file mode 100644 index 0000000000..3349580296 --- /dev/null +++ b/apis/openstack-nova/src/test/resources/access_version_uids.json @@ -0,0 +1 @@ +{"access": {"token": {"expires": "2012-09-29T19:53:45Z", "id": "b267e2e240624b108b1ed5bba6e5882e", "tenant": {"enabled": true, "description": null, "name": "demo", "id": "82d8d2f865484776a1daf1e2245d3317"}}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://10.10.10.10:8774/v2/82d8d2f865484776a1daf1e2245d3317", "region": "RegionOne", "internalURL": "http://10.10.10.10:8774/v2/82d8d2f865484776a1daf1e2245d3317", "id": "bb3ce9ccdc5045909882688b90cc3ff0", "publicURL": "http://10.10.10.10:8774/v2/82d8d2f865484776a1daf1e2245d3317"}], "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": "http://10.10.10.10:3333", "region": "RegionOne", "internalURL": "http://10.10.10.10:3333", "id": "9646263f31ea4f499732c5e1370ecf5e", "publicURL": "http://10.10.10.10:3333"}], "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": "http://10.10.10.10:9292", "region": "RegionOne", "internalURL": "http://10.10.10.10:9292", "id": "aa5d0b2574824ba097dc07faacf3be65", "publicURL": "http://10.10.10.10:9292"}], "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": "http://10.10.10.10:8776/v1/82d8d2f865484776a1daf1e2245d3317", "region": "RegionOne", "internalURL": "http://10.10.10.10:8776/v1/82d8d2f865484776a1daf1e2245d3317", "id": "7679065b1405447eb5f1a38a6b99ccc0", "publicURL": "http://10.10.10.10:8776/v1/82d8d2f865484776a1daf1e2245d3317"}], "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": [{"adminURL": "http://10.10.10.10:8773/services/Admin", "region": "RegionOne", "internalURL": "http://10.10.10.10:8773/services/Cloud", "id": "22b007f023fb4c42be094916eb2bf18b", "publicURL": "http://10.10.10.10:8773/services/Cloud"}], "endpoints_links": [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://10.10.10.10:35357/v2.0", "region": "RegionOne", "internalURL": "http://10.10.10.10:5000/v2.0", "id": "57ee5fb4f9a840f3b965909681d0fc53", "publicURL": "http://10.10.10.10:5000/v2.0"}], "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": "demo", "roles_links": [], "id": "ca248caf55844c14a4876c22112bbbb9", "roles": [{"name": "Member"}], "name": "demo"}, "metadata": {"is_admin": 0, "roles": ["1f697d8e3ace4f5a80f7701e554ee5d9"]}}} \ No newline at end of file